@apollo/gateway 2.0.0-alpha.2 → 2.0.0-alpha.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 (130) hide show
  1. package/dist/config.d.ts +43 -15
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +28 -18
  4. package/dist/config.js.map +1 -1
  5. package/dist/datasources/LocalGraphQLDataSource.js.map +1 -1
  6. package/dist/datasources/RemoteGraphQLDataSource.d.ts.map +1 -1
  7. package/dist/datasources/RemoteGraphQLDataSource.js +4 -1
  8. package/dist/datasources/RemoteGraphQLDataSource.js.map +1 -1
  9. package/dist/executeQueryPlan.d.ts.map +1 -1
  10. package/dist/executeQueryPlan.js +2 -2
  11. package/dist/executeQueryPlan.js.map +1 -1
  12. package/dist/index.d.ts +37 -22
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +199 -283
  15. package/dist/index.js.map +1 -1
  16. package/dist/schema-helper/addResolversToSchema.d.ts +4 -0
  17. package/dist/schema-helper/addResolversToSchema.d.ts.map +1 -0
  18. package/dist/schema-helper/addResolversToSchema.js +62 -0
  19. package/dist/schema-helper/addResolversToSchema.js.map +1 -0
  20. package/dist/schema-helper/error.d.ts +6 -0
  21. package/dist/schema-helper/error.d.ts.map +1 -0
  22. package/dist/schema-helper/error.js +14 -0
  23. package/dist/schema-helper/error.js.map +1 -0
  24. package/dist/schema-helper/index.d.ts +4 -0
  25. package/dist/schema-helper/index.d.ts.map +1 -0
  26. package/dist/schema-helper/index.js +16 -0
  27. package/dist/schema-helper/index.js.map +1 -0
  28. package/dist/schema-helper/resolverMap.d.ts +16 -0
  29. package/dist/schema-helper/resolverMap.d.ts.map +1 -0
  30. package/dist/schema-helper/resolverMap.js +3 -0
  31. package/dist/schema-helper/resolverMap.js.map +1 -0
  32. package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts +31 -0
  33. package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts.map +1 -0
  34. package/dist/supergraphManagers/IntrospectAndCompose/index.js +112 -0
  35. package/dist/supergraphManagers/IntrospectAndCompose/index.js.map +1 -0
  36. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts +12 -0
  37. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts.map +1 -0
  38. package/dist/{loadServicesFromRemoteEndpoint.js → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js} +6 -6
  39. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js.map +1 -0
  40. package/dist/supergraphManagers/LegacyFetcher/index.d.ts +33 -0
  41. package/dist/supergraphManagers/LegacyFetcher/index.d.ts.map +1 -0
  42. package/dist/supergraphManagers/LegacyFetcher/index.js +149 -0
  43. package/dist/supergraphManagers/LegacyFetcher/index.js.map +1 -0
  44. package/dist/supergraphManagers/LocalCompose/index.d.ts +19 -0
  45. package/dist/supergraphManagers/LocalCompose/index.d.ts.map +1 -0
  46. package/dist/supergraphManagers/LocalCompose/index.js +55 -0
  47. package/dist/supergraphManagers/LocalCompose/index.js.map +1 -0
  48. package/dist/supergraphManagers/UplinkFetcher/index.d.ts +33 -0
  49. package/dist/supergraphManagers/UplinkFetcher/index.d.ts.map +1 -0
  50. package/dist/supergraphManagers/UplinkFetcher/index.js +98 -0
  51. package/dist/supergraphManagers/UplinkFetcher/index.js.map +1 -0
  52. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts +25 -0
  53. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts.map +1 -0
  54. package/dist/{loadSupergraphSdlFromStorage.js → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js} +40 -15
  55. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js.map +1 -0
  56. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts +13 -0
  57. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts.map +1 -0
  58. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js +85 -0
  59. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js.map +1 -0
  60. package/dist/supergraphManagers/index.d.ts +6 -0
  61. package/dist/supergraphManagers/index.d.ts.map +1 -0
  62. package/dist/supergraphManagers/index.js +14 -0
  63. package/dist/supergraphManagers/index.js.map +1 -0
  64. package/dist/utilities/createHash.d.ts +2 -0
  65. package/dist/utilities/createHash.d.ts.map +1 -0
  66. package/dist/utilities/createHash.js +15 -0
  67. package/dist/utilities/createHash.js.map +1 -0
  68. package/dist/utilities/isNodeLike.d.ts +3 -0
  69. package/dist/utilities/isNodeLike.d.ts.map +1 -0
  70. package/dist/utilities/isNodeLike.js +8 -0
  71. package/dist/utilities/isNodeLike.js.map +1 -0
  72. package/package.json +9 -7
  73. package/src/__mocks__/make-fetch-happen-fetcher.ts +3 -1
  74. package/src/__tests__/build-query-plan.feature +52 -0
  75. package/src/__tests__/executeQueryPlan.test.ts +599 -1
  76. package/src/__tests__/execution-utils.ts +3 -3
  77. package/src/__tests__/gateway/buildService.test.ts +3 -3
  78. package/src/__tests__/gateway/endToEnd.test.ts +1 -1
  79. package/src/__tests__/gateway/executor.test.ts +1 -1
  80. package/src/__tests__/gateway/lifecycle-hooks.test.ts +59 -125
  81. package/src/__tests__/gateway/opentelemetry.test.ts +8 -4
  82. package/src/__tests__/gateway/queryPlanCache.test.ts +25 -12
  83. package/src/__tests__/gateway/reporting.test.ts +42 -13
  84. package/src/__tests__/gateway/supergraphSdl.test.ts +397 -0
  85. package/src/__tests__/integration/aliases.test.ts +9 -4
  86. package/src/__tests__/integration/configuration.test.ts +146 -9
  87. package/src/__tests__/integration/logger.test.ts +1 -1
  88. package/src/__tests__/integration/networkRequests.test.ts +99 -147
  89. package/src/__tests__/integration/nockMocks.ts +30 -16
  90. package/src/__tests__/nockAssertions.ts +20 -0
  91. package/src/config.ts +149 -38
  92. package/src/datasources/LocalGraphQLDataSource.ts +1 -1
  93. package/src/datasources/RemoteGraphQLDataSource.ts +8 -2
  94. package/src/datasources/__tests__/LocalGraphQLDataSource.test.ts +1 -1
  95. package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +4 -4
  96. package/src/executeQueryPlan.ts +14 -2
  97. package/src/index.ts +325 -452
  98. package/src/schema-helper/addResolversToSchema.ts +83 -0
  99. package/src/schema-helper/error.ts +11 -0
  100. package/src/schema-helper/index.ts +3 -0
  101. package/src/schema-helper/resolverMap.ts +23 -0
  102. package/src/supergraphManagers/IntrospectAndCompose/__tests__/IntrospectAndCompose.test.ts +370 -0
  103. package/src/{__tests__ → supergraphManagers/IntrospectAndCompose/__tests__}/loadServicesFromRemoteEndpoint.test.ts +5 -5
  104. package/src/supergraphManagers/IntrospectAndCompose/__tests__/tsconfig.json +8 -0
  105. package/src/supergraphManagers/IntrospectAndCompose/index.ts +160 -0
  106. package/src/{loadServicesFromRemoteEndpoint.ts → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts} +6 -6
  107. package/src/supergraphManagers/LegacyFetcher/index.ts +226 -0
  108. package/src/supergraphManagers/LocalCompose/index.ts +79 -0
  109. package/src/supergraphManagers/UplinkFetcher/__tests__/loadSupergraphSdlFromStorage.test.ts +397 -0
  110. package/src/supergraphManagers/UplinkFetcher/__tests__/tsconfig.json +8 -0
  111. package/src/supergraphManagers/UplinkFetcher/index.ts +130 -0
  112. package/src/{loadSupergraphSdlFromStorage.ts → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts} +68 -17
  113. package/src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts +126 -0
  114. package/src/supergraphManagers/index.ts +5 -0
  115. package/src/utilities/__tests__/cleanErrorOfInaccessibleElements.test.ts +12 -9
  116. package/src/utilities/createHash.ts +10 -0
  117. package/src/utilities/isNodeLike.ts +11 -0
  118. package/dist/loadServicesFromRemoteEndpoint.d.ts +0 -13
  119. package/dist/loadServicesFromRemoteEndpoint.d.ts.map +0 -1
  120. package/dist/loadServicesFromRemoteEndpoint.js.map +0 -1
  121. package/dist/loadSupergraphSdlFromStorage.d.ts +0 -13
  122. package/dist/loadSupergraphSdlFromStorage.d.ts.map +0 -1
  123. package/dist/loadSupergraphSdlFromStorage.js.map +0 -1
  124. package/dist/outOfBandReporter.d.ts +0 -15
  125. package/dist/outOfBandReporter.d.ts.map +0 -1
  126. package/dist/outOfBandReporter.js +0 -88
  127. package/dist/outOfBandReporter.js.map +0 -1
  128. package/src/__tests__/gateway/composedSdl.test.ts +0 -44
  129. package/src/__tests__/loadSupergraphSdlFromStorage.test.ts +0 -694
  130. package/src/outOfBandReporter.ts +0 -128
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LegacyFetcher = void 0;
7
+ const resolvable_1 = __importDefault(require("@josephg/resolvable"));
8
+ const config_1 = require("../../config");
9
+ const composition_1 = require("@apollo/composition");
10
+ class LegacyFetcher {
11
+ constructor(options) {
12
+ this.timerRef = null;
13
+ this.config = options;
14
+ this.state = { phase: 'initialized' };
15
+ this.issueDeprecationWarnings();
16
+ }
17
+ issueDeprecationWarnings() {
18
+ var _a, _b;
19
+ if ('experimental_updateSupergraphSdl' in this.config.gatewayConfig) {
20
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.warn('The `experimental_updateSupergraphSdl` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the function form of the `supergraphSdl` configuration option.');
21
+ }
22
+ if ('experimental_updateServiceDefinitions' in this.config.gatewayConfig) {
23
+ (_b = this.config.logger) === null || _b === void 0 ? void 0 : _b.warn('The `experimental_updateServiceDefinitions` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the function form of the `supergraphSdl` configuration option.');
24
+ }
25
+ }
26
+ async initialize({ update, healthCheck, getDataSource, }) {
27
+ this.update = update;
28
+ this.getDataSource = getDataSource;
29
+ if (this.config.subgraphHealthCheck) {
30
+ this.healthCheck = healthCheck;
31
+ }
32
+ let initialSupergraphSdl = null;
33
+ try {
34
+ initialSupergraphSdl = await this.updateSupergraphSdl();
35
+ }
36
+ catch (e) {
37
+ this.logUpdateFailure(e);
38
+ throw e;
39
+ }
40
+ if (this.config.pollIntervalInMs) {
41
+ this.beginPolling();
42
+ }
43
+ return {
44
+ supergraphSdl: initialSupergraphSdl,
45
+ cleanup: async () => {
46
+ if (this.state.phase === 'polling') {
47
+ await this.state.pollingPromise;
48
+ }
49
+ this.state = { phase: 'stopped' };
50
+ if (this.timerRef) {
51
+ clearTimeout(this.timerRef);
52
+ this.timerRef = null;
53
+ }
54
+ },
55
+ };
56
+ }
57
+ async updateSupergraphSdl() {
58
+ var _a, _b;
59
+ const result = await this.config.updateServiceDefinitions(this.config.gatewayConfig);
60
+ if ((0, config_1.isSupergraphSdlUpdate)(result)) {
61
+ if (this.compositionId === result.id)
62
+ return null;
63
+ await ((_a = this.healthCheck) === null || _a === void 0 ? void 0 : _a.call(this, result.supergraphSdl));
64
+ this.compositionId = result.id;
65
+ return result.supergraphSdl;
66
+ }
67
+ else if ((0, config_1.isServiceDefinitionUpdate)(result)) {
68
+ const supergraphSdl = this.updateByComposition(result);
69
+ if (!supergraphSdl)
70
+ return null;
71
+ await ((_b = this.healthCheck) === null || _b === void 0 ? void 0 : _b.call(this, supergraphSdl));
72
+ return supergraphSdl;
73
+ }
74
+ else {
75
+ throw new Error('Programming error: unexpected result type from `updateServiceDefinitions`');
76
+ }
77
+ }
78
+ updateByComposition(result) {
79
+ var _a, _b;
80
+ if (!result.serviceDefinitions ||
81
+ JSON.stringify(this.serviceDefinitions) ===
82
+ JSON.stringify(result.serviceDefinitions)) {
83
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.debug('No change in service definitions since last check.');
84
+ return null;
85
+ }
86
+ if (this.serviceDefinitions) {
87
+ (_b = this.config.logger) === null || _b === void 0 ? void 0 : _b.info('New service definitions were found.');
88
+ }
89
+ this.serviceDefinitions = result.serviceDefinitions;
90
+ const supergraphSdl = this.createSupergraphFromServiceList(result.serviceDefinitions);
91
+ if (!supergraphSdl) {
92
+ throw new Error("A valid schema couldn't be composed. Falling back to previous schema.");
93
+ }
94
+ else {
95
+ return supergraphSdl;
96
+ }
97
+ }
98
+ createSupergraphFromServiceList(serviceList) {
99
+ var _a, _b, _c;
100
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.debug(`Composing schema from service list: \n${serviceList
101
+ .map(({ name, url }) => ` ${url || 'local'}: ${name}`)
102
+ .join('\n')}`);
103
+ const compositionResult = (0, composition_1.composeServices)(serviceList);
104
+ if (compositionResult.errors) {
105
+ const { errors } = compositionResult;
106
+ throw Error("A valid schema couldn't be composed. The following composition errors were found:\n" +
107
+ errors.map((e) => '\t' + e.message).join('\n'));
108
+ }
109
+ else {
110
+ const { supergraphSdl } = compositionResult;
111
+ for (const service of serviceList) {
112
+ (_b = this.getDataSource) === null || _b === void 0 ? void 0 : _b.call(this, service);
113
+ }
114
+ (_c = this.config.logger) === null || _c === void 0 ? void 0 : _c.debug('Schema loaded and ready for execution');
115
+ return supergraphSdl;
116
+ }
117
+ }
118
+ beginPolling() {
119
+ this.state = { phase: 'polling' };
120
+ this.poll();
121
+ }
122
+ poll() {
123
+ this.timerRef = setTimeout(async () => {
124
+ var _a;
125
+ if (this.state.phase === 'polling') {
126
+ const pollingPromise = (0, resolvable_1.default)();
127
+ this.state.pollingPromise = pollingPromise;
128
+ try {
129
+ const maybeNewSupergraphSdl = await this.updateSupergraphSdl();
130
+ if (maybeNewSupergraphSdl) {
131
+ (_a = this.update) === null || _a === void 0 ? void 0 : _a.call(this, maybeNewSupergraphSdl);
132
+ }
133
+ }
134
+ catch (e) {
135
+ this.logUpdateFailure(e);
136
+ }
137
+ pollingPromise.resolve();
138
+ }
139
+ this.poll();
140
+ }, this.config.pollIntervalInMs);
141
+ }
142
+ logUpdateFailure(e) {
143
+ var _a, _b;
144
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.error('LegacyFetcher failed to update supergraph with the following error: ' +
145
+ ((_b = e.message) !== null && _b !== void 0 ? _b : e));
146
+ }
147
+ }
148
+ exports.LegacyFetcher = LegacyFetcher;
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/supergraphManagers/LegacyFetcher/index.ts"],"names":[],"mappings":";;;;;;AAOA,qEAA6C;AAC7C,yCAQsB;AAMtB,qDAAsD;AAgBtD,MAAa,aAAa;IAUxB,YAAY,OAA6B;QALjC,aAAQ,GAA0B,IAAI,CAAC;QAM7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;QACtC,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAEO,wBAAwB;;QAC9B,IAAI,kCAAkC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACnE,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,IAAI,CACtB,4MAA4M,CAC7M,CAAC;SACH;QAED,IAAI,uCAAuC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACxE,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,IAAI,CACtB,iNAAiN,CAClN,CAAC;SACH;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,EACtB,MAAM,EACN,WAAW,EACX,aAAa,GACY;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE;YACnC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;SAChC;QAED,IAAI,oBAAoB,GAAkB,I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iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;iBAC1B;gBACD,cAAc,CAAC,OAAO,EAAE,CAAC;aAC1B;YAED,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAiB,CAAC,CAAC;IACpC,CAAC;IAEO,gBAAgB,CAAC,CAAM;;QAC7B,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,KAAK,CACvB,sEAAsE;YACpE,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC,CACnB,CAAC;IACJ,CAAC;CACF;AA3LD,sCA2LC"}
@@ -0,0 +1,19 @@
1
+ import { Logger } from 'apollo-server-types';
2
+ import { SupergraphSdlHookOptions, SupergraphManager } from '../../config';
3
+ import { ServiceDefinition } from '@apollo/federation-internals';
4
+ export interface LocalComposeOptions {
5
+ logger?: Logger;
6
+ localServiceList: ServiceDefinition[];
7
+ }
8
+ export declare class LocalCompose implements SupergraphManager {
9
+ private config;
10
+ private getDataSource?;
11
+ constructor(options: LocalComposeOptions);
12
+ private issueDeprecationWarnings;
13
+ initialize({ getDataSource }: SupergraphSdlHookOptions): Promise<{
14
+ supergraphSdl: string;
15
+ }>;
16
+ private createSupergraphFromServiceList;
17
+ private logUpdateFailure;
18
+ }
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/LocalCompose/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAEL,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;CACvC;AAED,qBAAa,YAAa,YAAW,iBAAiB;IACpD,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,aAAa,CAAC,CAAwB;gBAElC,OAAO,EAAE,mBAAmB;IAKxC,OAAO,CAAC,wBAAwB;IAMnB,UAAU,CAAC,EAAE,aAAa,EAAE,EAAE,wBAAwB;;;IAgBnE,OAAO,CAAC,+BAA+B;IA0BvC,OAAO,CAAC,gBAAgB;CAMzB"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalCompose = void 0;
4
+ const composition_1 = require("@apollo/composition");
5
+ class LocalCompose {
6
+ constructor(options) {
7
+ this.config = options;
8
+ this.issueDeprecationWarnings();
9
+ }
10
+ issueDeprecationWarnings() {
11
+ var _a;
12
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.warn('The `localServiceList` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the `LocalCompose` supergraph manager exported by `@apollo/gateway`.');
13
+ }
14
+ async initialize({ getDataSource }) {
15
+ this.getDataSource = getDataSource;
16
+ let supergraphSdl = null;
17
+ try {
18
+ supergraphSdl = this.createSupergraphFromServiceList(this.config.localServiceList);
19
+ }
20
+ catch (e) {
21
+ this.logUpdateFailure(e);
22
+ throw e;
23
+ }
24
+ return {
25
+ supergraphSdl,
26
+ };
27
+ }
28
+ createSupergraphFromServiceList(serviceList) {
29
+ var _a, _b, _c;
30
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.debug(`Composing schema from service list: \n${serviceList
31
+ .map(({ name, url }) => ` ${url || 'local'}: ${name}`)
32
+ .join('\n')}`);
33
+ const compositionResult = (0, composition_1.composeServices)(serviceList);
34
+ const errors = compositionResult.errors;
35
+ if (errors) {
36
+ throw Error("A valid schema couldn't be composed. The following composition errors were found:\n" +
37
+ errors.map((e) => '\t' + e.message).join('\n'));
38
+ }
39
+ else {
40
+ const { supergraphSdl } = compositionResult;
41
+ for (const service of serviceList) {
42
+ (_b = this.getDataSource) === null || _b === void 0 ? void 0 : _b.call(this, service);
43
+ }
44
+ (_c = this.config.logger) === null || _c === void 0 ? void 0 : _c.debug('Schema loaded and ready for execution');
45
+ return supergraphSdl;
46
+ }
47
+ }
48
+ logUpdateFailure(e) {
49
+ var _a, _b;
50
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.error('LocalCompose failed to update supergraph with the following error: ' +
51
+ ((_b = e.message) !== null && _b !== void 0 ? _b : e));
52
+ }
53
+ }
54
+ exports.LocalCompose = LocalCompose;
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/supergraphManagers/LocalCompose/index.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAatD,MAAa,YAAY;IAIvB,YAAY,OAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAEO,wBAAwB;;QAC9B,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,IAAI,CACtB,kMAAkM,CACnM,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,EAAE,aAAa,EAA4B;QACjE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,aAAa,GAAkB,IAAI,CAAC;QACxC,IAAI;YACF,aAAa,GAAG,IAAI,CAAC,+BAA+B,CAClD,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAC7B,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,CAAC,CAAC;SACT;QACD,OAAO;YACL,aAAa;SACd,CAAC;IACJ,CAAC;IAEO,+BAA+B,CAAC,WAAgC;;QACtE,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,KAAK,CACvB,yCAAyC,WAAW;aACjD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;aACtD,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;QAEF,MAAM,iBAAiB,GAAG,IAAA,6BAAe,EAAC,WAAW,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;QACxC,IAAI,MAAM,EAAE;YACV,MAAM,KAAK,CACT,qFAAqF;gBACnF,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACjD,CAAC;SACH;aAAM;YACL,MAAM,EAAE,aAAa,EAAE,GAAG,iBAAiB,CAAC;YAC5C,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE;gBACjC,MAAA,IAAI,CAAC,aAAa,+CAAlB,IAAI,EAAiB,OAAO,CAAC,CAAC;aAC/B;YAED,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAEnE,OAAO,aAAa,CAAC;SACtB;IACH,CAAC;IAEO,gBAAgB,CAAC,CAAM;;QAC7B,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,KAAK,CACvB,qEAAqE;YACnE,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC,CACnB,CAAC;IACJ,CAAC;CACF;AA/DD,oCA+DC"}
@@ -0,0 +1,33 @@
1
+ import { fetch } from 'apollo-server-env';
2
+ import { Logger } from 'apollo-server-types';
3
+ import { SupergraphManager, SupergraphSdlHookOptions } from '../../config';
4
+ export interface UplinkFetcherOptions {
5
+ pollIntervalInMs: number;
6
+ subgraphHealthCheck?: boolean;
7
+ graphRef: string;
8
+ apiKey: string;
9
+ fetcher: typeof fetch;
10
+ maxRetries: number;
11
+ uplinkEndpoints: string[];
12
+ logger?: Logger;
13
+ }
14
+ export declare class UplinkFetcher implements SupergraphManager {
15
+ private config;
16
+ private update?;
17
+ private healthCheck?;
18
+ private timerRef;
19
+ private state;
20
+ private errorReportingEndpoint;
21
+ private compositionId?;
22
+ private fetchCount;
23
+ constructor(options: UplinkFetcherOptions);
24
+ initialize({ update, healthCheck }: SupergraphSdlHookOptions): Promise<{
25
+ supergraphSdl: string;
26
+ cleanup: () => Promise<void>;
27
+ }>;
28
+ private updateSupergraphSdl;
29
+ private beginPolling;
30
+ private poll;
31
+ private logUpdateFailure;
32
+ }
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAI3E,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,KAAK,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAOD,qBAAa,aAAc,YAAW,iBAAiB;IACrD,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAC,CAA8B;IAC7C,OAAO,CAAC,WAAW,CAAC,CAA8B;IAClD,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,sBAAsB,CACkC;IAChE,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,UAAU,CAAa;gBAEnB,OAAO,EAAE,oBAAoB;IAK5B,UAAU,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,wBAAwB;;;;YAoC3D,mBAAmB;IAsBjC,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,IAAI;IAqBZ,OAAO,CAAC,gBAAgB;CAMzB"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UplinkFetcher = void 0;
7
+ const resolvable_1 = __importDefault(require("@josephg/resolvable"));
8
+ const loadSupergraphSdlFromStorage_1 = require("./loadSupergraphSdlFromStorage");
9
+ class UplinkFetcher {
10
+ constructor(options) {
11
+ var _a;
12
+ this.timerRef = null;
13
+ this.errorReportingEndpoint = (_a = process.env.APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT) !== null && _a !== void 0 ? _a : undefined;
14
+ this.fetchCount = 0;
15
+ this.config = options;
16
+ this.state = { phase: 'initialized' };
17
+ }
18
+ async initialize({ update, healthCheck }) {
19
+ this.update = update;
20
+ if (this.config.subgraphHealthCheck) {
21
+ this.healthCheck = healthCheck;
22
+ }
23
+ let initialSupergraphSdl = null;
24
+ try {
25
+ initialSupergraphSdl = await this.updateSupergraphSdl();
26
+ }
27
+ catch (e) {
28
+ this.logUpdateFailure(e);
29
+ throw e;
30
+ }
31
+ this.beginPolling();
32
+ return {
33
+ supergraphSdl: initialSupergraphSdl,
34
+ cleanup: async () => {
35
+ if (this.state.phase === 'polling') {
36
+ await this.state.pollingPromise;
37
+ }
38
+ this.state = { phase: 'stopped' };
39
+ if (this.timerRef) {
40
+ clearTimeout(this.timerRef);
41
+ this.timerRef = null;
42
+ }
43
+ },
44
+ };
45
+ }
46
+ async updateSupergraphSdl() {
47
+ var _a, _b;
48
+ const result = await (0, loadSupergraphSdlFromStorage_1.loadSupergraphSdlFromUplinks)({
49
+ graphRef: this.config.graphRef,
50
+ apiKey: this.config.apiKey,
51
+ endpoints: this.config.uplinkEndpoints,
52
+ errorReportingEndpoint: this.errorReportingEndpoint,
53
+ fetcher: this.config.fetcher,
54
+ compositionId: (_a = this.compositionId) !== null && _a !== void 0 ? _a : null,
55
+ maxRetries: this.config.maxRetries,
56
+ roundRobinSeed: this.fetchCount++,
57
+ });
58
+ if (!result) {
59
+ return null;
60
+ }
61
+ else {
62
+ this.compositionId = result.id;
63
+ await ((_b = this.healthCheck) === null || _b === void 0 ? void 0 : _b.call(this, result.supergraphSdl));
64
+ return result.supergraphSdl;
65
+ }
66
+ }
67
+ beginPolling() {
68
+ this.state = { phase: 'polling' };
69
+ this.poll();
70
+ }
71
+ poll() {
72
+ this.timerRef = setTimeout(async () => {
73
+ var _a;
74
+ if (this.state.phase === 'polling') {
75
+ const pollingPromise = (0, resolvable_1.default)();
76
+ this.state.pollingPromise = pollingPromise;
77
+ try {
78
+ const maybeNewSupergraphSdl = await this.updateSupergraphSdl();
79
+ if (maybeNewSupergraphSdl) {
80
+ (_a = this.update) === null || _a === void 0 ? void 0 : _a.call(this, maybeNewSupergraphSdl);
81
+ }
82
+ }
83
+ catch (e) {
84
+ this.logUpdateFailure(e);
85
+ }
86
+ pollingPromise.resolve();
87
+ }
88
+ this.poll();
89
+ }, this.config.pollIntervalInMs);
90
+ }
91
+ logUpdateFailure(e) {
92
+ var _a, _b;
93
+ (_a = this.config.logger) === null || _a === void 0 ? void 0 : _a.error('UplinkFetcher failed to update supergraph with the following error: ' +
94
+ ((_b = e.message) !== null && _b !== void 0 ? _b : e));
95
+ }
96
+ }
97
+ exports.UplinkFetcher = UplinkFetcher;
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/index.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I,qBAAqB,EAAE;wBACzB,MAAA,IAAI,CAAC,MAAM,+CAAX,IAAI,EAAU,qBAAqB,CAAC,CAAC;qBACtC;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;iBAC1B;gBACD,cAAc,CAAC,OAAO,EAAE,CAAC;aAC1B;YAED,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC;IAEO,gBAAgB,CAAC,CAAM;;QAC7B,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,KAAK,CACvB,sEAAsE;YACpE,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC,CACnB,CAAC;IACJ,CAAC;CACF;AA1GD,sCA0GC"}
@@ -0,0 +1,25 @@
1
+ import { fetch } from 'apollo-server-env';
2
+ import { SupergraphSdlUpdate } from '../../config';
3
+ export declare const SUPERGRAPH_SDL_QUERY = "#graphql\n query SupergraphSdl($apiKey: String!, $ref: String!, $ifAfterId: ID) {\n routerConfig(ref: $ref, apiKey: $apiKey, ifAfterId: $ifAfterId) {\n __typename\n ... on RouterConfigResult {\n id\n supergraphSdl: supergraphSDL\n }\n ... on FetchError {\n code\n message\n }\n }\n }\n";
4
+ export declare class UplinkFetcherError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare function loadSupergraphSdlFromUplinks({ graphRef, apiKey, endpoints, errorReportingEndpoint, fetcher, compositionId, maxRetries, roundRobinSeed, }: {
8
+ graphRef: string;
9
+ apiKey: string;
10
+ endpoints: string[];
11
+ errorReportingEndpoint: string | undefined;
12
+ fetcher: typeof fetch;
13
+ compositionId: string | null;
14
+ maxRetries: number;
15
+ roundRobinSeed: number;
16
+ }): Promise<SupergraphSdlUpdate | null>;
17
+ export declare function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorReportingEndpoint, fetcher, compositionId, }: {
18
+ graphRef: string;
19
+ apiKey: string;
20
+ endpoint: string;
21
+ errorReportingEndpoint?: string;
22
+ fetcher: typeof fetch;
23
+ compositionId: string | null;
24
+ }): Promise<SupergraphSdlUpdate | null>;
25
+ //# sourceMappingURL=loadSupergraphSdlFromStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadSupergraphSdlFromStorage.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,mBAAmB,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKnD,eAAO,MAAM,oBAAoB,+VAchC,CAAC;AAoBF,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAsB,4BAA4B,CAAC,EACjD,QAAQ,EACR,MAAM,EACN,SAAS,EACT,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,UAAU,EACV,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,OAAO,EAAE,OAAO,KAAK,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB,GAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAmBvC;AAED,wBAAsB,4BAA4B,CAAC,EACjD,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,sBAAsB,EACtB,OAAO,EACP,aAAa,GACd,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,OAAO,KAAK,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,GAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAwFvC"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadSupergraphSdlFromStorage = exports.SUPERGRAPH_SDL_QUERY = void 0;
6
+ exports.loadSupergraphSdlFromStorage = exports.loadSupergraphSdlFromUplinks = exports.UplinkFetcherError = exports.SUPERGRAPH_SDL_QUERY = void 0;
4
7
  const apollo_server_env_1 = require("apollo-server-env");
