Skip to content

Commit

Permalink
only 3 spec errors left!
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Mar 17, 2024
1 parent 5544133 commit a608668
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
31 changes: 22 additions & 9 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Expand Up @@ -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),
),
},
],
Expand All @@ -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,
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 ?? '';
Expand Down
Expand Up @@ -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 } }'],
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a608668

Please sign in to comment.