@apollo/gateway 2.4.5 → 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 (64) hide show
  1. package/dist/__generated__/graphqlTypes.d.ts +19 -1
  2. package/dist/__generated__/graphqlTypes.d.ts.map +1 -1
  3. package/dist/__generated__/graphqlTypes.js +1 -0
  4. package/dist/__generated__/graphqlTypes.js.map +1 -1
  5. package/package.json +4 -4
  6. package/src/__generated__/graphqlTypes.ts +33 -2
  7. package/src/__mocks__/tsconfig.json +0 -7
  8. package/src/__tests__/.gitkeep +0 -0
  9. package/src/__tests__/CucumberREADME.md +0 -96
  10. package/src/__tests__/build-query-plan.feature +0 -1471
  11. package/src/__tests__/buildQueryPlan.test.ts +0 -1225
  12. package/src/__tests__/executeQueryPlan.conditions.test.ts +0 -1488
  13. package/src/__tests__/executeQueryPlan.introspection.test.ts +0 -140
  14. package/src/__tests__/executeQueryPlan.test.ts +0 -6140
  15. package/src/__tests__/execution-utils.ts +0 -124
  16. package/src/__tests__/gateway/__snapshots__/opentelemetry.test.ts.snap +0 -195
  17. package/src/__tests__/gateway/buildService.test.ts +0 -249
  18. package/src/__tests__/gateway/endToEnd.test.ts +0 -486
  19. package/src/__tests__/gateway/executor.test.ts +0 -96
  20. package/src/__tests__/gateway/extensions.test.ts +0 -37
  21. package/src/__tests__/gateway/lifecycle-hooks.test.ts +0 -239
  22. package/src/__tests__/gateway/opentelemetry.test.ts +0 -123
  23. package/src/__tests__/gateway/queryPlanCache.test.ts +0 -231
  24. package/src/__tests__/gateway/queryPlannerConfig.test.ts +0 -101
  25. package/src/__tests__/gateway/reporting.test.ts +0 -616
  26. package/src/__tests__/gateway/supergraphSdl.test.ts +0 -396
  27. package/src/__tests__/gateway/testUtils.ts +0 -89
  28. package/src/__tests__/integration/abstract-types.test.ts +0 -1861
  29. package/src/__tests__/integration/aliases.test.ts +0 -180
  30. package/src/__tests__/integration/boolean.test.ts +0 -279
  31. package/src/__tests__/integration/complex-key.test.ts +0 -197
  32. package/src/__tests__/integration/configuration.test.ts +0 -404
  33. package/src/__tests__/integration/custom-directives.test.ts +0 -174
  34. package/src/__tests__/integration/execution-style.test.ts +0 -35
  35. package/src/__tests__/integration/fragments.test.ts +0 -237
  36. package/src/__tests__/integration/list-key.test.ts +0 -128
  37. package/src/__tests__/integration/logger.test.ts +0 -122
  38. package/src/__tests__/integration/managed.test.ts +0 -319
  39. package/src/__tests__/integration/merge-arrays.test.ts +0 -34
  40. package/src/__tests__/integration/multiple-key.test.ts +0 -327
  41. package/src/__tests__/integration/mutations.test.ts +0 -287
  42. package/src/__tests__/integration/networkRequests.test.ts +0 -542
  43. package/src/__tests__/integration/nockMocks.ts +0 -157
  44. package/src/__tests__/integration/provides.test.ts +0 -77
  45. package/src/__tests__/integration/requires.test.ts +0 -359
  46. package/src/__tests__/integration/scope.test.ts +0 -557
  47. package/src/__tests__/integration/single-service.test.ts +0 -119
  48. package/src/__tests__/integration/unions.test.ts +0 -79
  49. package/src/__tests__/integration/value-types.test.ts +0 -382
  50. package/src/__tests__/integration/variables.test.ts +0 -120
  51. package/src/__tests__/nockAssertions.ts +0 -20
  52. package/src/__tests__/queryPlanCucumber.test.ts +0 -55
  53. package/src/__tests__/resultShaping.test.ts +0 -605
  54. package/src/__tests__/testSetup.ts +0 -1
  55. package/src/__tests__/tsconfig.json +0 -8
  56. package/src/core/__tests__/core.test.ts +0 -412
  57. package/src/datasources/__tests__/LocalGraphQLDataSource.test.ts +0 -51
  58. package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +0 -574
  59. package/src/schema-helper/__tests__/addExtensions.test.ts +0 -70
  60. package/src/supergraphManagers/IntrospectAndCompose/__tests__/IntrospectAndCompose.test.ts +0 -364
  61. package/src/supergraphManagers/IntrospectAndCompose/__tests__/loadServicesFromRemoteEndpoint.test.ts +0 -40
  62. package/src/supergraphManagers/UplinkSupergraphManager/__tests__/UplinkSupergraphManager.test.ts +0 -65
  63. package/src/supergraphManagers/UplinkSupergraphManager/__tests__/loadSupergraphSdlFromStorage.test.ts +0 -511
  64. package/src/utilities/__tests__/deepMerge.test.ts +0 -77
