@apollo/federation-internals 2.4.4 → 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/Subgraph.d.ts +1 -0
  2. package/dist/Subgraph.d.ts.map +1 -0
  3. package/dist/Subgraph.js +2 -0
  4. package/dist/Subgraph.js.map +1 -0
  5. package/dist/argumentCompositionStrategies.d.ts +34 -0
  6. package/dist/argumentCompositionStrategies.d.ts.map +1 -0
  7. package/dist/argumentCompositionStrategies.js +35 -0
  8. package/dist/argumentCompositionStrategies.js.map +1 -0
  9. package/dist/buildSchema.d.ts +10 -0
  10. package/dist/buildSchema.d.ts.map +1 -0
  11. package/dist/buildSchema.js +362 -0
  12. package/dist/buildSchema.js.map +1 -0
  13. package/dist/coreSpec.d.ts +127 -0
  14. package/dist/coreSpec.d.ts.map +1 -0
  15. package/dist/coreSpec.js +590 -0
  16. package/dist/coreSpec.js.map +1 -0
  17. package/dist/debug.d.ts +15 -0
  18. package/dist/debug.d.ts.map +1 -0
  19. package/dist/debug.js +122 -0
  20. package/dist/debug.js.map +1 -0
  21. package/dist/definitions.d.ts +663 -0
  22. package/dist/definitions.d.ts.map +1 -0
  23. package/dist/definitions.js +2841 -0
  24. package/dist/definitions.js.map +1 -0
  25. package/dist/directiveAndTypeSpecification.d.ts +67 -0
  26. package/dist/directiveAndTypeSpecification.d.ts.map +1 -0
  27. package/dist/directiveAndTypeSpecification.js +271 -0
  28. package/dist/directiveAndTypeSpecification.js.map +1 -0
  29. package/dist/error.d.ts +128 -0
  30. package/dist/error.d.ts.map +1 -0
  31. package/dist/error.js +315 -0
  32. package/dist/error.js.map +1 -0
  33. package/dist/extractSubgraphsFromSupergraph.d.ts +8 -0
  34. package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -0
  35. package/dist/extractSubgraphsFromSupergraph.js +576 -0
  36. package/dist/extractSubgraphsFromSupergraph.js.map +1 -0
  37. package/dist/federation.d.ts +175 -0
  38. package/dist/federation.d.ts.map +1 -0
  39. package/dist/federation.js +1414 -0
  40. package/dist/federation.js.map +1 -0
  41. package/dist/federationSpec.d.ts +25 -0
  42. package/dist/federationSpec.d.ts.map +1 -0
  43. package/dist/federationSpec.js +125 -0
  44. package/dist/federationSpec.js.map +1 -0
  45. package/dist/genErrorCodeDoc.d.ts +2 -0
  46. package/dist/genErrorCodeDoc.d.ts.map +1 -0
  47. package/dist/genErrorCodeDoc.js +61 -0
  48. package/dist/genErrorCodeDoc.js.map +1 -0
  49. package/dist/graphQLJSSchemaToAST.d.ts +8 -0
  50. package/dist/graphQLJSSchemaToAST.d.ts.map +1 -0
  51. package/dist/graphQLJSSchemaToAST.js +96 -0
  52. package/dist/graphQLJSSchemaToAST.js.map +1 -0
  53. package/dist/inaccessibleSpec.d.ts +18 -0
  54. package/dist/inaccessibleSpec.d.ts.map +1 -0
  55. package/dist/inaccessibleSpec.js +655 -0
  56. package/dist/inaccessibleSpec.js.map +1 -0
  57. package/dist/index.d.ts +24 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +42 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/introspection.d.ts +6 -0
  62. package/dist/introspection.d.ts.map +1 -0
  63. package/dist/introspection.js +96 -0
  64. package/dist/introspection.js.map +1 -0
  65. package/dist/joinSpec.d.ts +51 -0
  66. package/dist/joinSpec.d.ts.map +1 -0
  67. package/dist/joinSpec.js +160 -0
  68. package/dist/joinSpec.js.map +1 -0
  69. package/dist/knownCoreFeatures.d.ts +5 -0
  70. package/dist/knownCoreFeatures.d.ts.map +1 -0
  71. package/dist/knownCoreFeatures.js +20 -0
  72. package/dist/knownCoreFeatures.js.map +1 -0
  73. package/dist/operations.d.ts +418 -0
  74. package/dist/operations.d.ts.map +1 -0
  75. package/dist/operations.js +2068 -0
  76. package/dist/operations.js.map +1 -0
  77. package/dist/precompute.d.ts +3 -0
  78. package/dist/precompute.d.ts.map +1 -0
  79. package/dist/precompute.js +54 -0
  80. package/dist/precompute.js.map +1 -0
  81. package/dist/print.d.ts +28 -0
  82. package/dist/print.d.ts.map +1 -0
  83. package/dist/print.js +299 -0
  84. package/dist/print.js.map +1 -0
  85. package/dist/schemaUpgrader.d.ts +121 -0
  86. package/dist/schemaUpgrader.d.ts.map +1 -0
  87. package/dist/schemaUpgrader.js +570 -0
  88. package/dist/schemaUpgrader.js.map +1 -0
  89. package/dist/suggestions.d.ts +3 -0
  90. package/dist/suggestions.d.ts.map +1 -0
  91. package/dist/suggestions.js +44 -0
  92. package/dist/suggestions.js.map +1 -0
  93. package/dist/supergraphs.d.ts +10 -0
  94. package/dist/supergraphs.d.ts.map +1 -0
  95. package/dist/supergraphs.js +76 -0
  96. package/dist/supergraphs.js.map +1 -0
  97. package/dist/tagSpec.d.ts +19 -0
  98. package/dist/tagSpec.d.ts.map +1 -0
  99. package/dist/tagSpec.js +66 -0
  100. package/dist/tagSpec.js.map +1 -0
  101. package/dist/types.d.ts +9 -0
  102. package/dist/types.d.ts.map +1 -0
  103. package/dist/types.js +64 -0
  104. package/dist/types.js.map +1 -0
  105. package/dist/utils.d.ts +64 -0
  106. package/dist/utils.d.ts.map +1 -0
  107. package/dist/utils.js +326 -0
  108. package/dist/utils.js.map +1 -0
  109. package/dist/validate.d.ts +4 -0
  110. package/dist/validate.d.ts.map +1 -0
  111. package/dist/validate.js +239 -0
  112. package/dist/validate.js.map +1 -0
  113. package/dist/validation/KnownTypeNamesInFederationRule.d.ts +4 -0
  114. package/dist/validation/KnownTypeNamesInFederationRule.d.ts.map +1 -0
  115. package/dist/validation/KnownTypeNamesInFederationRule.js +41 -0
  116. package/dist/validation/KnownTypeNamesInFederationRule.js.map +1 -0
  117. package/dist/values.d.ts +23 -0
  118. package/dist/values.d.ts.map +1 -0
  119. package/dist/values.js +580 -0
  120. package/dist/values.js.map +1 -0
  121. package/package.json +1 -1
  122. package/src/operations.ts +145 -20
  123. package/src/utils.ts +1 -1
  124. package/CHANGELOG.md +0 -205
  125. package/jest.config.js +0 -11
  126. package/src/__tests__/coreSpec.test.ts +0 -212
  127. package/src/__tests__/definitions.test.ts +0 -982
  128. package/src/__tests__/directiveAndTypeSpecifications.test.ts +0 -41
  129. package/src/__tests__/extractSubgraphsFromSupergraph.test.ts +0 -748
  130. package/src/__tests__/federation.test.ts +0 -31
  131. package/src/__tests__/graphQLJSSchemaToAST.test.ts +0 -156
  132. package/src/__tests__/matchers/index.ts +0 -1
  133. package/src/__tests__/matchers/toMatchString.ts +0 -87
  134. package/src/__tests__/operations.test.ts +0 -1266
  135. package/src/__tests__/removeInaccessibleElements.test.ts +0 -2471
  136. package/src/__tests__/schemaUpgrader.test.ts +0 -287
  137. package/src/__tests__/subgraphValidation.test.ts +0 -1254
  138. package/src/__tests__/supergraphSdl.graphql +0 -281
  139. package/src/__tests__/testUtils.ts +0 -28
  140. package/src/__tests__/toAPISchema.test.ts +0 -53
  141. package/src/__tests__/tsconfig.json +0 -7
  142. package/src/__tests__/utils.test.ts +0 -92
  143. package/src/__tests__/values.test.ts +0 -390
  144. package/tsconfig.json +0 -10
  145. package/tsconfig.test.json +0 -8
