@apollo/gateway 2.0.0-alpha.0 → 2.0.0-alpha.4

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 (154) hide show
  1. package/README.md +1 -1
  2. package/dist/__generated__/graphqlTypes.d.ts +13 -11
  3. package/dist/__generated__/graphqlTypes.d.ts.map +1 -1
  4. package/dist/__generated__/graphqlTypes.js.map +1 -1
  5. package/dist/config.d.ts +45 -24
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +30 -31
  8. package/dist/config.js.map +1 -1
  9. package/dist/datasources/LocalGraphQLDataSource.js.map +1 -1
  10. package/dist/datasources/RemoteGraphQLDataSource.d.ts.map +1 -1
  11. package/dist/datasources/RemoteGraphQLDataSource.js +4 -1
  12. package/dist/datasources/RemoteGraphQLDataSource.js.map +1 -1
  13. package/dist/datasources/types.d.ts +1 -1
  14. package/dist/datasources/types.d.ts.map +1 -1
  15. package/dist/executeQueryPlan.d.ts.map +1 -1
  16. package/dist/executeQueryPlan.js +6 -6
  17. package/dist/executeQueryPlan.js.map +1 -1
  18. package/dist/index.d.ts +36 -23
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +197 -297
  21. package/dist/index.js.map +1 -1
  22. package/dist/operationContext.js +0 -1
  23. package/dist/operationContext.js.map +1 -1
  24. package/dist/schema-helper/addResolversToSchema.d.ts +4 -0
  25. package/dist/schema-helper/addResolversToSchema.d.ts.map +1 -0
  26. package/dist/schema-helper/addResolversToSchema.js +62 -0
  27. package/dist/schema-helper/addResolversToSchema.js.map +1 -0
  28. package/dist/schema-helper/error.d.ts +6 -0
  29. package/dist/schema-helper/error.d.ts.map +1 -0
  30. package/dist/schema-helper/error.js +14 -0
  31. package/dist/schema-helper/error.js.map +1 -0
  32. package/dist/schema-helper/index.d.ts +4 -0
  33. package/dist/schema-helper/index.d.ts.map +1 -0
  34. package/dist/schema-helper/index.js +16 -0
  35. package/dist/schema-helper/index.js.map +1 -0
  36. package/dist/schema-helper/resolverMap.d.ts +16 -0
  37. package/dist/schema-helper/resolverMap.d.ts.map +1 -0
  38. package/dist/schema-helper/resolverMap.js +3 -0
  39. package/dist/schema-helper/resolverMap.js.map +1 -0
  40. package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts +31 -0
  41. package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts.map +1 -0
  42. package/dist/supergraphManagers/IntrospectAndCompose/index.js +112 -0
  43. package/dist/supergraphManagers/IntrospectAndCompose/index.js.map +1 -0
  44. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts +12 -0
  45. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts.map +1 -0
  46. package/dist/{loadServicesFromRemoteEndpoint.js → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js} +6 -6
  47. package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js.map +1 -0
  48. package/dist/supergraphManagers/LegacyFetcher/index.d.ts +33 -0
  49. package/dist/supergraphManagers/LegacyFetcher/index.d.ts.map +1 -0
  50. package/dist/supergraphManagers/LegacyFetcher/index.js +149 -0
  51. package/dist/supergraphManagers/LegacyFetcher/index.js.map +1 -0
  52. package/dist/supergraphManagers/LocalCompose/index.d.ts +19 -0
  53. package/dist/supergraphManagers/LocalCompose/index.d.ts.map +1 -0
  54. package/dist/supergraphManagers/LocalCompose/index.js +55 -0
  55. package/dist/supergraphManagers/LocalCompose/index.js.map +1 -0
  56. package/dist/supergraphManagers/UplinkFetcher/index.d.ts +32 -0
  57. package/dist/supergraphManagers/UplinkFetcher/index.d.ts.map +1 -0
  58. package/dist/supergraphManagers/UplinkFetcher/index.js +96 -0
  59. package/dist/supergraphManagers/UplinkFetcher/index.js.map +1 -0
  60. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts +21 -0
  61. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts.map +1 -0
  62. package/dist/{loadSupergraphSdlFromStorage.js → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js} +41 -10
  63. package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js.map +1 -0
  64. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts +13 -0
  65. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts.map +1 -0
  66. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js +85 -0
  67. package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js.map +1 -0
  68. package/dist/supergraphManagers/index.d.ts +5 -0
  69. package/dist/supergraphManagers/index.d.ts.map +1 -0
  70. package/dist/supergraphManagers/index.js +12 -0
  71. package/dist/supergraphManagers/index.js.map +1 -0
  72. package/dist/utilities/array.js +1 -1
  73. package/dist/utilities/array.js.map +1 -1
  74. package/dist/utilities/createHash.d.ts +2 -0
  75. package/dist/utilities/createHash.d.ts.map +1 -0
  76. package/dist/utilities/createHash.js +15 -0
  77. package/dist/utilities/createHash.js.map +1 -0
  78. package/dist/utilities/isNodeLike.d.ts +3 -0
  79. package/dist/utilities/isNodeLike.d.ts.map +1 -0
  80. package/dist/utilities/isNodeLike.js +8 -0
  81. package/dist/utilities/isNodeLike.js.map +1 -0
  82. package/package.json +9 -9
  83. package/src/__generated__/graphqlTypes.ts +13 -11
  84. package/src/__mocks__/make-fetch-happen-fetcher.ts +3 -1
  85. package/src/__tests__/buildQueryPlan.test.ts +1 -1
  86. package/src/__tests__/executeQueryPlan.test.ts +1171 -77
  87. package/src/__tests__/execution-utils.ts +5 -7
  88. package/src/__tests__/gateway/buildService.test.ts +3 -3
  89. package/src/__tests__/gateway/endToEnd.test.ts +1 -1
  90. package/src/__tests__/gateway/executor.test.ts +3 -1
  91. package/src/__tests__/gateway/lifecycle-hooks.test.ts +59 -121
  92. package/src/__tests__/gateway/opentelemetry.test.ts +8 -3
  93. package/src/__tests__/gateway/queryPlanCache.test.ts +25 -9
  94. package/src/__tests__/gateway/reporting.test.ts +42 -13
  95. package/src/__tests__/gateway/supergraphSdl.test.ts +397 -0
  96. package/src/__tests__/integration/aliases.test.ts +9 -3
  97. package/src/__tests__/integration/configuration.test.ts +140 -21
  98. package/src/__tests__/integration/logger.test.ts +2 -2
  99. package/src/__tests__/integration/networkRequests.test.ts +126 -149
  100. package/src/__tests__/integration/nockMocks.ts +57 -16
  101. package/src/__tests__/nockAssertions.ts +20 -0
  102. package/src/config.ts +153 -77
  103. package/src/core/__tests__/core.test.ts +6 -6
  104. package/src/datasources/LocalGraphQLDataSource.ts +1 -1
  105. package/src/datasources/RemoteGraphQLDataSource.ts +8 -2
  106. package/src/datasources/__tests__/LocalGraphQLDataSource.test.ts +1 -1
  107. package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +4 -4
  108. package/src/datasources/types.ts +1 -1
  109. package/src/executeQueryPlan.ts +18 -9
  110. package/src/index.ts +323 -481
  111. package/src/make-fetch-happen.d.ts +1 -1
  112. package/src/operationContext.ts +2 -2
  113. package/src/schema-helper/addResolversToSchema.ts +83 -0
  114. package/src/schema-helper/error.ts +11 -0
  115. package/src/schema-helper/index.ts +3 -0
  116. package/src/schema-helper/resolverMap.ts +23 -0
  117. package/src/supergraphManagers/IntrospectAndCompose/__tests__/IntrospectAndCompose.test.ts +370 -0
  118. package/src/{__tests__ → supergraphManagers/IntrospectAndCompose/__tests__}/loadServicesFromRemoteEndpoint.test.ts +7 -7
  119. package/src/supergraphManagers/IntrospectAndCompose/__tests__/tsconfig.json +8 -0
  120. package/src/supergraphManagers/IntrospectAndCompose/index.ts +160 -0
  121. package/src/{loadServicesFromRemoteEndpoint.ts → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts} +7 -7
  122. package/src/supergraphManagers/LegacyFetcher/index.ts +226 -0
  123. package/src/supergraphManagers/LocalCompose/index.ts +79 -0
  124. package/src/supergraphManagers/UplinkFetcher/__tests__/loadSupergraphSdlFromStorage.test.ts +343 -0
  125. package/src/supergraphManagers/UplinkFetcher/__tests__/tsconfig.json +8 -0
  126. package/src/supergraphManagers/UplinkFetcher/index.ts +128 -0
  127. package/src/{loadSupergraphSdlFromStorage.ts → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts} +63 -14
  128. package/src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts +126 -0
  129. package/src/supergraphManagers/index.ts +4 -0
  130. package/src/utilities/__tests__/cleanErrorOfInaccessibleElements.test.ts +13 -10
  131. package/src/utilities/array.ts +1 -1
  132. package/src/utilities/createHash.ts +10 -0
  133. package/src/utilities/isNodeLike.ts +11 -0
  134. package/CHANGELOG.md +0 -452
  135. package/dist/legacyLoadServicesFromStorage.d.ts +0 -20
  136. package/dist/legacyLoadServicesFromStorage.d.ts.map +0 -1
  137. package/dist/legacyLoadServicesFromStorage.js +0 -62
  138. package/dist/legacyLoadServicesFromStorage.js.map +0 -1
  139. package/dist/loadServicesFromRemoteEndpoint.d.ts +0 -13
  140. package/dist/loadServicesFromRemoteEndpoint.d.ts.map +0 -1
  141. package/dist/loadServicesFromRemoteEndpoint.js.map +0 -1
  142. package/dist/loadSupergraphSdlFromStorage.d.ts +0 -12
  143. package/dist/loadSupergraphSdlFromStorage.d.ts.map +0 -1
  144. package/dist/loadSupergraphSdlFromStorage.js.map +0 -1
  145. package/dist/outOfBandReporter.d.ts +0 -15
  146. package/dist/outOfBandReporter.d.ts.map +0 -1
  147. package/dist/outOfBandReporter.js +0 -88
  148. package/dist/outOfBandReporter.js.map +0 -1
  149. package/src/__tests__/gateway/composedSdl.test.ts +0 -44
  150. package/src/__tests__/integration/legacyNetworkRequests.test.ts +0 -279
  151. package/src/__tests__/integration/legacyNockMocks.ts +0 -113
  152. package/src/__tests__/loadSupergraphSdlFromStorage.test.ts +0 -664
  153. package/src/legacyLoadServicesFromStorage.ts +0 -170
  154. package/src/outOfBandReporter.ts +0 -128
