Skip to content

Commit 0b7115b

Browse files
committed
fix: delete the unused method
1 parent ba7fd81 commit 0b7115b

File tree

2 files changed

+45
-58
lines changed

2 files changed

+45
-58
lines changed

packages/graphql-language-service-server/src/GraphQLCache.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,6 @@ export class GraphQLCache implements GraphQLCacheInterface {
244244
return fragmentDefinitions;
245245
};
246246

247-
getObjectTypeDependencies = async (
248-
query: string,
249-
objectTypeDefinitions?: Map<string, ObjectTypeInfo>,
250-
): Promise<Array<ObjectTypeInfo>> => {
251-
// If there isn't context for object type references,
252-
// return an empty array.
253-
if (!objectTypeDefinitions) {
254-
return [];
255-
}
256-
// If the query cannot be parsed, validations cannot happen yet.
257-
// Return an empty array.
258-
let parsedQuery;
259-
try {
260-
parsedQuery = parse(query);
261-
} catch {
262-
return [];
263-
}
264-
return this.getObjectTypeDependenciesForAST(
265-
parsedQuery,
266-
objectTypeDefinitions,
267-
);
268-
};
269-
270247
getObjectTypeDependenciesForAST = async (
271248
parsedQuery: ASTNode,
272249
objectTypeDefinitions: Map<string, ObjectTypeInfo>,

packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@ const defaultFiles = [
1414
] as MockFile[];
1515
const schemaFile: MockFile = [
1616
'schema.graphql',
17-
'type Query { foo: Foo }\n\ntype Foo { bar: String }',
17+
'type Query { foo: Foo, test: Test }\n\ntype Foo { bar: String }\n\ntype Test { test: Foo }',
1818
];
1919

20+
const fooTypePosition = {
21+
start: { line: 2, character: 0 },
22+
end: { line: 2, character: 24 },
23+
};
24+
2025
const genSchemaPath =
2126
'/tmp/graphql-language-service/test/projects/default/generated-schema.graphql';
2227

28+
// TODO:
29+
// - reorganize into multiple files
30+
// - potentially a high level abstraction and/or it.each() for a pathway across configs, file extensions, etc.
31+
// this may be cumbersome with offset position assertions but possible
32+
// if we can create consistency that doesn't limit variability
33+
// - convert each it() into a nested describe() block (or a top level describe() in another file), and sprinkle in it() statements to replace comments
34+
// - fix TODO comments where bugs were found that couldn't be resolved quickly (2-4hr timebox)
35+
2336
describe('MessageProcessor with no config', () => {
2437
afterEach(() => {
2538
mockfs.restore();
@@ -108,18 +121,11 @@ describe('project with simple config and graphql files', () => {
108121
});
109122
expect(initSchemaDefRequest.length).toEqual(1);
110123
expect(initSchemaDefRequest[0].uri).toEqual(project.uri('schema.graphql'));
111-
expect(serializeRange(initSchemaDefRequest[0].range)).toEqual({
112-
start: {
113-
line: 2,
114-
character: 0,
115-
},
116-
end: {
117-
character: 24,
118-
line: 2,
119-
},
120-
});
124+
expect(serializeRange(initSchemaDefRequest[0].range)).toEqual(
125+
fooTypePosition,
126+
);
121127
expect(project.lsp._logger.error).not.toHaveBeenCalled();
122-
expect(await project.lsp._graphQLCache.getSchema()).toBeDefined();
128+
expect(await project.lsp._graphQLCache.getSchema('default')).toBeDefined();
123129
// TODO: for some reason the cache result formats the graphql query??
124130
const docCache = project.lsp._textDocumentCache;
125131
expect(
@@ -131,10 +137,7 @@ describe('project with simple config and graphql files', () => {
131137
});
132138
expect(schemaDefinitions[0].uri).toEqual(project.uri('schema.graphql'));
133139

134-
expect(serializeRange(schemaDefinitions[0].range).end).toEqual({
135-
line: 2,
136-
character: 24,
137-
});
140+
expect(serializeRange(schemaDefinitions[0].range)).toEqual(fooTypePosition);
138141

139142
// query definition request of fragment name jumps to the fragment definition
140143
const firstQueryDefRequest = await project.lsp.handleDefinitionRequest({
@@ -174,18 +177,16 @@ describe('project with simple config and graphql files', () => {
174177
textDocument: { uri: project.uri('schema.graphql') },
175178
position: { character: 19, line: 0 },
176179
});
180+
181+
const fooLaterTypePosition = {
182+
start: { line: 7, character: 0 },
183+
end: { line: 7, character: 21 },
184+
};
177185
expect(schemaDefRequest.length).toEqual(1);
178186
expect(schemaDefRequest[0].uri).toEqual(project.uri('schema.graphql'));
179-
expect(serializeRange(schemaDefRequest[0].range)).toEqual({
180-
start: {
181-
line: 7,
182-
character: 0,
183-
},
184-
end: {
185-
character: 21,
186-
line: 7,
187-
},
188-
});
187+
expect(serializeRange(schemaDefRequest[0].range)).toEqual(
188+
fooLaterTypePosition,
189+
);
189190

190191
// TODO: this fragment should now be invalid
191192
const result = await project.lsp.handleDidOpenOrSaveNotification({
@@ -241,10 +242,9 @@ describe('project with simple config and graphql files', () => {
241242
project.uri('schema.graphql'),
242243
);
243244

244-
expect(serializeRange(schemaDefinitionsAgain[0].range).end).toEqual({
245-
line: 7,
246-
character: 21,
247-
});
245+
expect(serializeRange(schemaDefinitionsAgain[0].range)).toEqual(
246+
fooLaterTypePosition,
247+
);
248248
// TODO: the position should change when a watched file changes???
249249
});
250250
it('caches files and schema with a URL config', async () => {
@@ -327,6 +327,8 @@ describe('project with simple config and graphql files', () => {
327327
position: { character: 20, line: 17 },
328328
});
329329
expect(schemaDefs[0].uri).toEqual(URI.parse(genSchemaPath).toString());
330+
// note: if the graphiql test schema changes,
331+
// this might break, please adjust if you see a failure here
330332
expect(serializeRange(schemaDefs[0].range)).toEqual({
331333
start: {
332334
line: 100,
@@ -421,19 +423,20 @@ describe('project with simple config and graphql files', () => {
421423
position: { character: 13, line: 1 },
422424
});
423425

424-
expect(completion.items?.length).toEqual(4);
426+
expect(completion.items?.length).toEqual(5);
425427
expect(completion.items.map(i => i.label)).toEqual([
426428
'foo',
429+
'test',
427430
'__typename',
428431
'__schema',
429432
'__type',
430433
]);
431434

432-
// TODO this didn't work at all, how to register incomplete changes to model autocomplete, etc?
433435
// project.changeFile(
434436
// 'b/schema.graphql',
435437
// schemaFile[1] + '\ntype Example1 { field: }',
436438
// );
439+
// TODO: this didn't work at all, how to register incomplete changes to model autocomplete, etc?
437440
// await project.lsp.handleWatchedFilesChangedNotification({
438441
// changes: [
439442
// { uri: project.uri('b/schema.graphql'), type: FileChangeType.Changed },
@@ -457,11 +460,18 @@ describe('project with simple config and graphql files', () => {
457460
// '__schema',
458461
// '__type',
459462
// ]);
460-
// this confirms that autocomplete respects cross-project boundaries for types
461-
const schemaCompletion = await project.lsp.handleCompletionRequest({
463+
// this confirms that autocomplete respects cross-project boundaries for types.
464+
// it performs a definition request for the foo field in Query
465+
const schemaCompletion1 = await project.lsp.handleCompletionRequest({
462466
textDocument: { uri: project.uri('b/schema.graphql') },
463467
position: { character: 21, line: 0 },
464468
});
465-
expect(schemaCompletion.items.map(i => i.label)).toEqual(['Foo']);
469+
expect(schemaCompletion1.items.map(i => i.label)).toEqual(['Foo']);
470+
// it performs a definition request for the Foo type in Test.test
471+
const schemaDefinition = await project.lsp.handleDefinitionRequest({
472+
textDocument: { uri: project.uri('b/schema.graphql') },
473+
position: { character: 21, line: 4 },
474+
});
475+
expect(serializeRange(schemaDefinition[0].range)).toEqual(fooTypePosition);
466476
});
467477
});

0 commit comments

Comments
 (0)