@@ -1,748 +0,0 @@
1
- import { buildSupergraphSchema, extractSubgraphsFromSupergraph, InputObjectType } from "..";
2
-
3
-
4
- test('handles types having no fields referenced by other objects in a subgraph correctly', () => {
5
- /*
6
- * The following supergraph has been generated on version-0.x from:
7
- * - ServiceA:
8
- * type Query {
9
- * q: A
10
- * }
11
- *
12
- * type A {
13
- * a: B
14
- * }
15
- *
16
- * type B {
17
- * b: C @provides(fields: "c")
18
- * }
19
- *
20
- * type C {
21
- * c: String
22
- * }
23
- * - ServiceB:
24
- * type C {
25
- * c: String
26
- * }
27
- * - ServiceC:
28
- * type D {
29
- * d: String
30
- * }
31
- *
32
- * The general idea being that all types are "value types" so ends with no 'join__type' in the supergraph (so
33
- * `extractSubgraphsFromSupergraph` will have to initially assume that all types are in all subgraphs), but
34
- * due to the `@provides`, `B.b` has a `join__field`, which makes it be only in "ServiceA". As as result,
35
- * type `B` will end up empty in both "ServiceB" and "ServiceC" and will need to be removed, which has to
36
- * trickle to removing type `A` too (since it's only field mentions `B`). This later part wasn't always done
37
- * correctly, resulting in errors being throws and it is what this test checks.
38
- */
39
- const supergraph = `
40
- schema
41
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
42
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
43
- {
44
- query: Query
45
- }
46
-
47
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
48
-
49
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
50
-
51
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
52
-
53
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
54
-
55
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
56
-
57
- type A {
58
- a: B
59
- }
60
-
61
- type B {
62
- b: C @join__field(graph: SERVICEA, provides: \"c\")
63
- }
64
-
65
- type C {
66
- c: String
67
- }
68
-
69
- type D {
70
- d: String
71
- }
72
-
73
- type Query {
74
- q: A
75
- }
76
-
77
- enum core__Purpose {
78
- """
79
- \`EXECUTION\` features provide metadata necessary to for operation execution.
80
- """
81
- EXECUTION
82
-
83
- """
84
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
85
- """
86
- SECURITY
87
- }
88
-
89
- scalar join__FieldSet
90
-
91
- enum join__Graph {
92
- SERVICEA @join__graph(name: "serviceA" url: "")
93
- SERVICEB @join__graph(name: "serviceB" url: "")
94
- SERVICEC @join__graph(name: "serviceC" url: "")
95
- }
96
- `;
97
-
98
- const schema = buildSupergraphSchema(supergraph)[0];
99
- const subgraphs = extractSubgraphsFromSupergraph(schema);
100
- expect(subgraphs.size()).toBe(3);
101
-
102
- const [a, b, c] = subgraphs.values().map((s) => s.schema);
103
- expect(a.type('A')).toBeDefined();
104
- expect(a.type('B')).toBeDefined();
105
-
106
- expect(b.type('A')).toBeUndefined();
107
- expect(b.type('B')).toBeUndefined();
108
-
109
- expect(c.type('A')).toBeUndefined();
110
- expect(c.type('B')).toBeUndefined();
111
- })
112
-
113
- test('handles types having no fields referenced by other interfaces in a subgraph correctly', () => {
114
- /*
115
- *
116
- * The following supergraph has been generated on version-0.x from:
117
- * - ServiceA:
118
- * type Query {
119
- * q: A
120
- * }
121
- *
122
- * interface A {
123
- * a: B
124
- * }
125
- *
126
- * type B {
127
- * b: C @provides(fields: "c")
128
- * }
129
- *
130
- * type C {
131
- * c: String
132
- * }
133
- * - ServiceB:
134
- * type C {
135
- * c: String
136
- * }
137
- * - ServiceC:
138
- * type D {
139
- * d: String
140
- * }
141
- *
142
- * This tests is almost identical to the 'handles types having no fields referenced by other objects in a subgraph correctly'
143
- * one, except that the reference to the type being removed is in an interface, to make double-sure this case is
144
- * handled as well.
145
- */
146
- const supergraph = `
147
- schema
148
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
149
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
150
- {
151
- query: Query
152
- }
153
-
154
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
155
-
156
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
157
-
158
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
159
-
160
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
161
-
162
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
163
-
164
- interface A {
165
- a: B
166
- }
167
-
168
- type B {
169
- b: C @join__field(graph: SERVICEA, provides: "c")
170
- }
171
-
172
- type C {
173
- c: String
174
- }
175
-
176
- type D {
177
- d: String
178
- }
179
-
180
- type Query {
181
- q: A
182
- }
183
-
184
- enum core__Purpose {
185
- """
186
- \`EXECUTION\` features provide metadata necessary to for operation execution.
187
- """
188
- EXECUTION
189
-
190
- """
191
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
192
- """
193
- SECURITY
194
- }
195
-
196
- scalar join__FieldSet
197
-
198
- enum join__Graph {
199
- SERVICEA @join__graph(name: "serviceA" url: "")
200
- SERVICEB @join__graph(name: "serviceB" url: "")
201
- SERVICEC @join__graph(name: "serviceC" url: "")
202
- }
203
- `;
204
-
205
- const schema = buildSupergraphSchema(supergraph)[0];
206
- const subgraphs = extractSubgraphsFromSupergraph(schema);
207
- expect(subgraphs.size()).toBe(3);
208
-
209
- const [a, b, c] = subgraphs.values().map((s) => s.schema);
210
- expect(a.type('A')).toBeDefined();
211
- expect(a.type('B')).toBeDefined();
212
-
213
- expect(b.type('A')).toBeUndefined();
214
- expect(b.type('B')).toBeUndefined();
215
-
216
- expect(c.type('A')).toBeUndefined();
217
- expect(c.type('B')).toBeUndefined();
218
- })
219
-
220
- test('handles types having no fields referenced by other unions in a subgraph correctly', () => {
221
- /*
222
- *
223
- * The following supergraph has been generated on version-0.x from:
224
- * - ServiceA:
225
- * type Query {
226
- * q: A
227
- * }
228
- *
229
- * union A = B | C
230
- *
231
- * type B {
232
- * b: D @provides(fields: "d")
233
- * }
234
- *
235
- * type C {
236
- * c: D @provides(fields: "d")
237
- * }
238
- *
239
- * type D {
240
- * d: String
241
- * }
242
- * - ServiceB:
243
- * type D {
244
- * d: String
245
- * }
246
- *
247
- * This tests is similar identical to 'handles types having no fields referenced by other objects in a subgraph correctly'
248
- * but the reference to the type being removed is a union, one that should be fully removed.
249
- */
250
- const supergraph = `
251
- schema
252
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
253
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
254
- {
255
- query: Query
256
- }
257
-
258
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
259
-
260
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
261
-
262
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
263
-
264
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
265
-
266
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
267
-
268
- union A = B | C
269
-
270
- type B {
271
- b: D @join__field(graph: SERVICEA, provides: "d")
272
- }
273
-
274
- type C {
275
- c: D @join__field(graph: SERVICEA, provides: "d")
276
- }
277
-
278
- type D {
279
- d: String
280
- }
281
-
282
- type Query {
283
- q: A
284
- }
285
-
286
- enum core__Purpose {
287
- """
288
- \`EXECUTION\` features provide metadata necessary to for operation execution.
289
- """
290
- EXECUTION
291
-
292
- """
293
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
294
- """
295
- SECURITY
296
- }
297
-
298
- scalar join__FieldSet
299
-
300
- enum join__Graph {
301
- SERVICEA @join__graph(name: "serviceA" url: "")
302
- SERVICEB @join__graph(name: "serviceB" url: "")
303
- }
304
- `;
305
-
306
- const schema = buildSupergraphSchema(supergraph)[0];
307
- const subgraphs = extractSubgraphsFromSupergraph(schema);
308
- expect(subgraphs.size()).toBe(2);
309
-
310
- const [a, b] = subgraphs.values().map((s) => s.schema);
311
- expect(a.type('A')).toBeDefined();
312
- expect(a.type('B')).toBeDefined();
313
- expect(a.type('C')).toBeDefined();
314
- expect(a.type('D')).toBeDefined();
315
-
316
- expect(b.type('A')).toBeUndefined();
317
- expect(b.type('B')).toBeUndefined();
318
- expect(b.type('C')).toBeUndefined();
319
- expect(a.type('D')).toBeDefined();
320
- })
321
-
322
- test('handles types having only some of their fields removed in a subgraph correctly', () => {
323
- /*
324
- * The following supergraph has been generated on version-0.x from:
325
- * - ServiceA:
326
- * type Query {
327
- * q: A
328
- * }
329
- *
330
- * type A {
331
- * a: B
332
- * }
333
- *
334
- * type B {
335
- * b: C @provides(fields: "c")
336
- * c: Int
337
- * }
338
- *
339
- * type C {
340
- * c: String
341
- * }
342
- * - ServiceB:
343
- * type C {
344
- * c: String
345
- * }
346
- * - ServiceC:
347
- * type D {
348
- * d: String
349
- * }
350
- *
351
- * This tests is similar identical to 'handles types having no fields referenced by other objects in a subgraph correctly'
352
- * but where no all of B type fields are "removed" and so the type should be preserved. So it's a "negative" version of
353
- * that prior test of sorts.
354
- */
355
- const supergraph = `
356
- schema
357
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
358
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
359
- {
360
- query: Query
361
- }
362
-
363
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
364
-
365
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
366
-
367
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
368
-
369
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
370
-
371
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
372
-
373
- type A {
374
- a: B
375
- }
376
-
377
- type B {
378
- b: C @join__field(graph: SERVICEA, provides: "c")
379
- c: Int
380
- }
381
-
382
- type C {
383
- c: String
384
- }
385
-
386
- type D {
387
- d: String
388
- }
389
-
390
- type Query {
391
- q: A
392
- }
393
-
394
- enum core__Purpose {
395
- """
396
- \`EXECUTION\` features provide metadata necessary to for operation execution.
397
- """
398
- EXECUTION
399
-
400
- """
401
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
402
- """
403
- SECURITY
404
- }
405
-
406
- scalar join__FieldSet
407
-
408
- enum join__Graph {
409
- SERVICEA @join__graph(name: "serviceA" url: "")
410
- SERVICEB @join__graph(name: "serviceB" url: "")
411
- SERVICEC @join__graph(name: "serviceC" url: "")
412
- }
413
- `;
414
-
415
- const schema = buildSupergraphSchema(supergraph)[0];
416
- const subgraphs = extractSubgraphsFromSupergraph(schema);
417
- expect(subgraphs.size()).toBe(3);
418
-
419
- const [a, b, c] = subgraphs.values().map((s) => s.schema);
420
- expect(a.type('A')).toBeDefined();
421
- expect(a.type('B')).toBeDefined();
422
-
423
- // Do note that the fact that A and B are extracted in subgraph 'c' and 'd' is, in a way, "wrong" since
424
- // those subgraphs didn't had those type originally, but nothing in the supergraph allows to make that
425
- // decision so this simply assert the actuall code behaviour.
426
-
427
- expect(b.type('A')).toBeDefined();
428
- expect(b.type('B')).toBeDefined();
429
-
430
- expect(c.type('A')).toBeDefined();
431
- expect(c.type('B')).toBeDefined();
432
- })
433
-
434
- test('handles unions types having no members in a subgraph correctly', () => {
435
- /*
436
- * The following supergraph has been generated on version-0.x from:
437
- * - ServiceA:
438
- * type Query {
439
- * q: A
440
- * }
441
- *
442
- * union A = B | C
443
- *
444
- * type B @key(fields: "b") {
445
- * b: D
446
- * }
447
- *
448
- * type C @key(fields: "c"){
449
- * c: D
450
- * }
451
- *
452
- * type D {
453
- * d: String
454
- * }
455
- * - ServiceB:
456
- * type D {
457
- * d: String
458
- * }
459
- *
460
- * This tests is similar to the other test with unions, but because its members are enties, the
461
- * members themself with have a join__owner, and that means the removal will hit a different
462
- * code path (technically, the union A will be "removed" directly by `extractSubgraphsFromSupergraph`
463
- * instead of being removed indirectly through the removal of its members).
464
- */
465
- const supergraph = `
466
- schema
467
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
468
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
469
- {
470
- query: Query
471
- }
472
-
473
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
474
-
475
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
476
-
477
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
478
-
479
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
480
-
481
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
482
-
483
- union A = B | C
484
-
485
- type B @join__owner(graph: SERVICEA) @join__type(graph: SERVICEA, key: "b { d }") {
486
- b: D
487
- }
488
-
489
- type C @join__owner(graph: SERVICEA) @join__type(graph: SERVICEA, key: "c { d }") {
490
- c: D
491
- }
492
-
493
- type D {
494
- d: String
495
- }
496
-
497
- type Query {
498
- q: A
499
- }
500
-
501
- enum core__Purpose {
502
- """
503
- \`EXECUTION\` features provide metadata necessary to for operation execution.
504
- """
505
- EXECUTION
506
-
507
- """
508
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
509
- """
510
- SECURITY
511
- }
512
-
513
- scalar join__FieldSet
514
-
515
- enum join__Graph {
516
- SERVICEA @join__graph(name: "serviceA" url: "")
517
- SERVICEB @join__graph(name: "serviceB" url: "")
518
- }
519
- `;
520
-
521
- const schema = buildSupergraphSchema(supergraph)[0];
522
- const subgraphs = extractSubgraphsFromSupergraph(schema);
523
- expect(subgraphs.size()).toBe(2);
524
-
525
- const [a, b] = subgraphs.values().map((s) => s.schema);
526
- expect(a.type('A')).toBeDefined();
527
- expect(a.type('B')).toBeDefined();
528
- expect(a.type('C')).toBeDefined();
529
- expect(a.type('D')).toBeDefined();
530
-
531
- expect(b.type('A')).toBeUndefined();
532
- expect(b.type('B')).toBeUndefined();
533
- expect(b.type('C')).toBeUndefined();
534
- expect(a.type('D')).toBeDefined();
535
- })
536
-
537
- test('preserves default values of input object fields', () => {
538
- const supergraph = `
539
- schema
540
- @link(url: "https://specs.apollo.dev/link/v1.0")
541
- @link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
542
- {
543
- query: Query
544
- }
545
-
546
- directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
547
-
548
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
549
-
550
- directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
551
-
552
- directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
553
-
554
- directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
555
-
556
- input Input
557
- @join__type(graph: SERVICE)
558
- {
559
- a: Int! = 1234
560
- }
561
-
562
- scalar join__FieldSet
563
-
564
- enum join__Graph {
565
- SERVICE @join__graph(name: "service", url: "")
566
- }
567
-
568
- scalar link__Import
569
-
570
- enum link__Purpose {
571
- """
572
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
573
- """
574
- SECURITY
575
-
576
- """
577
- \`EXECUTION\` features provide metadata necessary for operation execution.
578
- """
579
- EXECUTION
580
- }
581
-
582
- type Query
583
- @join__type(graph: SERVICE)
584
- {
585
- field(input: Input!): String
586
- }
587
- `;
588
-
589
- const schema = buildSupergraphSchema(supergraph)[0];
590
- const subgraphs = extractSubgraphsFromSupergraph(schema);
591
-
592
- const subgraph = subgraphs.get('service')
593
- const inputType = subgraph?.schema.type('Input') as InputObjectType | undefined
594
- const inputFieldA = inputType?.field('a')
595
-
596
- expect(inputFieldA?.defaultValue).toBe(1234)
597
- })
598
-
599
- test('throw meaningful error for invalid federation directive fieldSet', () => {
600
- const supergraph = `
601
- schema
602
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
603
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
604
- {
605
- query: Query
606
- }
607
-
608
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
609
-
610
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
611
-
612
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
613
-
614
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
615
-
616
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
617
-
618
- type A @join__owner(graph: SERVICEA) @join__type(graph: SERVICEA, key: "id") @join__type(graph: SERVICEB, key: "id") {
619
- id: ID
620
- a: Int @join__field(graph: SERVICEB, requires: "b { x }")
621
- b: B
622
- }
623
-
624
- type B @join__owner(graph: SERVICEA) @join__type(graph: SERVICEA, key: "id") {
625
- id: ID
626
- x: Int
627
- }
628
-
629
- type Query {
630
- q: A
631
- }
632
-
633
- enum core__Purpose {
634
- """
635
- \`EXECUTION\` features provide metadata necessary to for operation execution.
636
- """
637
- EXECUTION
638
-
639
- """
640
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
641
- """
642
- SECURITY
643
- }
644
-
645
- scalar join__FieldSet
646
-
647
- enum join__Graph {
648
- SERVICEA @join__graph(name: "serviceA" url: "")
649
- SERVICEB @join__graph(name: "serviceB" url: "")
650
- }
651
- `;
652
-
653
- const schema = buildSupergraphSchema(supergraph)[0];
654
- expect(() => extractSubgraphsFromSupergraph(schema)).toThrow(
655
- 'Error extracting subgraph "serviceB" from the supergraph: this might be due to errors in subgraphs that were mistakenly ignored by federation 0.x versions but are rejected by federation 2.\n'
656
- + 'Please try composing your subgraphs with federation 2: this should help precisely pinpoint the problems and, once fixed, generate a correct federation 2 supergraph.\n'
657
- + '\n'
658
- + 'Details:\n'
659
- + '[serviceB] On field "A.a", for @requires(fields: "b { x }"): Cannot query field "b" on type "A" (if the field is defined in another subgraph, you need to add it to this subgraph with @external).'
660
- );
661
- })
662
-
663
- test('throw meaningful error for type erased from supergraph due to extending an entity without a key', () => {
664
- // Supergraph generated by fed1 composition from:
665
- // ServiceA:
666
- // type Query {
667
- // t: T
668
- // }
669
- //
670
- // type T @key(fields: "id") {
671
- // id: ID!
672
- // x: Int!
673
- // }
674
- //
675
- // ServiceB
676
- // extend type T {
677
- // x: Int! @external
678
- // }
679
- //
680
- // type Other @key(fields: "id") {
681
- // id: ID!
682
- // f: T @provides(fields: "x")
683
- // }
684
- //
685
- // The issue of that schema is that `T` is referenced in `ServiceB`, but because it extends an entity type
686
- // without a key and has only external fields, there is no remaining traces of its definition in `ServiceB`
687
- // in the supergraph. As extraction cannot make up the original definition out of thin air, it ends up erroring
688
- // when extracting `Other.t` due to not knowing that type.
689
- const supergraph = `
690
- schema
691
- @core(feature: "https://specs.apollo.dev/core/v0.2"),
692
- @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
693
- {
694
- query: Query
695
- }
696
-
697
- directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA
698
-
699
- directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION
700
-
701
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
702
-
703
- directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT
704
-
705
- directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT
706
-
707
- type Other
708
- @join__owner(graph: SERVICEB)
709
- @join__type(graph: SERVICEB, key: "id")
710
- {
711
- id: ID! @join__field(graph: SERVICEB)
712
- f: T @join__field(graph: SERVICEB, provides: "x")
713
- }
714
-
715
- type Query {
716
- t: T @join__field(graph: SERVICEA)
717
- }
718
-
719
- type T
720
- @join__owner(graph: SERVICEA)
721
- @join__type(graph: SERVICEA, key: "id")
722
- {
723
- id: ID! @join__field(graph: SERVICEA)
724
- x: Int! @join__field(graph: SERVICEA)
725
- }
726
-
727
- enum core__Purpose {
728
- EXECUTION
729
- SECURITY
730
- }
731
-
732
- scalar join__FieldSet
733
-
734
- enum join__Graph {
735
- SERVICEA @join__graph(name: "serviceA" url: "")
736
- SERVICEB @join__graph(name: "serviceB" url: "")
737
- }
738
- `;
739
-
740
- const schema = buildSupergraphSchema(supergraph)[0];
741
- expect(() => extractSubgraphsFromSupergraph(schema)).toThrow(
742
- 'Error extracting subgraphs from the supergraph: this might be due to errors in subgraphs that were mistakenly ignored by federation 0.x versions but are rejected by federation 2.\n'
743
- + 'Please try composing your subgraphs with federation 2: this should help precisely pinpoint the problems and, once fixed, generate a correct federation 2 supergraph.\n'
744
- + '\n'
745
- + 'Details:\n'
746
- + 'Error: Cannot find type "T" in subgraph "serviceB"'
747
- );
748
- })