@@ -1,616 +0,0 @@
1
- import { gunzipSync } from 'zlib';
2
- import nock from 'nock';
3
- import gql from 'graphql-tag';
4
- import { ApolloServerPluginUsageReporting } from '@apollo/server/plugin/usageReporting';
5
- import { execute } from '@apollo/client/link/core';
6
- import { toPromise } from '@apollo/client/link/utils';
7
- import { createHttpLink } from '@apollo/client/link/http';
8
- import fetch from 'node-fetch';
9
- import { Plugin, Config, Refs } from 'pretty-format';
10
- import { Report, Trace } from '@apollo/usage-reporting-protobuf';
11
- import { fixtures } from 'apollo-federation-integration-testsuite';
12
- import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
13
- import resolvable, { Resolvable } from '@josephg/resolvable';
14
- import { startSubgraphsAndGateway, Services } from './testUtils';
15
-
16
- // Normalize specific fields that change often (eg timestamps) to static values,
17
- // to make snapshot testing viable. (If these helpers are more generally
18
- // useful, they could be moved to a different file.)
19
-
20
- const alreadyProcessed = '__already_processed__';
21
-
22
- function replaceFieldValuesSerializer(
23
- replacements: Record<string, any>,
24
- ): Plugin {
25
- const fieldNames = Object.keys(replacements);
26
- return {
27
- test(value: any) {
28
- return (
29
- value &&
30
- typeof value === 'object' &&
31
- !value[alreadyProcessed] &&
32
- fieldNames.some((n) => n in value)
33
- );
34
- },
35
-
36
- serialize(
37
- value: Record<string, any>,
38
- config: Config,
39
- indentation: string,
40
- depth: number,
41
- refs: Refs,
42
- printer: any,
43
- ): string {
44
- // Clone object so pretty-format doesn't consider it as a circular
45
- // reference. Put a special (non-enumerable) property on it so that *we*
46
- // don't reprocess it ourselves.
47
- const newValue = { ...value };
48
- Object.defineProperty(newValue, alreadyProcessed, { value: true });
49
- fieldNames.forEach((fn) => {
50
- if (fn in value) {
51
- const replacement = replacements[fn];
52
- if (typeof replacement === 'function') {
53
- newValue[fn] = replacement(value[fn]);
54
- } else {
55
- newValue[fn] = replacement;
56
- }
57
- }
58
- });
59
- return printer(newValue, config, indentation, depth, refs, printer);
60
- },
61
- };
62
- }
63
-
64
- expect.addSnapshotSerializer(
65
- replaceFieldValuesSerializer({
66
- header: '<HEADER>',
67
- // We do want to differentiate between zero and non-zero in these numbers.
68
- durationNs: (v: number) => (v ? 12345 : 0),
69
- sentTimeOffset: (v: number) => (v ? 23456 : 0),
70
- // endTime and startTime are annoyingly used both for top-level Timestamps
71
- // and for node-level nanosecond offsets. The Timestamps will get normalized
72
- // by the nanos/seconds below.
73
- startTime: (v: any) => (typeof v === 'string' ? '34567' : v),
74
- endTime: (v: any) => (typeof v === 'string' ? '45678' : v),
75
- nanos: 123000000,
76
- seconds: '1562203363',
77
- }),
78
- );
79
-
80
- describe('reporting', () => {
81
- let services: Services;
82
- let reportPromise: Resolvable<any>;
83
-
84
- beforeEach(async () => {
85
- reportPromise = resolvable();
86
-
87
- nockBeforeEach();
88
- nock('https://usage-reporting.api.apollographql.com')
89
- .post('/api/ingress/traces')
90
- .reply(200, (_: any, requestBody: string) => {
91
- reportPromise.resolve(requestBody);
92
- return 'ok';
93
- });
94
-
95
- services = await startSubgraphsAndGateway(
96
- fixtures,
97
- {
98
- gatewayServerConfig: {
99
- apollo: {
100
- key: 'service:foo:bar',
101
- graphRef: 'foo@current',
102
- },
103
- plugins: [
104
- ApolloServerPluginUsageReporting({
105
- sendReportsImmediately: true,
106
- }),
107
- ],
108
- },
109
- }
110
- );
111
- });
112
-
113
- afterEach(async () => {
114
- if (services) {
115
- await services.stop();
116
- }
117
-
118
- nockAfterEach();
119
- });
120
-
121
- it(`queries three services`, async () => {
122
- const query = gql`
123
- query {
124
- me {
125
- name {
126
- first
127
- last
128
- }
129
- }
130
- topProducts {
131
- name
132
- }
133
- }
134
- `;
135
-
136
- const result = await toPromise(
137
- execute(createHttpLink({ uri: services.gatewayUrl, fetch: fetch as any }), {
138
- query,
139
- }),
140
- );
141
- expect(result).toMatchInlineSnapshot(`
142
- Object {
143
- "data": Object {
144
- "me": Object {
145
- "name": Object {
146
- "first": "Ada",
147
- "last": "Lovelace",
148
- },
149
- },
150
- "topProducts": Array [
151
- Object {
152
- "name": "Table",
153
- },
154
- Object {
155
- "name": "Couch",
156
- },
157
- Object {
158
- "name": "Chair",
159
- },
160
- Object {
161
- "name": "Structure and Interpretation of Computer Programs (1996)",
162
- },
163
- Object {
164
- "name": "Object Oriented Software Construction (1997)",
165
- },
166
- ],
167
- },
168
- }
169
- `);
170
- const reportBody = await reportPromise;
171
- // nock returns binary bodies as hex strings
172
- const gzipReportBuffer = Buffer.from(reportBody, 'hex');
173
- const reportBuffer = gunzipSync(gzipReportBuffer);
174
- const report = Report.decode(reportBuffer);
175
-
176
- // Some handwritten tests to capture salient properties.
177
- const statsReportKey = '# -\n{me{name{first last}}topProducts{name}}';
178
- expect(Object.keys(report.tracesPerQuery)).toStrictEqual([statsReportKey]);
179
- expect(report.tracesPerQuery[statsReportKey]!.trace!.length).toBe(1);
180
- const trace = report.tracesPerQuery[statsReportKey]!.trace![0]! as Trace;
181
- // In the gateway, the root trace is just an empty node (unless there are errors).
182
- expect(trace.root!.child).toStrictEqual([]);
183
- // The query plan has (among other things) a fetch against 'accounts' and a
184
- // fetch against 'product'.
185
- expect(trace.queryPlan).toBeTruthy();
186
- const queryPlan = trace.queryPlan!;
187
- expect(queryPlan.parallel).toBeTruthy();
188
- expect(queryPlan.parallel!.nodes![0]!.fetch!.serviceName).toBe('accounts');
189
- expect(
190
- queryPlan.parallel!.nodes![0]!.fetch!.trace!.root!.child![0]!
191
- .responseName,
192
- ).toBe('me');
193
- expect(queryPlan.parallel!.nodes![1]!.sequence).toBeTruthy();
194
- expect(
195
- queryPlan.parallel!.nodes![1]!.sequence!.nodes![0]!.fetch!.serviceName,
196
- ).toBe('product');
197
- expect(
198
- queryPlan.parallel!.nodes![1]!.sequence!.nodes![0]!.fetch!.trace!.root!
199
- .child![0].responseName,
200
- ).toBe('topProducts');
201
-
202
- expect(report).toMatchInlineSnapshot(`
203
- Object {
204
- "endTime": Object {
205
- "nanos": 123000000,
206
- "seconds": "1562203363",
207
- },
208
- "header": "<HEADER>",
209
- "operationCount": 1,
210
- "tracesPerQuery": Object {
211
- "# -
212
- {me{name{first last}}topProducts{name}}": Object {
213
- "referencedFieldsByType": Object {
214
- "Name": Object {
215
- "fieldNames": Array [
216
- "first",
217
- "last",
218
- ],
219
- "isInterface": false,
220
- },
221
- "Product": Object {
222
- "fieldNames": Array [
223
- "name",
224
- ],
225
- "isInterface": true,
226
- },
227
- "Query": Object {
228
- "fieldNames": Array [
229
- "me",
230
- "topProducts",
231
- ],
232
- "isInterface": false,
233
- },
234
- "User": Object {
235
- "fieldNames": Array [
236
- "name",
237
- ],
238
- "isInterface": false,
239
- },
240
- },
241
- "trace": Array [
242
- Object {
243
- "cachePolicy": Object {
244
- "maxAgeNs": "30000000000",
245
- "scope": "PRIVATE",
246
- },
247
- "clientName": "",
248
- "clientVersion": "",
249
- "details": Object {},
250
- "durationNs": 12345,
251
- "endTime": Object {
252
- "nanos": 123000000,
253
- "seconds": "1562203363",
254
- },
255
- "fieldExecutionWeight": 1,
256
- "forbiddenOperation": false,
257
- "fullQueryCacheHit": false,
258
- "http": Object {
259
- "method": "POST",
260
- },
261
- "queryPlan": Object {
262
- "parallel": Object {
263
- "nodes": Array [
264
- Object {
265
- "fetch": Object {
266
- "receivedTime": Object {
267
- "nanos": 123000000,
268
- "seconds": "1562203363",
269
- },
270
- "sentTime": Object {
271
- "nanos": 123000000,
272
- "seconds": "1562203363",
273
- },
274
- "sentTimeOffset": 23456,
275
- "serviceName": "accounts",
276
- "trace": Object {
277
- "durationNs": 12345,
278
- "endTime": Object {
279
- "nanos": 123000000,
280
- "seconds": "1562203363",
281
- },
282
- "fieldExecutionWeight": 1,
283
- "root": Object {
284
- "child": Array [
285
- Object {
286
- "child": Array [
287
- Object {
288
- "child": Array [
289
- Object {
290
- "endTime": "45678",
291
- "parentType": "Name",
292
- "responseName": "first",
293
- "startTime": "34567",
294
- "type": "String",
295
- },
296
- Object {
297
- "endTime": "45678",
298
- "parentType": "Name",
299
- "responseName": "last",
300
- "startTime": "34567",
301
- "type": "String",
302
- },
303
- ],
304
- "endTime": "45678",
305
- "parentType": "User",
306
- "responseName": "name",
307
- "startTime": "34567",
308
- "type": "Name",
309
- },
310
- ],
311
- "endTime": "45678",
312
- "parentType": "Query",
313
- "responseName": "me",
314
- "startTime": "34567",
315
- "type": "User",
316
- },
317
- ],
318
- },
319
- "startTime": Object {
320
- "nanos": 123000000,
321
- "seconds": "1562203363",
322
- },
323
- },
324
- "traceParsingFailed": false,
325
- },
326
- },
327
- Object {
328
- "sequence": Object {
329
- "nodes": Array [
330
- Object {
331
- "fetch": Object {
332
- "receivedTime": Object {
333
- "nanos": 123000000,
334
- "seconds": "1562203363",
335
- },
336
- "sentTime": Object {
337
- "nanos": 123000000,
338
- "seconds": "1562203363",
339
- },
340
- "sentTimeOffset": 23456,
341
- "serviceName": "product",
342
- "trace": Object {
343
- "durationNs": 12345,
344
- "endTime": Object {
345
- "nanos": 123000000,
346
- "seconds": "1562203363",
347
- },
348
- "fieldExecutionWeight": 1,
349
- "root": Object {
350
- "child": Array [
351
- Object {
352
- "child": Array [
353
- Object {
354
- "child": Array [
355
- Object {
356
- "endTime": "45678",
357
- "parentType": "Furniture",
358
- "responseName": "name",
359
- "startTime": "34567",
360
- "type": "String",
361
- },
362
- ],
363
- "index": 0,
364
- },
365
- Object {
366
- "child": Array [
367
- Object {
368
- "endTime": "45678",
369
- "parentType": "Furniture",
370
- "responseName": "name",
371
- "startTime": "34567",
372
- "type": "String",
373
- },
374
- ],
375
- "index": 1,
376
- },
377
- Object {
378
- "child": Array [
379
- Object {
380
- "endTime": "45678",
381
- "parentType": "Furniture",
382
- "responseName": "name",
383
- "startTime": "34567",
384
- "type": "String",
385
- },
386
- ],
387
- "index": 2,
388
- },
389
- Object {
390
- "child": Array [
391
- Object {
392
- "endTime": "45678",
393
- "parentType": "Book",
394
- "responseName": "isbn",
395
- "startTime": "34567",
396
- "type": "String!",
397
- },
398
- ],
399
- "index": 3,
400
- },
401
- Object {
402
- "child": Array [
403
- Object {
404
- "endTime": "45678",
405
- "parentType": "Book",
406
- "responseName": "isbn",
407
- "startTime": "34567",
408
- "type": "String!",
409
- },
410
- ],
411
- "index": 4,
412
- },
413
- ],
414
- "endTime": "45678",
415
- "parentType": "Query",
416
- "responseName": "topProducts",
417
- "startTime": "34567",
418
- "type": "[Product]",
419
- },
420
- ],
421
- },
422
- "startTime": Object {
423
- "nanos": 123000000,
424
- "seconds": "1562203363",
425
- },
426
- },
427
- "traceParsingFailed": false,
428
- },
429
- },
430
- Object {
431
- "flatten": Object {
432
- "node": Object {
433
- "fetch": Object {
434
- "receivedTime": Object {
435
- "nanos": 123000000,
436
- "seconds": "1562203363",
437
- },
438
- "sentTime": Object {
439
- "nanos": 123000000,
440
- "seconds": "1562203363",
441
- },
442
- "sentTimeOffset": 23456,
443
- "serviceName": "books",
444
- "trace": Object {
445
- "durationNs": 12345,
446
- "endTime": Object {
447
- "nanos": 123000000,
448
- "seconds": "1562203363",
449
- },
450
- "fieldExecutionWeight": 1,
451
- "root": Object {
452
- "child": Array [
453
- Object {
454
- "child": Array [
455
- Object {
456
- "child": Array [
457
- Object {
458
- "endTime": "45678",
459
- "parentType": "Book",
460
- "responseName": "title",
461
- "startTime": "34567",
462
- "type": "String",
463
- },
464
- Object {
465
- "endTime": "45678",
466
- "parentType": "Book",
467
- "responseName": "year",
468
- "startTime": "34567",
469
- "type": "Int",
470
- },
471
- ],
472
- "index": 0,
473
- },
474
- Object {
475
- "child": Array [
476
- Object {
477
- "endTime": "45678",
478
- "parentType": "Book",
479
- "responseName": "title",
480
- "startTime": "34567",
481
- "type": "String",
482
- },
483
- Object {
484
- "endTime": "45678",
485
- "parentType": "Book",
486
- "responseName": "year",
487
- "startTime": "34567",
488
- "type": "Int",
489
- },
490
- ],
491
- "index": 1,
492
- },
493
- ],
494
- "endTime": "45678",
495
- "parentType": "Query",
496
- "responseName": "_entities",
497
- "startTime": "34567",
498
- "type": "[_Entity]!",
499
- },
500
- ],
501
- },
502
- "startTime": Object {
503
- "nanos": 123000000,
504
- "seconds": "1562203363",
505
- },
506
- },
507
- "traceParsingFailed": false,
508
- },
509
- },
510
- "responsePath": Array [
511
- Object {
512
- "fieldName": "topProducts",
513
- },
514
- Object {
515
- "fieldName": "@",
516
- },
517
- ],
518
- },
519
- },
520
- Object {
521
- "flatten": Object {
522
- "node": Object {
523
- "fetch": Object {
524
- "receivedTime": Object {
525
- "nanos": 123000000,
526
- "seconds": "1562203363",
527
- },
528
- "sentTime": Object {
529
- "nanos": 123000000,
530
- "seconds": "1562203363",
531
- },
532
- "sentTimeOffset": 23456,
533
- "serviceName": "product",
534
- "trace": Object {
535
- "durationNs": 12345,
536
- "endTime": Object {
537
- "nanos": 123000000,
538
- "seconds": "1562203363",
539
- },
540
- "fieldExecutionWeight": 1,
541
- "root": Object {
542
- "child": Array [
543
- Object {
544
- "child": Array [
545
- Object {
546
- "child": Array [
547
- Object {
548
- "endTime": "45678",
549
- "parentType": "Book",
550
- "responseName": "name",
551
- "startTime": "34567",
552
- "type": "String",
553
- },
554
- ],
555
- "index": 0,
556
- },
557
- Object {
558
- "child": Array [
559
- Object {
560
- "endTime": "45678",
561
- "parentType": "Book",
562
- "responseName": "name",
563
- "startTime": "34567",
564
- "type": "String",
565
- },
566
- ],
567
- "index": 1,
568
- },
569
- ],
570
- "endTime": "45678",
571
- "parentType": "Query",
572
- "responseName": "_entities",
573
- "startTime": "34567",
574
- "type": "[_Entity]!",
575
- },
576
- ],
577
- },
578
- "startTime": Object {
579
- "nanos": 123000000,
580
- "seconds": "1562203363",
581
- },
582
- },
583
- "traceParsingFailed": false,
584
- },
585
- },
586
- "responsePath": Array [
587
- Object {
588
- "fieldName": "topProducts",
589
- },
590
- Object {
591
- "fieldName": "@",
592
- },
593
- ],
594
- },
595
- },
596
- ],
597
- },
598
- },
599
- ],
600
- },
601
- },
602
- "registeredOperation": false,
603
- "root": Object {},
604
- "startTime": Object {
605
- "nanos": 123000000,
606
- "seconds": "1562203363",
607
- },
608
- },
609
- ],
610
- },
611
- },
612
- "tracesPreAggregated": false,
613
- }
614
- `);
615
- });
616
- });