From a608668ba35b1b803e451a5242567eb5266f1eef Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Sun, 17 Mar 2024 10:40:03 +0100 Subject: [PATCH] only 3 spec errors left! --- .../src/GraphQLCache.ts | 31 +++++++++++++------ .../src/__tests__/MessageProcessor.spec.ts | 10 +++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/graphql-language-service-server/src/GraphQLCache.ts b/packages/graphql-language-service-server/src/GraphQLCache.ts index d02da820712..ccb6dc07235 100644 --- a/packages/graphql-language-service-server/src/GraphQLCache.ts +++ b/packages/graphql-language-service-server/src/GraphQLCache.ts @@ -320,7 +320,7 @@ export class GraphQLCache { ast, range: new Range( new Position(0, 0), - new Position(lines.length, lines.at(-1).length), + new Position(lines.length, lines.at(-1)?.length ?? 0), ), }, ], @@ -332,7 +332,7 @@ export class GraphQLCache { projectCache.delete(project.schema.toString()); this._setDefinitionCache( - [{ documentString: text, ast, range: null }], + [{ documentString: text, ast, range: undefined }], this._typeDefinitionsCache.get(projectCacheKey) || new Map(), uri, ); @@ -543,7 +543,20 @@ export class GraphQLCache { if (typeof pointer === 'string') { try { const { fsPath } = URI.parse(pointer); - return this.loadTypeDefs(project, fsPath, target); + // @ts-expect-error these are always here. better typings soon + + return project._extensionsRegistry.loaders[target].loadTypeDefs( + fsPath, + { + cwd: project.dirpath, + includes: project.include, + excludes: project.exclude, + includeSources: true, + assumeValid: false, + noLocation: false, + assumeValidSDL: false, + }, + ); } catch {} } // @ts-expect-error these are always here. better typings soon @@ -802,7 +815,12 @@ export class GraphQLCache { let fsPath = doc.location; let filePath; const isNetwork = doc.location.startsWith('http'); - if (isNetwork) { + if (!isNetwork) { + try { + fsPath = resolve(rootDir, doc.location); + } catch {} + filePath = URI.file(fsPath).toString(); + } else { filePath = this._getTmpProjectPath( projectConfig, true, @@ -813,11 +831,6 @@ export class GraphQLCache { false, 'generated-schema.graphql', ); - } else { - try { - fsPath = resolve(rootDir, doc.location); - } catch {} - filePath = URI.file(fsPath).toString(); } const content = doc.document.loc?.source.body ?? ''; diff --git a/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts b/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts index 9da9bee3700..db402abf259 100644 --- a/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts +++ b/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts @@ -310,7 +310,7 @@ describe('the lsp', () => { expect(project.lsp._logger.error).not.toHaveBeenCalled(); }); - it.only('caches files and schema with a URL config', async () => { + it('caches files and schema with a URL config', async () => { const project = new MockProject({ files: [ ['query.graphql', 'query { test { isTest, ...T } }'], @@ -481,10 +481,10 @@ describe('the lsp', () => { expect(project.lsp._logger.error).not.toHaveBeenCalled(); expect(await project.lsp._graphQLCache.getSchema('a')).toBeDefined(); - // const file = await readFile(join(genSchemaPath.replace('default', 'a')), { - // encoding: 'utf-8', - // }); - // expect(file.split('\n').length).toBeGreaterThan(10); + const file = await readFile(join(genSchemaPath.replace('default', 'a')), { + encoding: 'utf-8', + }); + expect(file.split('\n').length).toBeGreaterThan(10); // add a new typescript file with empty query to the b project // and expect autocomplete to only show options for project b await project.addFile(