@@ -14,12 +14,25 @@ const defaultFiles = [
14
14
] as MockFile [ ] ;
15
15
const schemaFile : MockFile = [
16
16
'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 }' ,
18
18
] ;
19
19
20
+ const fooTypePosition = {
21
+ start : { line : 2 , character : 0 } ,
22
+ end : { line : 2 , character : 24 } ,
23
+ } ;
24
+
20
25
const genSchemaPath =
21
26
'/tmp/graphql-language-service/test/projects/default/generated-schema.graphql' ;
22
27
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
+
23
36
describe ( 'MessageProcessor with no config' , ( ) => {
24
37
afterEach ( ( ) => {
25
38
mockfs . restore ( ) ;
@@ -108,18 +121,11 @@ describe('project with simple config and graphql files', () => {
108
121
} ) ;
109
122
expect ( initSchemaDefRequest . length ) . toEqual ( 1 ) ;
110
123
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
+ ) ;
121
127
expect ( project . lsp . _logger . error ) . not . toHaveBeenCalled ( ) ;
122
- expect ( await project . lsp . _graphQLCache . getSchema ( ) ) . toBeDefined ( ) ;
128
+ expect ( await project . lsp . _graphQLCache . getSchema ( 'default' ) ) . toBeDefined ( ) ;
123
129
// TODO: for some reason the cache result formats the graphql query??
124
130
const docCache = project . lsp . _textDocumentCache ;
125
131
expect (
@@ -131,10 +137,7 @@ describe('project with simple config and graphql files', () => {
131
137
} ) ;
132
138
expect ( schemaDefinitions [ 0 ] . uri ) . toEqual ( project . uri ( 'schema.graphql' ) ) ;
133
139
134
- expect ( serializeRange ( schemaDefinitions [ 0 ] . range ) . end ) . toEqual ( {
135
- line : 2 ,
136
- character : 24 ,
137
- } ) ;
140
+ expect ( serializeRange ( schemaDefinitions [ 0 ] . range ) ) . toEqual ( fooTypePosition ) ;
138
141
139
142
// query definition request of fragment name jumps to the fragment definition
140
143
const firstQueryDefRequest = await project . lsp . handleDefinitionRequest ( {
@@ -174,18 +177,16 @@ describe('project with simple config and graphql files', () => {
174
177
textDocument : { uri : project . uri ( 'schema.graphql' ) } ,
175
178
position : { character : 19 , line : 0 } ,
176
179
} ) ;
180
+
181
+ const fooLaterTypePosition = {
182
+ start : { line : 7 , character : 0 } ,
183
+ end : { line : 7 , character : 21 } ,
184
+ } ;
177
185
expect ( schemaDefRequest . length ) . toEqual ( 1 ) ;
178
186
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
+ ) ;
189
190
190
191
// TODO: this fragment should now be invalid
191
192
const result = await project . lsp . handleDidOpenOrSaveNotification ( {
@@ -241,10 +242,9 @@ describe('project with simple config and graphql files', () => {
241
242
project . uri ( 'schema.graphql' ) ,
242
243
) ;
243
244
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
+ ) ;
248
248
// TODO: the position should change when a watched file changes???
249
249
} ) ;
250
250
it ( 'caches files and schema with a URL config' , async ( ) => {
@@ -327,6 +327,8 @@ describe('project with simple config and graphql files', () => {
327
327
position : { character : 20 , line : 17 } ,
328
328
} ) ;
329
329
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
330
332
expect ( serializeRange ( schemaDefs [ 0 ] . range ) ) . toEqual ( {
331
333
start : {
332
334
line : 100 ,
@@ -421,19 +423,20 @@ describe('project with simple config and graphql files', () => {
421
423
position : { character : 13 , line : 1 } ,
422
424
} ) ;
423
425
424
- expect ( completion . items ?. length ) . toEqual ( 4 ) ;
426
+ expect ( completion . items ?. length ) . toEqual ( 5 ) ;
425
427
expect ( completion . items . map ( i => i . label ) ) . toEqual ( [
426
428
'foo' ,
429
+ 'test' ,
427
430
'__typename' ,
428
431
'__schema' ,
429
432
'__type' ,
430
433
] ) ;
431
434
432
- // TODO this didn't work at all, how to register incomplete changes to model autocomplete, etc?
433
435
// project.changeFile(
434
436
// 'b/schema.graphql',
435
437
// schemaFile[1] + '\ntype Example1 { field: }',
436
438
// );
439
+ // TODO: this didn't work at all, how to register incomplete changes to model autocomplete, etc?
437
440
// await project.lsp.handleWatchedFilesChangedNotification({
438
441
// changes: [
439
442
// { uri: project.uri('b/schema.graphql'), type: FileChangeType.Changed },
@@ -457,11 +460,18 @@ describe('project with simple config and graphql files', () => {
457
460
// '__schema',
458
461
// '__type',
459
462
// ]);
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 ( {
462
466
textDocument : { uri : project . uri ( 'b/schema.graphql' ) } ,
463
467
position : { character : 21 , line : 0 } ,
464
468
} ) ;
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 ) ;
466
476
} ) ;
467
477
} ) ;
0 commit comments