8
+ const async_retry_1 = __importDefault(require("async-retry"));
5
9
  const outOfBandReporter_1 = require("./outOfBandReporter");
6
10
  exports.SUPERGRAPH_SDL_QUERY = `#graphql
7
11
  query SupergraphSdl($apiKey: String!, $ref: String!, $ifAfterId: ID) {
@@ -18,9 +22,29 @@ exports.SUPERGRAPH_SDL_QUERY = `#graphql
18
22
  }
19
23
  }
20
24
  `;
21
- const { name, version } = require('../package.json');
25
+ const { name, version } = require('../../../package.json');
22
26
  const fetchErrorMsg = "An error occurred while fetching your schema from Apollo: ";
23
- async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, fetcher, compositionId, }) {
27
+ class UplinkFetcherError extends Error {
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = 'UplinkFetcherError';
31
+ }
32
+ }
33
+ exports.UplinkFetcherError = UplinkFetcherError;
34
+ async function loadSupergraphSdlFromUplinks({ graphRef, apiKey, endpoints, errorReportingEndpoint, fetcher, compositionId, maxRetries, roundRobinSeed, }) {
35
+ return (0, async_retry_1.default)(() => loadSupergraphSdlFromStorage({
36
+ graphRef,
37
+ apiKey,
38
+ endpoint: endpoints[roundRobinSeed++ % endpoints.length],
39
+ errorReportingEndpoint,
40
+ fetcher,
41
+ compositionId,
42
+ }), {
43
+ retries: maxRetries,
44
+ });
45
+ }
46
+ exports.loadSupergraphSdlFromUplinks = loadSupergraphSdlFromUplinks;
47
+ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorReportingEndpoint, fetcher, compositionId, }) {
24
48
  var _a, _b;
25
49
  let result;
26
50
  const requestDetails = {
@@ -41,21 +65,21 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, fetche
41
65
  },
42
66
  };
43
67
  const request = new apollo_server_env_1.Request(endpoint, requestDetails);
44
- const OOBReport = new outOfBandReporter_1.OutOfBandReporter();
45
68
  const startTime = new Date();
46
69
  try {
47
70
  result = await fetcher(endpoint, requestDetails);
48
71
  }
49
72
  catch (e) {
50
73
  const endTime = new Date();
51
- await OOBReport.submitOutOfBandReportIfConfigured({
74
+ await (0, outOfBandReporter_1.submitOutOfBandReportIfConfigured)({
52
75
  error: e,
53
76
  request,
77
+ endpoint: errorReportingEndpoint,
54
78
  startedAt: startTime,
55
79
  endedAt: endTime,
56
- fetcher
80
+ fetcher,
57
81
  });
58
- throw new Error(fetchErrorMsg + ((_a = e.message) !== null && _a !== void 0 ? _a : e));
82
+ throw new UplinkFetcherError(fetchErrorMsg + ((_a = e.message) !== null && _a !== void 0 ? _a : e));
59
83
  }
60
84
  const endTime = new Date();
61
85
  let response;
@@ -64,22 +88,23 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, fetche
64
88
  response = await result.json();
65
89
  }
66
90
  catch (e) {
67
- throw new Error((_b = fetchErrorMsg + result.status + ' ' + e.message) !== null && _b !== void 0 ? _b : e);
91
+ throw new UplinkFetcherError((_b = fetchErrorMsg + result.status + ' ' + e.message) !== null && _b !== void 0 ? _b : e);
68
92
  }
69
93
  if ('errors' in response) {
70
- throw new Error([fetchErrorMsg, ...response.errors.map((error) => error.message)].join('\n'));
94
+ throw new UplinkFetcherError([fetchErrorMsg, ...response.errors.map((error) => error.message)].join('\n'));
71
95
  }
72
96
  }
73
97
  else {
74
- await OOBReport.submitOutOfBandReportIfConfigured({
75
- error: new Error(fetchErrorMsg + result.status + ' ' + result.statusText),
98
+ await (0, outOfBandReporter_1.submitOutOfBandReportIfConfigured)({
99
+ error: new UplinkFetcherError(fetchErrorMsg + result.status + ' ' + result.statusText),
76
100
  request,
101
+ endpoint: errorReportingEndpoint,
77
102
  response: result,
78
103
  startedAt: startTime,
79
104
  endedAt: endTime,
80
- fetcher
105
+ fetcher,
81
106
  });
82
- throw new Error(fetchErrorMsg + result.status + ' ' + result.statusText);
107
+ throw new UplinkFetcherError(fetchErrorMsg + result.status + ' ' + result.statusText);
83
108
  }
84
109
  const { routerConfig } = response.data;
85
110
  if (routerConfig.__typename === 'RouterConfigResult') {
@@ -88,13 +113,13 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, fetche
88
113
  }
89
114
  else if (routerConfig.__typename === 'FetchError') {
90
115
  const { code, message } = routerConfig;
91
- throw new Error(`${code}: ${message}`);
116
+ throw new UplinkFetcherError(`${code}: ${message}`);
92
117
  }
93
118
  else if (routerConfig.__typename === 'Unchanged') {
94
119
  return null;
95
120
  }
96
121
  else {
97
- throw new Error('Programming error: unhandled response failure');
122
+ throw new UplinkFetcherError('Programming error: unhandled response failure');
98
123
  }
99
124
  }
100
125
  exports.loadSupergraphSdlFromStorage = loadSupergraphSdlFromStorage;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadSupergraphSdlFromStorage.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts"],"names":[],"mappings":";;;;;;AAAA,yDAA6D;AAE7D,8DAAgC;AAEhC,2DAAwE;AAI3D,QAAA,oBAAoB,GAAgB;;;;;;;;;;;;;;CAchD,CAAC;AAgBF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAE3D,MAAM,aAAa,GAAG,4DAA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YAChC,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,OAAO;YAChB,OAAO;SACR,CAAC,CAAC;QACH,MAAM,IAAI,kBAAkB,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;KACvF;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC;IACvC,IAAI,YAAY,CAAC,UAAU,KAAK,oBAAoB,EAAE;QACpD,MAAM,EACJ,EAAE,EACF,aAAa,GAEd,GAAG,YAAY,CAAC;QACjB,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,aAAc,EAAE,CAAC;KAC9C;SAAM,IAAI,YAAY,CAAC,UAAU,KAAK,YAAY,EAAE;QAEnD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;QACvC,MAAM,IAAI,kBAAkB,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;KACrD;SAAM,IAAI,YAAY,CAAC,UAAU,KAAK,WAAW,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;SAAM;QACL,MAAM,IAAI,kBAAkB,CAAC,+CAA+C,CAAC,CAAC;KAC/E;AACH,CAAC;AAtGD,oEAsGC"}
@@ -0,0 +1,13 @@
1
+ import { fetch, Response, Request } from 'apollo-server-env';
2
+ export declare const OUT_OF_BAND_REPORTER_QUERY = "#graphql\n mutation OOBReport($input: APIMonitoringReport) {\n reportError(report: $input)\n }\n";
3
+ export declare function submitOutOfBandReportIfConfigured({ error, request, endpoint, response, startedAt, endedAt, tags, fetcher, }: {
4
+ error: Error;
5
+ request: Request;
6
+ endpoint: string | undefined;
7
+ response?: Response;
8
+ startedAt: Date;
9
+ endedAt: Date;
10
+ tags?: string[];
11
+ fetcher: typeof fetch;
12
+ }): Promise<void>;
13
+ //# sourceMappingURL=outOfBandReporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outOfBandReporter.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAS7D,eAAO,MAAM,0BAA0B,0GAItC,CAAC;AAiBF,wBAAsB,iCAAiC,CAAC,EACtD,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,OAAO,KAAK,CAAC;CACvB,iBA6EA"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.submitOutOfBandReportIfConfigured = exports.OUT_OF_BAND_REPORTER_QUERY = void 0;
4
+ const graphqlTypes_1 = require("../../__generated__/graphqlTypes");
5
+ exports.OUT_OF_BAND_REPORTER_QUERY = `#graphql
6
+ mutation OOBReport($input: APIMonitoringReport) {
7
+ reportError(report: $input)
8
+ }
9
+ `;
10
+ const { name, version } = require('../../../package.json');
11
+ async function submitOutOfBandReportIfConfigured({ error, request, endpoint, response, startedAt, endedAt, tags, fetcher, }) {
12
+ var _a, _b;
13
+ if (!endpoint) {
14
+ return;
15
+ }
16
+ let errorCode;
17
+ if (!response) {
18
+ errorCode = graphqlTypes_1.ErrorCode.ConnectionFailed;
19
+ }
20
+ else {
21
+ switch (response.status) {
22
+ case 400:
23
+ case 413:
24
+ case 422:
25
+ errorCode = graphqlTypes_1.ErrorCode.InvalidBody;
26
+ break;
27
+ case 408:
28
+ case 504:
29
+ errorCode = graphqlTypes_1.ErrorCode.Timeout;
30
+ break;
31
+ case 502:
32
+ case 503:
33
+ errorCode = graphqlTypes_1.ErrorCode.ConnectionFailed;
34
+ break;
35
+ default:
36
+ errorCode = graphqlTypes_1.ErrorCode.Other;
37
+ }
38
+ }
39
+ const responseBody = await (response === null || response === void 0 ? void 0 : response.text());
40
+ const variables = {
41
+ input: {
42
+ error: {
43
+ code: errorCode,
44
+ message: error.message,
45
+ },
46
+ request: {
47
+ url: request.url,
48
+ body: await request.text(),
49
+ },
50
+ response: response
51
+ ? {
52
+ httpStatusCode: response.status,
53
+ body: responseBody,
54
+ }
55
+ : null,
56
+ startedAt: startedAt.toISOString(),
57
+ endedAt: endedAt.toISOString(),
58
+ tags: tags,
59
+ },
60
+ };
61
+ try {
62
+ const oobResponse = await fetcher(endpoint, {
63
+ method: 'POST',
64
+ body: JSON.stringify({
65
+ query: exports.OUT_OF_BAND_REPORTER_QUERY,
66
+ variables,
67
+ }),
68
+ headers: {
69
+ 'apollographql-client-name': name,
70
+ 'apollographql-client-version': version,
71
+ 'user-agent': `${name}/${version}`,
72
+ 'content-type': 'application/json',
73
+ },
74
+ });
75
+ const parsedResponse = await oobResponse.json();
76
+ if (!((_a = parsedResponse === null || parsedResponse === void 0 ? void 0 : parsedResponse.data) === null || _a === void 0 ? void 0 : _a.reportError)) {
77
+ throw new Error(`Out-of-band error reporting failed: ${oobResponse.status} ${oobResponse.statusText}`);
78
+ }
79
+ }
80
+ catch (e) {
81
+ throw new Error(`Out-of-band error reporting failed: ${(_b = e.message) !== null && _b !== void 0 ? _b : e}`);
82
+ }
83
+ }
84
+ exports.submitOutOfBandReportIfConfigured = submitOutOfBandReportIfConfigured;
85
+ //# sourceMappingURL=outOfBandReporter.js.map