@@ -1,664 +0,0 @@
1
- import { loadSupergraphSdlFromStorage } from '../loadSupergraphSdlFromStorage';
2
- import { getDefaultFetcher } from '../..';
3
- import {
4
- graphRef,
5
- apiKey,
6
- mockCloudConfigUrl,
7
- mockSupergraphSdlRequest,
8
- mockOutOfBandReporterUrl,
9
- mockOutOfBandReportRequestSuccess,
10
- mockSupergraphSdlRequestSuccess,
11
- } from './integration/nockMocks';
12
- import mockedEnv from 'mocked-env';
13
-
14
- describe('loadSupergraphSdlFromStorage', () => {
15
- let cleanUp: (() => void) | null = null;
16
-
17
- afterAll(async () => {
18
- if (cleanUp) {
19
- cleanUp();
20
- cleanUp = null;
21
- }
22
- });
23
-
24
- it('fetches Supergraph SDL as expected', async () => {
25
- mockSupergraphSdlRequestSuccess();
26
-
27
- const fetcher = getDefaultFetcher();
28
- const result = await loadSupergraphSdlFromStorage({
29
- graphRef,
30
- apiKey,
31
- endpoint: mockCloudConfigUrl,
32
- fetcher,
33
- });
34
-
35
- expect(result).toMatchInlineSnapshot(`
36
- Object {
37
- "id": "originalId-1234",
38
- "supergraphSdl": "schema
39
- @core(feature: \\"https://specs.apollo.dev/core/v0.2\\")
40
- @core(feature: \\"https://specs.apollo.dev/join/v0.2\\", for: EXECUTION)
41
- @core(feature: \\"https://specs.apollo.dev/tag/v0.1\\")
42
- {
43
- query: Query
44
- mutation: Mutation
45
- }
46
-
47
- directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
48
-
49
- directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
50
-
51
- directive @join__graph(name: String!, url: String!) on ENUM_VALUE
52
-
53
- directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
54
-
55
- directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
56
-
57
- directive @stream on FIELD
58
-
59
- directive @tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION
60
-
61
- directive @transform(from: String!) on FIELD
62
-
63
- union AccountType
64
- @join__type(graph: ACCOUNTS)
65
- @tag(name: \\"from-accounts\\")
66
- = PasswordAccount | SMSAccount
67
-
68
- type Amazon
69
- @join__type(graph: PRODUCT)
70
- {
71
- referrer: String
72
- }
73
-
74
- union Body
75
- @join__type(graph: DOCUMENTS)
76
- = Image | Text
77
-
78
- type Book implements Product
79
- @join__implements(graph: INVENTORY, interface: \\"Product\\")
80
- @join__implements(graph: PRODUCT, interface: \\"Product\\")
81
- @join__implements(graph: REVIEWS, interface: \\"Product\\")
82
- @join__type(graph: BOOKS, key: \\"isbn\\")
83
- @join__type(graph: INVENTORY, key: \\"isbn\\", extension: true)
84
- @join__type(graph: PRODUCT, key: \\"isbn\\", extension: true)
85
- @join__type(graph: REVIEWS, key: \\"isbn\\", extension: true)
86
- {
87
- isbn: String!
88
- title: String @join__field(graph: BOOKS) @join__field(graph: PRODUCT, external: true)
89
- year: Int @join__field(graph: BOOKS) @join__field(graph: PRODUCT, external: true)
90
- similarBooks: [Book]! @join__field(graph: BOOKS) @join__field(graph: REVIEWS, external: true)
91
- metadata: [MetadataOrError] @join__field(graph: BOOKS)
92
- inStock: Boolean @join__field(graph: INVENTORY)
93
- isCheckedOut: Boolean @join__field(graph: INVENTORY)
94
- upc: String! @join__field(graph: PRODUCT)
95
- sku: String! @join__field(graph: PRODUCT)
96
- name(delimeter: String = \\" \\"): String @join__field(graph: PRODUCT, requires: \\"title year\\")
97
- price: String @join__field(graph: PRODUCT)
98
- details: ProductDetailsBook @join__field(graph: PRODUCT)
99
- reviews: [Review] @join__field(graph: REVIEWS)
100
- relatedReviews: [Review!]! @join__field(graph: REVIEWS, requires: \\"similarBooks { isbn }\\")
101
- }
102
-
103
- union Brand
104
- @join__type(graph: PRODUCT)
105
- = Ikea | Amazon
106
-
107
- enum CacheControlScope
108
- @join__type(graph: ACCOUNTS)
109
- @join__type(graph: BOOKS)
110
- @join__type(graph: PRODUCT)
111
- {
112
- PUBLIC
113
- PRIVATE
114
- }
115
-
116
- type Car implements Vehicle
117
- @join__implements(graph: PRODUCT, interface: \\"Vehicle\\")
118
- @join__implements(graph: REVIEWS, interface: \\"Vehicle\\")
119
- @join__type(graph: PRODUCT, key: \\"id\\")
120
- @join__type(graph: REVIEWS, key: \\"id\\", extension: true)
121
- {
122
- id: String!
123
- description: String @join__field(graph: PRODUCT)
124
- price: String @join__field(graph: PRODUCT) @join__field(graph: REVIEWS, external: true)
125
- retailPrice: String @join__field(graph: REVIEWS, requires: \\"price\\")
126
- }
127
-
128
- enum core__Purpose {
129
- \\"\\"\\"
130
- \`SECURITY\` features provide metadata necessary to securely resolve fields.
131
- \\"\\"\\"
132
- SECURITY
133
-
134
- \\"\\"\\"
135
- \`EXECUTION\` features provide metadata necessary for operation execution.
136
- \\"\\"\\"
137
- EXECUTION
138
- }
139
-
140
- type Error
141
- @join__type(graph: BOOKS)
142
- @join__type(graph: PRODUCT)
143
- @join__type(graph: REVIEWS)
144
- {
145
- code: Int
146
- message: String
147
- }
148
-
149
- type Furniture implements Product
150
- @join__implements(graph: INVENTORY, interface: \\"Product\\")
151
- @join__implements(graph: PRODUCT, interface: \\"Product\\")
152
- @join__implements(graph: REVIEWS, interface: \\"Product\\")
153
- @join__type(graph: INVENTORY, key: \\"sku\\", extension: true)
154
- @join__type(graph: PRODUCT, key: \\"upc\\")
155
- @join__type(graph: PRODUCT, key: \\"sku\\")
156
- @join__type(graph: REVIEWS, key: \\"upc\\", extension: true)
157
- {
158
- sku: String! @join__field(graph: INVENTORY) @join__field(graph: PRODUCT)
159
- inStock: Boolean @join__field(graph: INVENTORY)
160
- isHeavy: Boolean @join__field(graph: INVENTORY)
161
- upc: String! @join__field(graph: PRODUCT) @join__field(graph: REVIEWS)
162
- name: String @join__field(graph: PRODUCT)
163
- price: String @join__field(graph: PRODUCT)
164
- brand: Brand @join__field(graph: PRODUCT)
165
- metadata: [MetadataOrError] @join__field(graph: PRODUCT)
166
- details: ProductDetailsFurniture @join__field(graph: PRODUCT)
167
- reviews: [Review] @join__field(graph: REVIEWS)
168
- }
169
-
170
- type Ikea
171
- @join__type(graph: PRODUCT)
172
- {
173
- asile: Int
174
- }
175
-
176
- type Image implements NamedObject
177
- @join__implements(graph: DOCUMENTS, interface: \\"NamedObject\\")
178
- @join__type(graph: DOCUMENTS)
179
- {
180
- name: String!
181
- attributes: ImageAttributes!
182
- }
183
-
184
- type ImageAttributes
185
- @join__type(graph: DOCUMENTS)
186
- {
187
- url: String!
188
- }
189
-
190
- scalar join__FieldSet
191
-
192
- enum join__Graph {
193
- ACCOUNTS @join__graph(name: \\"accounts\\", url: \\"https://accounts.api.com\\")
194
- BOOKS @join__graph(name: \\"books\\", url: \\"https://books.api.com\\")
195
- DOCUMENTS @join__graph(name: \\"documents\\", url: \\"https://documents.api.com\\")
196
- INVENTORY @join__graph(name: \\"inventory\\", url: \\"https://inventory.api.com\\")
197
- PRODUCT @join__graph(name: \\"product\\", url: \\"https://product.api.com\\")
198
- REVIEWS @join__graph(name: \\"reviews\\", url: \\"https://reviews.api.com\\")
199
- }
200
-
201
- scalar JSON
202
- @join__type(graph: ACCOUNTS)
203
- @specifiedBy(url: \\"https://json-spec.dev\\")
204
-
205
- type KeyValue
206
- @join__type(graph: BOOKS)
207
- @join__type(graph: PRODUCT)
208
- @join__type(graph: REVIEWS)
209
- {
210
- key: String!
211
- value: String!
212
- }
213
-
214
- type Library
215
- @join__type(graph: ACCOUNTS, key: \\"id\\", extension: true)
216
- @join__type(graph: BOOKS, key: \\"id\\")
217
- {
218
- id: ID!
219
- name: String @join__field(graph: ACCOUNTS, external: true) @join__field(graph: BOOKS)
220
- userAccount(id: ID! = 1): User @join__field(graph: ACCOUNTS, requires: \\"name\\")
221
- }
222
-
223
- union MetadataOrError
224
- @join__type(graph: BOOKS)
225
- @join__type(graph: PRODUCT)
226
- @join__type(graph: REVIEWS)
227
- = KeyValue | Error
228
-
229
- type Mutation
230
- @join__type(graph: ACCOUNTS)
231
- @join__type(graph: REVIEWS)
232
- {
233
- login(username: String!, password: String!, userId: String @deprecated(reason: \\"Use username instead\\")): User @join__field(graph: ACCOUNTS)
234
- reviewProduct(input: ReviewProduct!): Product @join__field(graph: REVIEWS)
235
- updateReview(review: UpdateReviewInput!): Review @join__field(graph: REVIEWS)
236
- deleteReview(id: ID!): Boolean @join__field(graph: REVIEWS)
237
- }
238
-
239
- type Name
240
- @join__type(graph: ACCOUNTS)
241
- {
242
- first: String
243
- last: String
244
- }
245
-
246
- interface NamedObject
247
- @join__type(graph: DOCUMENTS)
248
- {
249
- name: String!
250
- }
251
-
252
- type PasswordAccount
253
- @join__type(graph: ACCOUNTS, key: \\"email\\")
254
- {
255
- email: String!
256
- }
257
-
258
- interface Product
259
- @join__type(graph: INVENTORY)
260
- @join__type(graph: PRODUCT)
261
- @join__type(graph: REVIEWS)
262
- @tag(name: \\"from-reviews\\")
263
- {
264
- inStock: Boolean @join__field(graph: INVENTORY)
265
- upc: String! @join__field(graph: PRODUCT)
266
- sku: String! @join__field(graph: PRODUCT)
267
- name: String @join__field(graph: PRODUCT)
268
- price: String @join__field(graph: PRODUCT)
269
- details: ProductDetails @join__field(graph: PRODUCT)
270
- reviews: [Review] @join__field(graph: REVIEWS)
271
- }
272
-
273
- interface ProductDetails
274
- @join__type(graph: PRODUCT)
275
- {
276
- country: String
277
- }
278
-
279
- type ProductDetailsBook implements ProductDetails
280
- @join__implements(graph: PRODUCT, interface: \\"ProductDetails\\")
281
- @join__type(graph: PRODUCT)
282
- {
283
- country: String
284
- pages: Int
285
- }
286
-
287
- type ProductDetailsFurniture implements ProductDetails
288
- @join__implements(graph: PRODUCT, interface: \\"ProductDetails\\")
289
- @join__type(graph: PRODUCT)
290
- {
291
- country: String
292
- color: String
293
- }
294
-
295
- type Query
296
- @join__type(graph: ACCOUNTS)
297
- @join__type(graph: BOOKS)
298
- @join__type(graph: DOCUMENTS)
299
- @join__type(graph: INVENTORY)
300
- @join__type(graph: PRODUCT)
301
- @join__type(graph: REVIEWS)
302
- {
303
- user(id: ID!): User @join__field(graph: ACCOUNTS)
304
- me: User @join__field(graph: ACCOUNTS)
305
- book(isbn: String!): Book @join__field(graph: BOOKS)
306
- books: [Book] @join__field(graph: BOOKS)
307
- library(id: ID!): Library @join__field(graph: BOOKS)
308
- body: Body! @join__field(graph: DOCUMENTS)
309
- product(upc: String!): Product @join__field(graph: PRODUCT)
310
- vehicle(id: String!): Vehicle @join__field(graph: PRODUCT)
311
- topProducts(first: Int = 5): [Product] @join__field(graph: PRODUCT)
312
- topCars(first: Int = 5): [Car] @join__field(graph: PRODUCT)
313
- topReviews(first: Int = 5): [Review] @join__field(graph: REVIEWS)
314
- }
315
-
316
- type Review
317
- @join__type(graph: REVIEWS, key: \\"id\\")
318
- {
319
- id: ID!
320
- body(format: Boolean = false): String
321
- author: User @join__field(graph: REVIEWS, provides: \\"username\\")
322
- product: Product
323
- metadata: [MetadataOrError]
324
- }
325
-
326
- input ReviewProduct
327
- @join__type(graph: REVIEWS)
328
- {
329
- upc: String!
330
- body: String!
331
- stars: Int @deprecated(reason: \\"Stars are no longer in use\\")
332
- }
333
-
334
- type SMSAccount
335
- @join__type(graph: ACCOUNTS, key: \\"number\\")
336
- {
337
- number: String
338
- }
339
-
340
- type Text implements NamedObject
341
- @join__implements(graph: DOCUMENTS, interface: \\"NamedObject\\")
342
- @join__type(graph: DOCUMENTS)
343
- {
344
- name: String!
345
- attributes: TextAttributes!
346
- }
347
-
348
- type TextAttributes
349
- @join__type(graph: DOCUMENTS)
350
- {
351
- bold: Boolean
352
- text: String
353
- }
354
-
355
- union Thing
356
- @join__type(graph: PRODUCT)
357
- = Car | Ikea
358
-
359
- input UpdateReviewInput
360
- @join__type(graph: REVIEWS)
361
- {
362
- id: ID!
363
- body: String
364
- }
365
-
366
- type User
367
- @join__type(graph: ACCOUNTS, key: \\"id\\")
368
- @join__type(graph: ACCOUNTS, key: \\"username name { first last }\\")
369
- @join__type(graph: INVENTORY, key: \\"id\\", extension: true)
370
- @join__type(graph: PRODUCT, key: \\"id\\", extension: true)
371
- @join__type(graph: REVIEWS, key: \\"id\\", extension: true)
372
- @tag(name: \\"from-accounts\\")
373
- @tag(name: \\"from-reviews\\")
374
- {
375
- id: ID! @tag(name: \\"accounts\\")
376
- name: Name @join__field(graph: ACCOUNTS)
377
- username: String @join__field(graph: ACCOUNTS) @join__field(graph: REVIEWS, external: true)
378
- birthDate(locale: String): String @tag(name: \\"admin\\") @tag(name: \\"dev\\") @join__field(graph: ACCOUNTS)
379
- account: AccountType @join__field(graph: ACCOUNTS)
380
- metadata: [UserMetadata] @join__field(graph: ACCOUNTS) @join__field(graph: INVENTORY, external: true) @join__field(graph: REVIEWS, external: true)
381
- ssn: String @join__field(graph: ACCOUNTS)
382
- goodDescription: Boolean @join__field(graph: INVENTORY, requires: \\"metadata { description }\\")
383
- vehicle: Vehicle @join__field(graph: PRODUCT)
384
- thing: Thing @join__field(graph: PRODUCT)
385
- reviews: [Review] @join__field(graph: REVIEWS)
386
- numberOfReviews: Int! @join__field(graph: REVIEWS)
387
- goodAddress: Boolean @join__field(graph: REVIEWS, requires: \\"metadata { address }\\")
388
- }
389
-
390
- type UserMetadata
391
- @join__type(graph: ACCOUNTS)
392
- @join__type(graph: INVENTORY)
393
- @join__type(graph: REVIEWS)
394
- {
395
- name: String @join__field(graph: ACCOUNTS)
396
- address: String @join__field(graph: ACCOUNTS) @join__field(graph: REVIEWS, external: true)
397
- description: String @join__field(graph: ACCOUNTS) @join__field(graph: INVENTORY, external: true)
398
- }
399
-
400
- type Van implements Vehicle
401
- @join__implements(graph: PRODUCT, interface: \\"Vehicle\\")
402
- @join__implements(graph: REVIEWS, interface: \\"Vehicle\\")
403
- @join__type(graph: PRODUCT, key: \\"id\\")
404
- @join__type(graph: REVIEWS, key: \\"id\\", extension: true)
405
- {
406
- id: String!
407
- description: String @join__field(graph: PRODUCT)
408
- price: String @join__field(graph: PRODUCT) @join__field(graph: REVIEWS, external: true)
409
- retailPrice: String @join__field(graph: REVIEWS, requires: \\"price\\")
410
- }
411
-
412
- interface Vehicle
413
- @join__type(graph: PRODUCT)
414
- @join__type(graph: REVIEWS)
415
- {
416
- id: String! @join__field(graph: PRODUCT)
417
- description: String @join__field(graph: PRODUCT)
418
- price: String @join__field(graph: PRODUCT)
419
- retailPrice: String @join__field(graph: REVIEWS)
420
- }",
421
- }
422
- `);
423
- });
424
-
425
- describe('errors', () => {
426
- it('throws on a malformed response', async () => {
427
- mockSupergraphSdlRequest().reply(200, 'Invalid JSON');
428
-
429
- const fetcher = getDefaultFetcher();
430
- await expect(
431
- loadSupergraphSdlFromStorage({
432
- graphRef,
433
- apiKey,
434
- endpoint: mockCloudConfigUrl,
435
- fetcher,
436
- }),
437
- ).rejects.toThrowErrorMatchingInlineSnapshot(
438
- `"An error occurred while fetching your schema from Apollo: 200 invalid json response body at https://example.cloud-config-url.com/cloudconfig/ reason: Unexpected token I in JSON at position 0"`,
439
- );
440
- });
441
-
442
- it('throws errors from JSON on 400', async () => {
443
- const message = 'Query syntax error';
444
- mockSupergraphSdlRequest().reply(
445
- 400,
446
- JSON.stringify({
447
- errors: [{ message }],
448
- }),
449
- );
450
-
451
- const fetcher = getDefaultFetcher();
452
- await expect(
453
- loadSupergraphSdlFromStorage({
454
- graphRef,
455
- apiKey,
456
- endpoint: mockCloudConfigUrl,
457
- fetcher,
458
- }),
459
- ).rejects.toThrowError(message);
460
- });
461
-
462
- it("throws on non-OK status codes when `errors` isn't present in a JSON response", async () => {
463
- mockSupergraphSdlRequest().reply(500);
464
-
465
- const fetcher = getDefaultFetcher();
466
- await expect(
467
- loadSupergraphSdlFromStorage({
468
- graphRef,
469
- apiKey,
470
- endpoint: mockCloudConfigUrl,
471
- fetcher,
472
- }),
473
- ).rejects.toThrowErrorMatchingInlineSnapshot(
474
- `"An error occurred while fetching your schema from Apollo: 500 Internal Server Error"`,
475
- );
476
- });
477
-
478
- // if an additional request were made by the out of band reporter, nock would throw since it's unmocked
479
- // and this test would fail
480
- it("Out of band reporting doesn't submit reports when endpoint is not configured", async () => {
481
- mockSupergraphSdlRequest().reply(400);
482
-
483
- const fetcher = getDefaultFetcher();
484
- await expect(
485
- loadSupergraphSdlFromStorage({
486
- graphRef,
487
- apiKey,
488
- endpoint: mockCloudConfigUrl,
489
- fetcher,
490
- }),
491
- ).rejects.toThrowErrorMatchingInlineSnapshot(
492
- `"An error occurred while fetching your schema from Apollo: 400 invalid json response body at https://example.cloud-config-url.com/cloudconfig/ reason: Unexpected end of JSON input"`,
493
- );
494
- });
495
-
496
- it('throws on 400 status response and successfully submits an out of band error', async () => {
497
- cleanUp = mockedEnv({
498
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
499
- });
500
-
501
- mockSupergraphSdlRequest().reply(400);
502
- mockOutOfBandReportRequestSuccess();
503
-
504
- const fetcher = getDefaultFetcher();
505
- await expect(
506
- loadSupergraphSdlFromStorage({
507
- graphRef,
508
- apiKey,
509
- endpoint: mockCloudConfigUrl,
510
- fetcher,
511
- }),
512
- ).rejects.toThrowErrorMatchingInlineSnapshot(
513
- `"An error occurred while fetching your schema from Apollo: 400 invalid json response body at https://example.cloud-config-url.com/cloudconfig/ reason: Unexpected end of JSON input"`,
514
- );
515
- });
516
-
517
- it('throws on 413 status response and successfully submits an out of band error', async () => {
518
- cleanUp = mockedEnv({
519
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
520
- });
521
-
522
- mockSupergraphSdlRequest().reply(413);
523
- mockOutOfBandReportRequestSuccess();
524
-
525
- const fetcher = getDefaultFetcher();
526
- await expect(
527
- loadSupergraphSdlFromStorage({
528
- graphRef,
529
- apiKey,
530
- endpoint: mockCloudConfigUrl,
531
- fetcher,
532
- }),
533
- ).rejects.toThrowErrorMatchingInlineSnapshot(
534
- `"An error occurred while fetching your schema from Apollo: 413 Payload Too Large"`,
535
- );
536
- });
537
-
538
- it('throws on 422 status response and successfully submits an out of band error', async () => {
539
- cleanUp = mockedEnv({
540
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
541
- });
542
-
543
- mockSupergraphSdlRequest().reply(422);
544
- mockOutOfBandReportRequestSuccess();
545
-
546
- const fetcher = getDefaultFetcher();
547
- await expect(
548
- loadSupergraphSdlFromStorage({
549
- graphRef,
550
- apiKey,
551
- endpoint: mockCloudConfigUrl,
552
- fetcher,
553
- }),
554
- ).rejects.toThrowErrorMatchingInlineSnapshot(
555
- `"An error occurred while fetching your schema from Apollo: 422 Unprocessable Entity"`,
556
- );
557
- });
558
-
559
- it('throws on 408 status response and successfully submits an out of band error', async () => {
560
- cleanUp = mockedEnv({
561
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
562
- });
563
-
564
- mockSupergraphSdlRequest().reply(408);
565
- mockOutOfBandReportRequestSuccess();
566
-
567
- const fetcher = getDefaultFetcher();
568
- await expect(
569
- loadSupergraphSdlFromStorage({
570
- graphRef,
571
- apiKey,
572
- endpoint: mockCloudConfigUrl,
573
- fetcher,
574
- }),
575
- ).rejects.toThrowErrorMatchingInlineSnapshot(
576
- `"An error occurred while fetching your schema from Apollo: 408 Request Timeout"`,
577
- );
578
- });
579
- });
580
-
581
- it('throws on 504 status response and successfully submits an out of band error', async () => {
582
- cleanUp = mockedEnv({
583
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
584
- });
585
-
586
- mockSupergraphSdlRequest().reply(504);
587
- mockOutOfBandReportRequestSuccess();
588
-
589
- const fetcher = getDefaultFetcher();
590
- await expect(
591
- loadSupergraphSdlFromStorage({
592
- graphRef,
593
- apiKey,
594
- endpoint: mockCloudConfigUrl,
595
- fetcher,
596
- }),
597
- ).rejects.toThrowErrorMatchingInlineSnapshot(
598
- `"An error occurred while fetching your schema from Apollo: 504 Gateway Timeout"`,
599
- );
600
- });
601
-
602
- it('throws when there is no response and successfully submits an out of band error', async () => {
603
- cleanUp = mockedEnv({
604
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
605
- });
606
-
607
- mockSupergraphSdlRequest().replyWithError('no response');
608
- mockOutOfBandReportRequestSuccess();
609
-
610
- const fetcher = getDefaultFetcher();
611
- await expect(
612
- loadSupergraphSdlFromStorage({
613
- graphRef,
614
- apiKey,
615
- endpoint: mockCloudConfigUrl,
616
- fetcher,
617
- }),
618
- ).rejects.toThrowErrorMatchingInlineSnapshot(
619
- `"An error occurred while fetching your schema from Apollo: request to https://example.cloud-config-url.com/cloudconfig/ failed, reason: no response"`,
620
- );
621
- });
622
-
623
- it('throws on 502 status response and successfully submits an out of band error', async () => {
624
- cleanUp = mockedEnv({
625
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
626
- });
627
-
628
- mockSupergraphSdlRequest().reply(502);
629
- mockOutOfBandReportRequestSuccess();
630
-
631
- const fetcher = getDefaultFetcher();
632
- await expect(
633
- loadSupergraphSdlFromStorage({
634
- graphRef,
635
- apiKey,
636
- endpoint: mockCloudConfigUrl,
637
- fetcher,
638
- }),
639
- ).rejects.toThrowErrorMatchingInlineSnapshot(
640
- `"An error occurred while fetching your schema from Apollo: 502 Bad Gateway"`,
641
- );
642
- });
643
-
644
- it('throws on 503 status response and successfully submits an out of band error', async () => {
645
- cleanUp = mockedEnv({
646
- APOLLO_OUT_OF_BAND_REPORTER_ENDPOINT: mockOutOfBandReporterUrl,
647
- });
648
-
649
- mockSupergraphSdlRequest().reply(503);
650
- mockOutOfBandReportRequestSuccess();
651
-
652
- const fetcher = getDefaultFetcher();
653
- await expect(
654
- loadSupergraphSdlFromStorage({
655
- graphRef,
656
- apiKey,
657
- endpoint: mockCloudConfigUrl,
658
- fetcher,
659
- }),
660
- ).rejects.toThrowErrorMatchingInlineSnapshot(
661
- `"An error occurred while fetching your schema from Apollo: 503 Service Unavailable"`,
662
- );
663
- });
664
- });