@graphql-tools/delegate 8.2.2-alpha-5d885fa3.0 → 8.2.2
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.
- package/package.json +4 -4
- package/es5/README.md +0 -7
- package/es5/Subschema.d.ts +0 -19
- package/es5/Transformer.d.ts +0 -10
- package/es5/applySchemaTransforms.d.ts +0 -3
- package/es5/checkResultAndHandleErrors.d.ts +0 -8
- package/es5/createRequest.d.ts +0 -6
- package/es5/defaultMergedResolver.d.ts +0 -9
- package/es5/delegateToSchema.d.ts +0 -6
- package/es5/finalizeGatewayRequest.d.ts +0 -3
- package/es5/getDocumentMetadata.d.ts +0 -6
- package/es5/index.d.ts +0 -10
- package/es5/index.js +0 -1694
- package/es5/index.mjs +0 -1672
- package/es5/mergeFields.d.ts +0 -8
- package/es5/package.json +0 -39
- package/es5/prepareGatewayDocument.d.ts +0 -2
- package/es5/resolveExternalValue.d.ts +0 -3
- package/es5/subschemaConfig.d.ts +0 -3
- package/es5/symbols.d.ts +0 -3
- package/es5/types.d.ts +0 -149
package/es5/index.js
DELETED
|
@@ -1,1694 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const tslib = require('tslib');
|
|
6
|
-
const graphql = require('graphql');
|
|
7
|
-
const utils = require('@graphql-tools/utils/es5');
|
|
8
|
-
const valueOrPromise = require('value-or-promise');
|
|
9
|
-
const batchExecute = require('@graphql-tools/batch-execute/es5');
|
|
10
|
-
|
|
11
|
-
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
12
|
-
var schemaTransforms = subschemaConfig.transforms;
|
|
13
|
-
if (schemaTransforms == null) {
|
|
14
|
-
return originalWrappingSchema;
|
|
15
|
-
}
|
|
16
|
-
return schemaTransforms.reduce(function (schema, transform) {
|
|
17
|
-
return transform.transformSchema != null
|
|
18
|
-
? transform.transformSchema(schema, subschemaConfig, transformedSchema)
|
|
19
|
-
: schema;
|
|
20
|
-
}, originalWrappingSchema);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isSubschema(value) {
|
|
24
|
-
return Boolean(value.transformedSchema);
|
|
25
|
-
}
|
|
26
|
-
var Subschema = /** @class */ (function () {
|
|
27
|
-
function Subschema(config) {
|
|
28
|
-
var _a;
|
|
29
|
-
this.schema = config.schema;
|
|
30
|
-
this.executor = config.executor;
|
|
31
|
-
this.batch = config.batch;
|
|
32
|
-
this.batchingOptions = config.batchingOptions;
|
|
33
|
-
this.createProxyingResolver = config.createProxyingResolver;
|
|
34
|
-
this.transforms = (_a = config.transforms) !== null && _a !== void 0 ? _a : [];
|
|
35
|
-
this.transformedSchema = applySchemaTransforms(this.schema, config);
|
|
36
|
-
this.merge = config.merge;
|
|
37
|
-
}
|
|
38
|
-
return Subschema;
|
|
39
|
-
}());
|
|
40
|
-
|
|
41
|
-
function getDocumentMetadata(document) {
|
|
42
|
-
var operations = [];
|
|
43
|
-
var fragments = [];
|
|
44
|
-
var fragmentNames = new Set();
|
|
45
|
-
for (var i = 0; i < document.definitions.length; i++) {
|
|
46
|
-
var def = document.definitions[i];
|
|
47
|
-
if (def.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
|
48
|
-
fragments.push(def);
|
|
49
|
-
fragmentNames.add(def.name.value);
|
|
50
|
-
}
|
|
51
|
-
else if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
52
|
-
operations.push(def);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
operations: operations,
|
|
57
|
-
fragments: fragments,
|
|
58
|
-
fragmentNames: fragmentNames,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function prepareGatewayDocument(originalDocument, transformedSchema, returnType, infoSchema) {
|
|
63
|
-
var _a;
|
|
64
|
-
var wrappedConcreteTypesDocument = wrapConcreteTypes(returnType, transformedSchema, originalDocument);
|
|
65
|
-
if (infoSchema == null) {
|
|
66
|
-
return wrappedConcreteTypesDocument;
|
|
67
|
-
}
|
|
68
|
-
var _b = getSchemaMetaData(infoSchema, transformedSchema), possibleTypesMap = _b.possibleTypesMap, reversePossibleTypesMap = _b.reversePossibleTypesMap, interfaceExtensionsMap = _b.interfaceExtensionsMap, fieldNodesByType = _b.fieldNodesByType, fieldNodesByField = _b.fieldNodesByField, dynamicSelectionSetsByField = _b.dynamicSelectionSetsByField;
|
|
69
|
-
var _c = getDocumentMetadata(wrappedConcreteTypesDocument), operations = _c.operations, fragments = _c.fragments, fragmentNames = _c.fragmentNames;
|
|
70
|
-
var _d = getExpandedFragments(fragments, fragmentNames, possibleTypesMap), expandedFragments = _d.expandedFragments, fragmentReplacements = _d.fragmentReplacements;
|
|
71
|
-
var typeInfo = new graphql.TypeInfo(transformedSchema);
|
|
72
|
-
var expandedDocument = {
|
|
73
|
-
kind: graphql.Kind.DOCUMENT,
|
|
74
|
-
definitions: tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(operations), false), tslib.__read(fragments), false), tslib.__read(expandedFragments), false),
|
|
75
|
-
};
|
|
76
|
-
var visitorKeyMap = {
|
|
77
|
-
Document: ['definitions'],
|
|
78
|
-
OperationDefinition: ['selectionSet'],
|
|
79
|
-
SelectionSet: ['selections'],
|
|
80
|
-
Field: ['selectionSet'],
|
|
81
|
-
InlineFragment: ['selectionSet'],
|
|
82
|
-
FragmentDefinition: ['selectionSet'],
|
|
83
|
-
};
|
|
84
|
-
return graphql.visit(expandedDocument, graphql.visitWithTypeInfo(typeInfo, (_a = {},
|
|
85
|
-
_a[graphql.Kind.SELECTION_SET] = function (node) {
|
|
86
|
-
return visitSelectionSet(node, fragmentReplacements, transformedSchema, typeInfo, possibleTypesMap, reversePossibleTypesMap, interfaceExtensionsMap, fieldNodesByType, fieldNodesByField, dynamicSelectionSetsByField);
|
|
87
|
-
},
|
|
88
|
-
_a)),
|
|
89
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
90
|
-
// empty keys cannot be removed only because of typescript errors
|
|
91
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
92
|
-
visitorKeyMap);
|
|
93
|
-
}
|
|
94
|
-
function visitSelectionSet(node, fragmentReplacements, schema, typeInfo, possibleTypesMap, reversePossibleTypesMap, interfaceExtensionsMap, fieldNodesByType, fieldNodesByField, dynamicSelectionSetsByField) {
|
|
95
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f, e_7, _g, e_8, _h;
|
|
96
|
-
var _j, _k;
|
|
97
|
-
var newSelections = new Set();
|
|
98
|
-
var maybeType = typeInfo.getParentType();
|
|
99
|
-
if (maybeType != null) {
|
|
100
|
-
var parentType = graphql.getNamedType(maybeType);
|
|
101
|
-
var parentTypeName = parentType.name;
|
|
102
|
-
var fieldNodes = fieldNodesByType[parentTypeName];
|
|
103
|
-
if (fieldNodes) {
|
|
104
|
-
try {
|
|
105
|
-
for (var fieldNodes_1 = tslib.__values(fieldNodes), fieldNodes_1_1 = fieldNodes_1.next(); !fieldNodes_1_1.done; fieldNodes_1_1 = fieldNodes_1.next()) {
|
|
106
|
-
var fieldNode = fieldNodes_1_1.value;
|
|
107
|
-
newSelections.add(fieldNode);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
111
|
-
finally {
|
|
112
|
-
try {
|
|
113
|
-
if (fieldNodes_1_1 && !fieldNodes_1_1.done && (_a = fieldNodes_1.return)) _a.call(fieldNodes_1);
|
|
114
|
-
}
|
|
115
|
-
finally { if (e_1) throw e_1.error; }
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
var interfaceExtensions = interfaceExtensionsMap[parentType.name];
|
|
119
|
-
var interfaceExtensionFields = [];
|
|
120
|
-
try {
|
|
121
|
-
for (var _l = tslib.__values(node.selections), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
122
|
-
var selection = _m.value;
|
|
123
|
-
if (selection.kind === graphql.Kind.INLINE_FRAGMENT) {
|
|
124
|
-
if (selection.typeCondition != null) {
|
|
125
|
-
var possibleTypes = possibleTypesMap[selection.typeCondition.name.value];
|
|
126
|
-
if (possibleTypes == null) {
|
|
127
|
-
newSelections.add(selection);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
for (var possibleTypes_1 = (e_3 = void 0, tslib.__values(possibleTypes)), possibleTypes_1_1 = possibleTypes_1.next(); !possibleTypes_1_1.done; possibleTypes_1_1 = possibleTypes_1.next()) {
|
|
132
|
-
var possibleTypeName = possibleTypes_1_1.value;
|
|
133
|
-
var maybePossibleType = schema.getType(possibleTypeName);
|
|
134
|
-
if (maybePossibleType != null && utils.implementsAbstractType(schema, parentType, maybePossibleType)) {
|
|
135
|
-
newSelections.add(generateInlineFragment(possibleTypeName, selection.selectionSet));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
140
|
-
finally {
|
|
141
|
-
try {
|
|
142
|
-
if (possibleTypes_1_1 && !possibleTypes_1_1.done && (_c = possibleTypes_1.return)) _c.call(possibleTypes_1);
|
|
143
|
-
}
|
|
144
|
-
finally { if (e_3) throw e_3.error; }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else if (selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
149
|
-
var fragmentName = selection.name.value;
|
|
150
|
-
if (!fragmentReplacements[fragmentName]) {
|
|
151
|
-
newSelections.add(selection);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
for (var _o = (e_4 = void 0, tslib.__values(fragmentReplacements[fragmentName])), _p = _o.next(); !_p.done; _p = _o.next()) {
|
|
156
|
-
var replacement = _p.value;
|
|
157
|
-
var typeName = replacement.typeName;
|
|
158
|
-
var maybeReplacementType = schema.getType(typeName);
|
|
159
|
-
if (maybeReplacementType != null && utils.implementsAbstractType(schema, parentType, maybeType)) {
|
|
160
|
-
newSelections.add({
|
|
161
|
-
kind: graphql.Kind.FRAGMENT_SPREAD,
|
|
162
|
-
name: {
|
|
163
|
-
kind: graphql.Kind.NAME,
|
|
164
|
-
value: replacement.fragmentName,
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
171
|
-
finally {
|
|
172
|
-
try {
|
|
173
|
-
if (_p && !_p.done && (_d = _o.return)) _d.call(_o);
|
|
174
|
-
}
|
|
175
|
-
finally { if (e_4) throw e_4.error; }
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
var fieldName = selection.name.value;
|
|
180
|
-
var fieldNodes_3 = (_j = fieldNodesByField[parentTypeName]) === null || _j === void 0 ? void 0 : _j[fieldName];
|
|
181
|
-
if (fieldNodes_3 != null) {
|
|
182
|
-
try {
|
|
183
|
-
for (var fieldNodes_2 = (e_5 = void 0, tslib.__values(fieldNodes_3)), fieldNodes_2_1 = fieldNodes_2.next(); !fieldNodes_2_1.done; fieldNodes_2_1 = fieldNodes_2.next()) {
|
|
184
|
-
var fieldNode = fieldNodes_2_1.value;
|
|
185
|
-
newSelections.add(fieldNode);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
189
|
-
finally {
|
|
190
|
-
try {
|
|
191
|
-
if (fieldNodes_2_1 && !fieldNodes_2_1.done && (_e = fieldNodes_2.return)) _e.call(fieldNodes_2);
|
|
192
|
-
}
|
|
193
|
-
finally { if (e_5) throw e_5.error; }
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
var dynamicSelectionSets = (_k = dynamicSelectionSetsByField[parentTypeName]) === null || _k === void 0 ? void 0 : _k[fieldName];
|
|
197
|
-
if (dynamicSelectionSets != null) {
|
|
198
|
-
try {
|
|
199
|
-
for (var dynamicSelectionSets_1 = (e_6 = void 0, tslib.__values(dynamicSelectionSets)), dynamicSelectionSets_1_1 = dynamicSelectionSets_1.next(); !dynamicSelectionSets_1_1.done; dynamicSelectionSets_1_1 = dynamicSelectionSets_1.next()) {
|
|
200
|
-
var selectionSetFn = dynamicSelectionSets_1_1.value;
|
|
201
|
-
var selectionSet = selectionSetFn(selection);
|
|
202
|
-
if (selectionSet != null) {
|
|
203
|
-
try {
|
|
204
|
-
for (var _q = (e_7 = void 0, tslib.__values(selectionSet.selections)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
205
|
-
var selection_1 = _r.value;
|
|
206
|
-
newSelections.add(selection_1);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
210
|
-
finally {
|
|
211
|
-
try {
|
|
212
|
-
if (_r && !_r.done && (_g = _q.return)) _g.call(_q);
|
|
213
|
-
}
|
|
214
|
-
finally { if (e_7) throw e_7.error; }
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
220
|
-
finally {
|
|
221
|
-
try {
|
|
222
|
-
if (dynamicSelectionSets_1_1 && !dynamicSelectionSets_1_1.done && (_f = dynamicSelectionSets_1.return)) _f.call(dynamicSelectionSets_1);
|
|
223
|
-
}
|
|
224
|
-
finally { if (e_6) throw e_6.error; }
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (interfaceExtensions === null || interfaceExtensions === void 0 ? void 0 : interfaceExtensions[fieldName]) {
|
|
228
|
-
interfaceExtensionFields.push(selection);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
newSelections.add(selection);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
237
|
-
finally {
|
|
238
|
-
try {
|
|
239
|
-
if (_m && !_m.done && (_b = _l.return)) _b.call(_l);
|
|
240
|
-
}
|
|
241
|
-
finally { if (e_2) throw e_2.error; }
|
|
242
|
-
}
|
|
243
|
-
if (reversePossibleTypesMap[parentType.name]) {
|
|
244
|
-
newSelections.add({
|
|
245
|
-
kind: graphql.Kind.FIELD,
|
|
246
|
-
name: {
|
|
247
|
-
kind: graphql.Kind.NAME,
|
|
248
|
-
value: '__typename',
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
if (interfaceExtensionFields.length) {
|
|
253
|
-
var possibleTypes = possibleTypesMap[parentType.name];
|
|
254
|
-
if (possibleTypes != null) {
|
|
255
|
-
try {
|
|
256
|
-
for (var possibleTypes_2 = tslib.__values(possibleTypes), possibleTypes_2_1 = possibleTypes_2.next(); !possibleTypes_2_1.done; possibleTypes_2_1 = possibleTypes_2.next()) {
|
|
257
|
-
var possibleType = possibleTypes_2_1.value;
|
|
258
|
-
newSelections.add(generateInlineFragment(possibleType, {
|
|
259
|
-
kind: graphql.Kind.SELECTION_SET,
|
|
260
|
-
selections: interfaceExtensionFields,
|
|
261
|
-
}));
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
265
|
-
finally {
|
|
266
|
-
try {
|
|
267
|
-
if (possibleTypes_2_1 && !possibleTypes_2_1.done && (_h = possibleTypes_2.return)) _h.call(possibleTypes_2);
|
|
268
|
-
}
|
|
269
|
-
finally { if (e_8) throw e_8.error; }
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return tslib.__assign(tslib.__assign({}, node), { selections: Array.from(newSelections) });
|
|
274
|
-
}
|
|
275
|
-
return node;
|
|
276
|
-
}
|
|
277
|
-
function generateInlineFragment(typeName, selectionSet) {
|
|
278
|
-
return {
|
|
279
|
-
kind: graphql.Kind.INLINE_FRAGMENT,
|
|
280
|
-
typeCondition: {
|
|
281
|
-
kind: graphql.Kind.NAMED_TYPE,
|
|
282
|
-
name: {
|
|
283
|
-
kind: graphql.Kind.NAME,
|
|
284
|
-
value: typeName,
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
selectionSet: selectionSet,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
var getSchemaMetaData = utils.memoize2(function (sourceSchema, targetSchema) {
|
|
291
|
-
var e_9, _a;
|
|
292
|
-
var _b, _c, _d, _e;
|
|
293
|
-
var typeMap = sourceSchema.getTypeMap();
|
|
294
|
-
var targetTypeMap = targetSchema.getTypeMap();
|
|
295
|
-
var possibleTypesMap = Object.create(null);
|
|
296
|
-
var interfaceExtensionsMap = Object.create(null);
|
|
297
|
-
for (var typeName in typeMap) {
|
|
298
|
-
var type = typeMap[typeName];
|
|
299
|
-
if (graphql.isAbstractType(type)) {
|
|
300
|
-
var targetType = targetTypeMap[typeName];
|
|
301
|
-
if (graphql.isInterfaceType(type) && graphql.isInterfaceType(targetType)) {
|
|
302
|
-
var targetTypeFields = targetType.getFields();
|
|
303
|
-
var sourceTypeFields = type.getFields();
|
|
304
|
-
var extensionFields = Object.create(null);
|
|
305
|
-
var isExtensionFieldsEmpty = true;
|
|
306
|
-
for (var fieldName in sourceTypeFields) {
|
|
307
|
-
if (!targetTypeFields[fieldName]) {
|
|
308
|
-
extensionFields[fieldName] = true;
|
|
309
|
-
isExtensionFieldsEmpty = false;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
if (!isExtensionFieldsEmpty) {
|
|
313
|
-
interfaceExtensionsMap[typeName] = extensionFields;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
if (interfaceExtensionsMap[typeName] || !graphql.isAbstractType(targetType)) {
|
|
317
|
-
var implementations = sourceSchema.getPossibleTypes(type);
|
|
318
|
-
possibleTypesMap[typeName] = [];
|
|
319
|
-
try {
|
|
320
|
-
for (var implementations_1 = (e_9 = void 0, tslib.__values(implementations)), implementations_1_1 = implementations_1.next(); !implementations_1_1.done; implementations_1_1 = implementations_1.next()) {
|
|
321
|
-
var impl = implementations_1_1.value;
|
|
322
|
-
if (targetTypeMap[impl.name]) {
|
|
323
|
-
possibleTypesMap[typeName].push(impl.name);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
328
|
-
finally {
|
|
329
|
-
try {
|
|
330
|
-
if (implementations_1_1 && !implementations_1_1.done && (_a = implementations_1.return)) _a.call(implementations_1);
|
|
331
|
-
}
|
|
332
|
-
finally { if (e_9) throw e_9.error; }
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
var stitchingInfo = (_b = sourceSchema.extensions) === null || _b === void 0 ? void 0 : _b['stitchingInfo'];
|
|
338
|
-
return {
|
|
339
|
-
possibleTypesMap: possibleTypesMap,
|
|
340
|
-
reversePossibleTypesMap: reversePossibleTypesMap(possibleTypesMap),
|
|
341
|
-
interfaceExtensionsMap: interfaceExtensionsMap,
|
|
342
|
-
fieldNodesByType: (_c = stitchingInfo === null || stitchingInfo === void 0 ? void 0 : stitchingInfo.fieldNodesByType) !== null && _c !== void 0 ? _c : {},
|
|
343
|
-
fieldNodesByField: (_d = stitchingInfo === null || stitchingInfo === void 0 ? void 0 : stitchingInfo.fieldNodesByField) !== null && _d !== void 0 ? _d : {},
|
|
344
|
-
dynamicSelectionSetsByField: (_e = stitchingInfo === null || stitchingInfo === void 0 ? void 0 : stitchingInfo.dynamicSelectionSetsByField) !== null && _e !== void 0 ? _e : {},
|
|
345
|
-
};
|
|
346
|
-
});
|
|
347
|
-
function reversePossibleTypesMap(possibleTypesMap) {
|
|
348
|
-
var e_10, _a;
|
|
349
|
-
var result = Object.create(null);
|
|
350
|
-
for (var typeName in possibleTypesMap) {
|
|
351
|
-
var toTypeNames = possibleTypesMap[typeName];
|
|
352
|
-
try {
|
|
353
|
-
for (var toTypeNames_1 = (e_10 = void 0, tslib.__values(toTypeNames)), toTypeNames_1_1 = toTypeNames_1.next(); !toTypeNames_1_1.done; toTypeNames_1_1 = toTypeNames_1.next()) {
|
|
354
|
-
var toTypeName = toTypeNames_1_1.value;
|
|
355
|
-
if (!result[toTypeName]) {
|
|
356
|
-
result[toTypeName] = [];
|
|
357
|
-
}
|
|
358
|
-
result[toTypeName].push(typeName);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
362
|
-
finally {
|
|
363
|
-
try {
|
|
364
|
-
if (toTypeNames_1_1 && !toTypeNames_1_1.done && (_a = toTypeNames_1.return)) _a.call(toTypeNames_1);
|
|
365
|
-
}
|
|
366
|
-
finally { if (e_10) throw e_10.error; }
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return result;
|
|
370
|
-
}
|
|
371
|
-
function getExpandedFragments(fragments, fragmentNames, possibleTypesMap) {
|
|
372
|
-
var e_11, _a, e_12, _b;
|
|
373
|
-
var fragmentCounter = 0;
|
|
374
|
-
function generateFragmentName(typeName) {
|
|
375
|
-
var fragmentName;
|
|
376
|
-
do {
|
|
377
|
-
fragmentName = "_" + typeName + "_Fragment" + fragmentCounter.toString();
|
|
378
|
-
fragmentCounter++;
|
|
379
|
-
} while (fragmentNames.has(fragmentName));
|
|
380
|
-
return fragmentName;
|
|
381
|
-
}
|
|
382
|
-
var expandedFragments = [];
|
|
383
|
-
var fragmentReplacements = Object.create(null);
|
|
384
|
-
try {
|
|
385
|
-
for (var fragments_1 = tslib.__values(fragments), fragments_1_1 = fragments_1.next(); !fragments_1_1.done; fragments_1_1 = fragments_1.next()) {
|
|
386
|
-
var fragment = fragments_1_1.value;
|
|
387
|
-
var possibleTypes = possibleTypesMap[fragment.typeCondition.name.value];
|
|
388
|
-
if (possibleTypes != null) {
|
|
389
|
-
var fragmentName = fragment.name.value;
|
|
390
|
-
fragmentReplacements[fragmentName] = [];
|
|
391
|
-
try {
|
|
392
|
-
for (var possibleTypes_3 = (e_12 = void 0, tslib.__values(possibleTypes)), possibleTypes_3_1 = possibleTypes_3.next(); !possibleTypes_3_1.done; possibleTypes_3_1 = possibleTypes_3.next()) {
|
|
393
|
-
var possibleTypeName = possibleTypes_3_1.value;
|
|
394
|
-
var name_1 = generateFragmentName(possibleTypeName);
|
|
395
|
-
fragmentNames.add(name_1);
|
|
396
|
-
expandedFragments.push({
|
|
397
|
-
kind: graphql.Kind.FRAGMENT_DEFINITION,
|
|
398
|
-
name: {
|
|
399
|
-
kind: graphql.Kind.NAME,
|
|
400
|
-
value: name_1,
|
|
401
|
-
},
|
|
402
|
-
typeCondition: {
|
|
403
|
-
kind: graphql.Kind.NAMED_TYPE,
|
|
404
|
-
name: {
|
|
405
|
-
kind: graphql.Kind.NAME,
|
|
406
|
-
value: possibleTypeName,
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
selectionSet: fragment.selectionSet,
|
|
410
|
-
});
|
|
411
|
-
fragmentReplacements[fragmentName].push({
|
|
412
|
-
fragmentName: name_1,
|
|
413
|
-
typeName: possibleTypeName,
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
418
|
-
finally {
|
|
419
|
-
try {
|
|
420
|
-
if (possibleTypes_3_1 && !possibleTypes_3_1.done && (_b = possibleTypes_3.return)) _b.call(possibleTypes_3);
|
|
421
|
-
}
|
|
422
|
-
finally { if (e_12) throw e_12.error; }
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
428
|
-
finally {
|
|
429
|
-
try {
|
|
430
|
-
if (fragments_1_1 && !fragments_1_1.done && (_a = fragments_1.return)) _a.call(fragments_1);
|
|
431
|
-
}
|
|
432
|
-
finally { if (e_11) throw e_11.error; }
|
|
433
|
-
}
|
|
434
|
-
return {
|
|
435
|
-
expandedFragments: expandedFragments,
|
|
436
|
-
fragmentReplacements: fragmentReplacements,
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
function wrapConcreteTypes(returnType, targetSchema, document) {
|
|
440
|
-
var _a;
|
|
441
|
-
var namedType = graphql.getNamedType(returnType);
|
|
442
|
-
if (!graphql.isObjectType(namedType)) {
|
|
443
|
-
return document;
|
|
444
|
-
}
|
|
445
|
-
var rootTypeNames = utils.getRootTypeNames(targetSchema);
|
|
446
|
-
var typeInfo = new graphql.TypeInfo(targetSchema);
|
|
447
|
-
var visitorKeys = {
|
|
448
|
-
Document: ['definitions'],
|
|
449
|
-
OperationDefinition: ['selectionSet'],
|
|
450
|
-
SelectionSet: ['selections'],
|
|
451
|
-
InlineFragment: ['selectionSet'],
|
|
452
|
-
FragmentDefinition: ['selectionSet'],
|
|
453
|
-
};
|
|
454
|
-
return graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, (_a = {},
|
|
455
|
-
_a[graphql.Kind.FRAGMENT_DEFINITION] = function (node) {
|
|
456
|
-
var typeName = node.typeCondition.name.value;
|
|
457
|
-
if (!rootTypeNames.has(typeName)) {
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
_a[graphql.Kind.FIELD] = function (node) {
|
|
462
|
-
var type = typeInfo.getType();
|
|
463
|
-
if (type != null && graphql.isAbstractType(graphql.getNamedType(type))) {
|
|
464
|
-
return tslib.__assign(tslib.__assign({}, node), { selectionSet: {
|
|
465
|
-
kind: graphql.Kind.SELECTION_SET,
|
|
466
|
-
selections: [
|
|
467
|
-
{
|
|
468
|
-
kind: graphql.Kind.INLINE_FRAGMENT,
|
|
469
|
-
typeCondition: {
|
|
470
|
-
kind: graphql.Kind.NAMED_TYPE,
|
|
471
|
-
name: {
|
|
472
|
-
kind: graphql.Kind.NAME,
|
|
473
|
-
value: namedType.name,
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
selectionSet: node.selectionSet,
|
|
477
|
-
},
|
|
478
|
-
],
|
|
479
|
-
} });
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
_a)),
|
|
483
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
484
|
-
// empty keys cannot be removed only because of typescript errors
|
|
485
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
486
|
-
visitorKeys);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function finalizeGatewayDocument(targetSchema, fragments, operations) {
|
|
490
|
-
var e_1, _a, e_2, _b;
|
|
491
|
-
var _c;
|
|
492
|
-
var usedVariables = [];
|
|
493
|
-
var usedFragments = [];
|
|
494
|
-
var newOperations = [];
|
|
495
|
-
var newFragments = [];
|
|
496
|
-
var validFragments = [];
|
|
497
|
-
var validFragmentsWithType = Object.create(null);
|
|
498
|
-
try {
|
|
499
|
-
for (var fragments_1 = tslib.__values(fragments), fragments_1_1 = fragments_1.next(); !fragments_1_1.done; fragments_1_1 = fragments_1.next()) {
|
|
500
|
-
var fragment = fragments_1_1.value;
|
|
501
|
-
var typeName = fragment.typeCondition.name.value;
|
|
502
|
-
var type = targetSchema.getType(typeName);
|
|
503
|
-
if (type != null) {
|
|
504
|
-
validFragments.push(fragment);
|
|
505
|
-
validFragmentsWithType[fragment.name.value] = type;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
510
|
-
finally {
|
|
511
|
-
try {
|
|
512
|
-
if (fragments_1_1 && !fragments_1_1.done && (_a = fragments_1.return)) _a.call(fragments_1);
|
|
513
|
-
}
|
|
514
|
-
finally { if (e_1) throw e_1.error; }
|
|
515
|
-
}
|
|
516
|
-
var fragmentSet = Object.create(null);
|
|
517
|
-
var _loop_1 = function (operation) {
|
|
518
|
-
var type = utils.getDefinedRootType(targetSchema, operation.operation);
|
|
519
|
-
var _d = finalizeSelectionSet(targetSchema, type, validFragmentsWithType, operation.selectionSet), selectionSet = _d.selectionSet, operationUsedFragments = _d.usedFragments, operationUsedVariables = _d.usedVariables;
|
|
520
|
-
usedFragments = union(usedFragments, operationUsedFragments);
|
|
521
|
-
var _e = collectFragmentVariables(targetSchema, fragmentSet, validFragments, validFragmentsWithType, usedFragments), collectedUsedVariables = _e.usedVariables, collectedNewFragments = _e.newFragments, collectedFragmentSet = _e.fragmentSet;
|
|
522
|
-
var operationOrFragmentVariables = union(operationUsedVariables, collectedUsedVariables);
|
|
523
|
-
usedVariables = union(usedVariables, operationOrFragmentVariables);
|
|
524
|
-
newFragments = collectedNewFragments;
|
|
525
|
-
fragmentSet = collectedFragmentSet;
|
|
526
|
-
var variableDefinitions = ((_c = operation.variableDefinitions) !== null && _c !== void 0 ? _c : []).filter(function (variable) { return operationOrFragmentVariables.indexOf(variable.variable.name.value) !== -1; });
|
|
527
|
-
newOperations.push({
|
|
528
|
-
kind: graphql.Kind.OPERATION_DEFINITION,
|
|
529
|
-
operation: operation.operation,
|
|
530
|
-
name: operation.name,
|
|
531
|
-
directives: operation.directives,
|
|
532
|
-
variableDefinitions: variableDefinitions,
|
|
533
|
-
selectionSet: selectionSet,
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
try {
|
|
537
|
-
for (var operations_1 = tslib.__values(operations), operations_1_1 = operations_1.next(); !operations_1_1.done; operations_1_1 = operations_1.next()) {
|
|
538
|
-
var operation = operations_1_1.value;
|
|
539
|
-
_loop_1(operation);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
543
|
-
finally {
|
|
544
|
-
try {
|
|
545
|
-
if (operations_1_1 && !operations_1_1.done && (_b = operations_1.return)) _b.call(operations_1);
|
|
546
|
-
}
|
|
547
|
-
finally { if (e_2) throw e_2.error; }
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
usedVariables: usedVariables,
|
|
551
|
-
newDocument: {
|
|
552
|
-
kind: graphql.Kind.DOCUMENT,
|
|
553
|
-
definitions: tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(newOperations), false), tslib.__read(newFragments), false),
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function finalizeGatewayRequest(originalRequest, delegationContext) {
|
|
558
|
-
var e_3, _a;
|
|
559
|
-
var document = originalRequest.document, variables = originalRequest.variables;
|
|
560
|
-
var _b = getDocumentMetadata(document), operations = _b.operations, fragments = _b.fragments;
|
|
561
|
-
var targetSchema = delegationContext.targetSchema, args = delegationContext.args;
|
|
562
|
-
if (args) {
|
|
563
|
-
var requestWithNewVariables = addVariablesToRootFields(targetSchema, operations, args);
|
|
564
|
-
operations = requestWithNewVariables.newOperations;
|
|
565
|
-
variables = Object.assign({}, variables !== null && variables !== void 0 ? variables : {}, requestWithNewVariables.newVariables);
|
|
566
|
-
}
|
|
567
|
-
var _c = finalizeGatewayDocument(targetSchema, fragments, operations), usedVariables = _c.usedVariables, newDocument = _c.newDocument;
|
|
568
|
-
var newVariables = {};
|
|
569
|
-
if (variables != null) {
|
|
570
|
-
try {
|
|
571
|
-
for (var usedVariables_1 = tslib.__values(usedVariables), usedVariables_1_1 = usedVariables_1.next(); !usedVariables_1_1.done; usedVariables_1_1 = usedVariables_1.next()) {
|
|
572
|
-
var variableName = usedVariables_1_1.value;
|
|
573
|
-
var variableValue = variables[variableName];
|
|
574
|
-
if (variableValue !== undefined) {
|
|
575
|
-
newVariables[variableName] = variableValue;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
580
|
-
finally {
|
|
581
|
-
try {
|
|
582
|
-
if (usedVariables_1_1 && !usedVariables_1_1.done && (_a = usedVariables_1.return)) _a.call(usedVariables_1);
|
|
583
|
-
}
|
|
584
|
-
finally { if (e_3) throw e_3.error; }
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
return tslib.__assign(tslib.__assign({}, originalRequest), { document: newDocument, variables: newVariables });
|
|
588
|
-
}
|
|
589
|
-
function addVariablesToRootFields(targetSchema, operations, args) {
|
|
590
|
-
var newVariables = Object.create(null);
|
|
591
|
-
var newOperations = operations.map(function (operation) {
|
|
592
|
-
var e_4, _a;
|
|
593
|
-
var _b, _c;
|
|
594
|
-
var variableDefinitionMap = ((_b = operation.variableDefinitions) !== null && _b !== void 0 ? _b : []).reduce(function (prev, def) {
|
|
595
|
-
var _a;
|
|
596
|
-
return (tslib.__assign(tslib.__assign({}, prev), (_a = {}, _a[def.variable.name.value] = def, _a)));
|
|
597
|
-
}, {});
|
|
598
|
-
var type = utils.getDefinedRootType(targetSchema, operation.operation);
|
|
599
|
-
var newSelectionSet = [];
|
|
600
|
-
try {
|
|
601
|
-
for (var _d = tslib.__values(operation.selectionSet.selections), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
602
|
-
var selection = _e.value;
|
|
603
|
-
if (selection.kind === graphql.Kind.FIELD) {
|
|
604
|
-
var argumentNodes = (_c = selection.arguments) !== null && _c !== void 0 ? _c : [];
|
|
605
|
-
var argumentNodeMap = argumentNodes.reduce(function (prev, argument) {
|
|
606
|
-
var _a;
|
|
607
|
-
return (tslib.__assign(tslib.__assign({}, prev), (_a = {}, _a[argument.name.value] = argument, _a)));
|
|
608
|
-
}, {});
|
|
609
|
-
var targetField = type.getFields()[selection.name.value];
|
|
610
|
-
// excludes __typename
|
|
611
|
-
if (targetField != null) {
|
|
612
|
-
updateArguments(targetField, argumentNodeMap, variableDefinitionMap, newVariables, args);
|
|
613
|
-
}
|
|
614
|
-
newSelectionSet.push(tslib.__assign(tslib.__assign({}, selection), { arguments: Object.values(argumentNodeMap) }));
|
|
615
|
-
}
|
|
616
|
-
else {
|
|
617
|
-
newSelectionSet.push(selection);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
622
|
-
finally {
|
|
623
|
-
try {
|
|
624
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
625
|
-
}
|
|
626
|
-
finally { if (e_4) throw e_4.error; }
|
|
627
|
-
}
|
|
628
|
-
return tslib.__assign(tslib.__assign({}, operation), { variableDefinitions: Object.values(variableDefinitionMap), selectionSet: {
|
|
629
|
-
kind: graphql.Kind.SELECTION_SET,
|
|
630
|
-
selections: newSelectionSet,
|
|
631
|
-
} });
|
|
632
|
-
});
|
|
633
|
-
return {
|
|
634
|
-
newOperations: newOperations,
|
|
635
|
-
newVariables: newVariables,
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
function updateArguments(targetField, argumentNodeMap, variableDefinitionMap, variableValues, newArgs) {
|
|
639
|
-
var e_5, _a;
|
|
640
|
-
var generateVariableName = utils.createVariableNameGenerator(variableDefinitionMap);
|
|
641
|
-
try {
|
|
642
|
-
for (var _b = tslib.__values(targetField.args), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
643
|
-
var argument = _c.value;
|
|
644
|
-
var argName = argument.name;
|
|
645
|
-
var argType = argument.type;
|
|
646
|
-
if (argName in newArgs) {
|
|
647
|
-
utils.updateArgument(argumentNodeMap, variableDefinitionMap, variableValues, argName, generateVariableName(argName), argType, utils.serializeInputValue(argType, newArgs[argName]));
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
652
|
-
finally {
|
|
653
|
-
try {
|
|
654
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
655
|
-
}
|
|
656
|
-
finally { if (e_5) throw e_5.error; }
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
function collectFragmentVariables(targetSchema, fragmentSet, validFragments, validFragmentsWithType, usedFragments) {
|
|
660
|
-
var remainingFragments = usedFragments.slice();
|
|
661
|
-
var usedVariables = [];
|
|
662
|
-
var newFragments = [];
|
|
663
|
-
var _loop_2 = function () {
|
|
664
|
-
var nextFragmentName = remainingFragments.pop();
|
|
665
|
-
var fragment = validFragments.find(function (fr) { return fr.name.value === nextFragmentName; });
|
|
666
|
-
if (fragment != null) {
|
|
667
|
-
var name_1 = nextFragmentName;
|
|
668
|
-
var typeName = fragment.typeCondition.name.value;
|
|
669
|
-
var type = targetSchema.getType(typeName);
|
|
670
|
-
if (type == null) {
|
|
671
|
-
throw new Error("Fragment reference type \"" + typeName + "\", but the type is not contained within the target schema.");
|
|
672
|
-
}
|
|
673
|
-
var _a = finalizeSelectionSet(targetSchema, type, validFragmentsWithType, fragment.selectionSet), selectionSet = _a.selectionSet, fragmentUsedFragments = _a.usedFragments, fragmentUsedVariables = _a.usedVariables;
|
|
674
|
-
remainingFragments = union(remainingFragments, fragmentUsedFragments);
|
|
675
|
-
usedVariables = union(usedVariables, fragmentUsedVariables);
|
|
676
|
-
if (name_1 && !(name_1 in fragmentSet)) {
|
|
677
|
-
fragmentSet[name_1] = true;
|
|
678
|
-
newFragments.push({
|
|
679
|
-
kind: graphql.Kind.FRAGMENT_DEFINITION,
|
|
680
|
-
name: {
|
|
681
|
-
kind: graphql.Kind.NAME,
|
|
682
|
-
value: name_1,
|
|
683
|
-
},
|
|
684
|
-
typeCondition: fragment.typeCondition,
|
|
685
|
-
selectionSet: selectionSet,
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
while (remainingFragments.length !== 0) {
|
|
691
|
-
_loop_2();
|
|
692
|
-
}
|
|
693
|
-
return {
|
|
694
|
-
usedVariables: usedVariables,
|
|
695
|
-
newFragments: newFragments,
|
|
696
|
-
fragmentSet: fragmentSet,
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
var filteredSelectionSetVisitorKeys = {
|
|
700
|
-
SelectionSet: ['selections'],
|
|
701
|
-
Field: ['selectionSet'],
|
|
702
|
-
InlineFragment: ['selectionSet'],
|
|
703
|
-
FragmentDefinition: ['selectionSet'],
|
|
704
|
-
};
|
|
705
|
-
var variablesVisitorKeys = {
|
|
706
|
-
SelectionSet: ['selections'],
|
|
707
|
-
Field: ['arguments', 'directives', 'selectionSet'],
|
|
708
|
-
Argument: ['value'],
|
|
709
|
-
InlineFragment: ['directives', 'selectionSet'],
|
|
710
|
-
FragmentSpread: ['directives'],
|
|
711
|
-
FragmentDefinition: ['selectionSet'],
|
|
712
|
-
ObjectValue: ['fields'],
|
|
713
|
-
ObjectField: ['name', 'value'],
|
|
714
|
-
Directive: ['arguments'],
|
|
715
|
-
ListValue: ['values'],
|
|
716
|
-
};
|
|
717
|
-
function finalizeSelectionSet(schema, type, validFragments, selectionSet) {
|
|
718
|
-
var _a, _b;
|
|
719
|
-
var usedFragments = [];
|
|
720
|
-
var usedVariables = [];
|
|
721
|
-
var typeInfo = graphql.versionInfo.major < 16 ? new graphql.TypeInfo(schema, undefined, type) : new graphql.TypeInfo(schema, type);
|
|
722
|
-
var filteredSelectionSet = graphql.visit(selectionSet, graphql.visitWithTypeInfo(typeInfo, (_a = {},
|
|
723
|
-
_a[graphql.Kind.FIELD] = {
|
|
724
|
-
enter: function (node) {
|
|
725
|
-
var e_6, _a, e_7, _b;
|
|
726
|
-
var parentType = typeInfo.getParentType();
|
|
727
|
-
if (graphql.isObjectType(parentType) || graphql.isInterfaceType(parentType)) {
|
|
728
|
-
var fields = parentType.getFields();
|
|
729
|
-
var field = node.name.value === '__typename' ? graphql.TypeNameMetaFieldDef : fields[node.name.value];
|
|
730
|
-
if (!field) {
|
|
731
|
-
return null;
|
|
732
|
-
}
|
|
733
|
-
var args = field.args != null ? field.args : [];
|
|
734
|
-
var argsMap = Object.create(null);
|
|
735
|
-
try {
|
|
736
|
-
for (var args_1 = tslib.__values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
737
|
-
var arg = args_1_1.value;
|
|
738
|
-
argsMap[arg.name] = arg;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
742
|
-
finally {
|
|
743
|
-
try {
|
|
744
|
-
if (args_1_1 && !args_1_1.done && (_a = args_1.return)) _a.call(args_1);
|
|
745
|
-
}
|
|
746
|
-
finally { if (e_6) throw e_6.error; }
|
|
747
|
-
}
|
|
748
|
-
if (node.arguments != null) {
|
|
749
|
-
var newArgs = [];
|
|
750
|
-
try {
|
|
751
|
-
for (var _c = tslib.__values(node.arguments), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
752
|
-
var arg = _d.value;
|
|
753
|
-
if (arg.name.value in argsMap) {
|
|
754
|
-
newArgs.push(arg);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
759
|
-
finally {
|
|
760
|
-
try {
|
|
761
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
762
|
-
}
|
|
763
|
-
finally { if (e_7) throw e_7.error; }
|
|
764
|
-
}
|
|
765
|
-
if (newArgs.length !== node.arguments.length) {
|
|
766
|
-
return tslib.__assign(tslib.__assign({}, node), { arguments: newArgs });
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
leave: function (node) {
|
|
772
|
-
var type = typeInfo.getType();
|
|
773
|
-
if (type == null) {
|
|
774
|
-
throw new Error("No type was found for field node " + utils.inspect(node) + ".");
|
|
775
|
-
}
|
|
776
|
-
var namedType = graphql.getNamedType(type);
|
|
777
|
-
if (!schema.getType(namedType.name) == null) {
|
|
778
|
-
return null;
|
|
779
|
-
}
|
|
780
|
-
if (graphql.isObjectType(namedType) || graphql.isInterfaceType(namedType)) {
|
|
781
|
-
var selections = node.selectionSet != null ? node.selectionSet.selections : null;
|
|
782
|
-
if (selections == null || selections.length === 0) {
|
|
783
|
-
return null;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
},
|
|
788
|
-
_a[graphql.Kind.FRAGMENT_SPREAD] = {
|
|
789
|
-
enter: function (node) {
|
|
790
|
-
if (!(node.name.value in validFragments)) {
|
|
791
|
-
return null;
|
|
792
|
-
}
|
|
793
|
-
var parentType = typeInfo.getParentType();
|
|
794
|
-
var innerType = validFragments[node.name.value];
|
|
795
|
-
if (!utils.implementsAbstractType(schema, parentType, innerType)) {
|
|
796
|
-
return null;
|
|
797
|
-
}
|
|
798
|
-
usedFragments.push(node.name.value);
|
|
799
|
-
},
|
|
800
|
-
},
|
|
801
|
-
_a[graphql.Kind.INLINE_FRAGMENT] = {
|
|
802
|
-
enter: function (node) {
|
|
803
|
-
if (node.typeCondition != null) {
|
|
804
|
-
var parentType = typeInfo.getParentType();
|
|
805
|
-
var innerType = schema.getType(node.typeCondition.name.value);
|
|
806
|
-
if (!utils.implementsAbstractType(schema, parentType, innerType)) {
|
|
807
|
-
return null;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
},
|
|
811
|
-
},
|
|
812
|
-
_a[graphql.Kind.SELECTION_SET] = {
|
|
813
|
-
leave: function (node) {
|
|
814
|
-
var parentType = typeInfo.getParentType();
|
|
815
|
-
if (parentType != null && graphql.isAbstractType(parentType)) {
|
|
816
|
-
var selections = node.selections.concat([
|
|
817
|
-
{
|
|
818
|
-
kind: graphql.Kind.FIELD,
|
|
819
|
-
name: {
|
|
820
|
-
kind: graphql.Kind.NAME,
|
|
821
|
-
value: '__typename',
|
|
822
|
-
},
|
|
823
|
-
},
|
|
824
|
-
]);
|
|
825
|
-
return tslib.__assign(tslib.__assign({}, node), { selections: selections });
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
},
|
|
829
|
-
_a)),
|
|
830
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
831
|
-
// empty keys cannot be removed only because of typescript errors
|
|
832
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
833
|
-
filteredSelectionSetVisitorKeys);
|
|
834
|
-
graphql.visit(filteredSelectionSet, (_b = {},
|
|
835
|
-
_b[graphql.Kind.VARIABLE] = function (variableNode) {
|
|
836
|
-
usedVariables.push(variableNode.name.value);
|
|
837
|
-
},
|
|
838
|
-
_b),
|
|
839
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
840
|
-
// empty keys cannot be removed only because of typescript errors
|
|
841
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
842
|
-
variablesVisitorKeys);
|
|
843
|
-
return {
|
|
844
|
-
selectionSet: filteredSelectionSet,
|
|
845
|
-
usedFragments: usedFragments,
|
|
846
|
-
usedVariables: usedVariables,
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
function union() {
|
|
850
|
-
var e_8, _a, e_9, _b;
|
|
851
|
-
var arrays = [];
|
|
852
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
853
|
-
arrays[_i] = arguments[_i];
|
|
854
|
-
}
|
|
855
|
-
var cache = Object.create(null);
|
|
856
|
-
var result = [];
|
|
857
|
-
try {
|
|
858
|
-
for (var arrays_1 = tslib.__values(arrays), arrays_1_1 = arrays_1.next(); !arrays_1_1.done; arrays_1_1 = arrays_1.next()) {
|
|
859
|
-
var array = arrays_1_1.value;
|
|
860
|
-
try {
|
|
861
|
-
for (var array_1 = (e_9 = void 0, tslib.__values(array)), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
|
|
862
|
-
var item = array_1_1.value;
|
|
863
|
-
if (!(item in cache)) {
|
|
864
|
-
cache[item] = true;
|
|
865
|
-
result.push(item);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
870
|
-
finally {
|
|
871
|
-
try {
|
|
872
|
-
if (array_1_1 && !array_1_1.done && (_b = array_1.return)) _b.call(array_1);
|
|
873
|
-
}
|
|
874
|
-
finally { if (e_9) throw e_9.error; }
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
879
|
-
finally {
|
|
880
|
-
try {
|
|
881
|
-
if (arrays_1_1 && !arrays_1_1.done && (_a = arrays_1.return)) _a.call(arrays_1);
|
|
882
|
-
}
|
|
883
|
-
finally { if (e_8) throw e_8.error; }
|
|
884
|
-
}
|
|
885
|
-
return result;
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
var UNPATHED_ERRORS_SYMBOL = Symbol('subschemaErrors');
|
|
889
|
-
var OBJECT_SUBSCHEMA_SYMBOL = Symbol('initialSubschema');
|
|
890
|
-
var FIELD_SUBSCHEMA_MAP_SYMBOL = Symbol('subschemaMap');
|
|
891
|
-
|
|
892
|
-
function isExternalObject(data) {
|
|
893
|
-
return data[UNPATHED_ERRORS_SYMBOL] !== undefined;
|
|
894
|
-
}
|
|
895
|
-
function annotateExternalObject(object, errors, subschema, subschemaMap) {
|
|
896
|
-
var _a;
|
|
897
|
-
Object.defineProperties(object, (_a = {},
|
|
898
|
-
_a[OBJECT_SUBSCHEMA_SYMBOL] = { value: subschema },
|
|
899
|
-
_a[FIELD_SUBSCHEMA_MAP_SYMBOL] = { value: subschemaMap },
|
|
900
|
-
_a[UNPATHED_ERRORS_SYMBOL] = { value: errors },
|
|
901
|
-
_a));
|
|
902
|
-
return object;
|
|
903
|
-
}
|
|
904
|
-
function getSubschema(object, responseKey) {
|
|
905
|
-
var _a;
|
|
906
|
-
return (_a = object[FIELD_SUBSCHEMA_MAP_SYMBOL][responseKey]) !== null && _a !== void 0 ? _a : object[OBJECT_SUBSCHEMA_SYMBOL];
|
|
907
|
-
}
|
|
908
|
-
function getUnpathedErrors(object) {
|
|
909
|
-
return object[UNPATHED_ERRORS_SYMBOL];
|
|
910
|
-
}
|
|
911
|
-
var EMPTY_ARRAY = [];
|
|
912
|
-
var EMPTY_OBJECT = Object.create(null);
|
|
913
|
-
function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
914
|
-
var _a;
|
|
915
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
916
|
-
var delegationMaps, delegationMaps_1, delegationMaps_1_1, delegationMap, e_1_1;
|
|
917
|
-
var e_1, _b;
|
|
918
|
-
return tslib.__generator(this, function (_c) {
|
|
919
|
-
switch (_c.label) {
|
|
920
|
-
case 0:
|
|
921
|
-
delegationMaps = mergedTypeInfo.delegationPlanBuilder(info.schema, sourceSubschema, info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT, info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT, ((_a = info.fieldNodes) === null || _a === void 0 ? void 0 : _a.length) ? info.fieldNodes : EMPTY_ARRAY);
|
|
922
|
-
_c.label = 1;
|
|
923
|
-
case 1:
|
|
924
|
-
_c.trys.push([1, 6, 7, 8]);
|
|
925
|
-
delegationMaps_1 = tslib.__values(delegationMaps), delegationMaps_1_1 = delegationMaps_1.next();
|
|
926
|
-
_c.label = 2;
|
|
927
|
-
case 2:
|
|
928
|
-
if (!!delegationMaps_1_1.done) return [3 /*break*/, 5];
|
|
929
|
-
delegationMap = delegationMaps_1_1.value;
|
|
930
|
-
return [4 /*yield*/, executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info)];
|
|
931
|
-
case 3:
|
|
932
|
-
_c.sent();
|
|
933
|
-
_c.label = 4;
|
|
934
|
-
case 4:
|
|
935
|
-
delegationMaps_1_1 = delegationMaps_1.next();
|
|
936
|
-
return [3 /*break*/, 2];
|
|
937
|
-
case 5: return [3 /*break*/, 8];
|
|
938
|
-
case 6:
|
|
939
|
-
e_1_1 = _c.sent();
|
|
940
|
-
e_1 = { error: e_1_1 };
|
|
941
|
-
return [3 /*break*/, 8];
|
|
942
|
-
case 7:
|
|
943
|
-
try {
|
|
944
|
-
if (delegationMaps_1_1 && !delegationMaps_1_1.done && (_b = delegationMaps_1.return)) _b.call(delegationMaps_1);
|
|
945
|
-
}
|
|
946
|
-
finally { if (e_1) throw e_1.error; }
|
|
947
|
-
return [7 /*endfinally*/];
|
|
948
|
-
case 8: return [2 /*return*/, object];
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
function executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info) {
|
|
954
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
955
|
-
var combinedErrors, path, combinedFieldSubschemaMap, type;
|
|
956
|
-
var _this = this;
|
|
957
|
-
return tslib.__generator(this, function (_a) {
|
|
958
|
-
switch (_a.label) {
|
|
959
|
-
case 0:
|
|
960
|
-
combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
961
|
-
path = graphql.responsePathAsArray(info.path);
|
|
962
|
-
combinedFieldSubschemaMap = object[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
963
|
-
type = info.schema.getType(object.__typename);
|
|
964
|
-
return [4 /*yield*/, Promise.all(tslib.__spreadArray([], tslib.__read(delegationMap.entries()), false).map(function (_a) {
|
|
965
|
-
var _b = tslib.__read(_a, 2), s = _b[0], selectionSet = _b[1];
|
|
966
|
-
return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
967
|
-
var resolver, source, error_1, fieldNodeResponseKeyMap, nullResult, fieldNodeResponseKeyMap_1, fieldNodeResponseKeyMap_1_1, _c, responseKey, fieldNodes, combinedPath, objectSubschema, fieldSubschemaMap, responseKey;
|
|
968
|
-
var e_2, _d;
|
|
969
|
-
var _e;
|
|
970
|
-
return tslib.__generator(this, function (_f) {
|
|
971
|
-
switch (_f.label) {
|
|
972
|
-
case 0:
|
|
973
|
-
resolver = mergedTypeInfo.resolvers.get(s);
|
|
974
|
-
if (!resolver) return [3 /*break*/, 5];
|
|
975
|
-
source = void 0;
|
|
976
|
-
_f.label = 1;
|
|
977
|
-
case 1:
|
|
978
|
-
_f.trys.push([1, 3, , 4]);
|
|
979
|
-
return [4 /*yield*/, resolver(object, context, info, s, selectionSet)];
|
|
980
|
-
case 2:
|
|
981
|
-
source = _f.sent();
|
|
982
|
-
return [3 /*break*/, 4];
|
|
983
|
-
case 3:
|
|
984
|
-
error_1 = _f.sent();
|
|
985
|
-
source = error_1;
|
|
986
|
-
return [3 /*break*/, 4];
|
|
987
|
-
case 4:
|
|
988
|
-
if (source instanceof Error || source == null) {
|
|
989
|
-
fieldNodeResponseKeyMap = utils.collectFields(info.schema, {}, {}, type, selectionSet, new Map(), new Set());
|
|
990
|
-
nullResult = {};
|
|
991
|
-
try {
|
|
992
|
-
for (fieldNodeResponseKeyMap_1 = tslib.__values(fieldNodeResponseKeyMap), fieldNodeResponseKeyMap_1_1 = fieldNodeResponseKeyMap_1.next(); !fieldNodeResponseKeyMap_1_1.done; fieldNodeResponseKeyMap_1_1 = fieldNodeResponseKeyMap_1.next()) {
|
|
993
|
-
_c = tslib.__read(fieldNodeResponseKeyMap_1_1.value, 2), responseKey = _c[0], fieldNodes = _c[1];
|
|
994
|
-
combinedPath = tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(path), false), [responseKey], false);
|
|
995
|
-
if (source instanceof graphql.GraphQLError) {
|
|
996
|
-
nullResult[responseKey] = utils.relocatedError(source, combinedPath);
|
|
997
|
-
}
|
|
998
|
-
else if (source instanceof Error) {
|
|
999
|
-
nullResult[responseKey] = graphql.locatedError(source, fieldNodes, combinedPath);
|
|
1000
|
-
}
|
|
1001
|
-
else {
|
|
1002
|
-
nullResult[responseKey] = null;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1007
|
-
finally {
|
|
1008
|
-
try {
|
|
1009
|
-
if (fieldNodeResponseKeyMap_1_1 && !fieldNodeResponseKeyMap_1_1.done && (_d = fieldNodeResponseKeyMap_1.return)) _d.call(fieldNodeResponseKeyMap_1);
|
|
1010
|
-
}
|
|
1011
|
-
finally { if (e_2) throw e_2.error; }
|
|
1012
|
-
}
|
|
1013
|
-
source = nullResult;
|
|
1014
|
-
}
|
|
1015
|
-
else {
|
|
1016
|
-
if (source[UNPATHED_ERRORS_SYMBOL]) {
|
|
1017
|
-
combinedErrors.push.apply(combinedErrors, tslib.__spreadArray([], tslib.__read(source[UNPATHED_ERRORS_SYMBOL]), false));
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
objectSubschema = source[OBJECT_SUBSCHEMA_SYMBOL];
|
|
1021
|
-
fieldSubschemaMap = source[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
1022
|
-
for (responseKey in source) {
|
|
1023
|
-
object[responseKey] = source[responseKey];
|
|
1024
|
-
combinedFieldSubschemaMap[responseKey] = (_e = fieldSubschemaMap === null || fieldSubschemaMap === void 0 ? void 0 : fieldSubschemaMap[responseKey]) !== null && _e !== void 0 ? _e : objectSubschema;
|
|
1025
|
-
}
|
|
1026
|
-
_f.label = 5;
|
|
1027
|
-
case 5: return [2 /*return*/];
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
}))];
|
|
1032
|
-
case 1:
|
|
1033
|
-
_a.sent();
|
|
1034
|
-
return [2 /*return*/];
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
function resolveExternalValue(result, unpathedErrors, subschema, context, info, returnType, skipTypeMerging) {
|
|
1041
|
-
if (returnType === void 0) { returnType = getReturnType(info); }
|
|
1042
|
-
var type = graphql.getNullableType(returnType);
|
|
1043
|
-
if (result instanceof Error) {
|
|
1044
|
-
return result;
|
|
1045
|
-
}
|
|
1046
|
-
if (result == null) {
|
|
1047
|
-
return reportUnpathedErrorsViaNull(unpathedErrors);
|
|
1048
|
-
}
|
|
1049
|
-
if ('parseValue' in type) {
|
|
1050
|
-
return type.parseValue(result);
|
|
1051
|
-
}
|
|
1052
|
-
else if (graphql.isCompositeType(type)) {
|
|
1053
|
-
return resolveExternalObject(type, result, unpathedErrors, subschema, context, info, skipTypeMerging);
|
|
1054
|
-
}
|
|
1055
|
-
else if (graphql.isListType(type)) {
|
|
1056
|
-
return resolveExternalList(type, result, unpathedErrors, subschema, context, info, skipTypeMerging);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
function resolveExternalObject(type, object, unpathedErrors, subschema, context, info, skipTypeMerging) {
|
|
1060
|
-
var _a;
|
|
1061
|
-
// if we have already resolved this object, for example, when the identical object appears twice
|
|
1062
|
-
// in a list, see https://github.com/ardatan/graphql-tools/issues/2304
|
|
1063
|
-
if (!isExternalObject(object)) {
|
|
1064
|
-
annotateExternalObject(object, unpathedErrors, subschema, Object.create(null));
|
|
1065
|
-
}
|
|
1066
|
-
if (skipTypeMerging || info == null) {
|
|
1067
|
-
return object;
|
|
1068
|
-
}
|
|
1069
|
-
var stitchingInfo = (_a = info.schema.extensions) === null || _a === void 0 ? void 0 : _a['stitchingInfo'];
|
|
1070
|
-
if (stitchingInfo == null) {
|
|
1071
|
-
return object;
|
|
1072
|
-
}
|
|
1073
|
-
var typeName;
|
|
1074
|
-
if (graphql.isAbstractType(type)) {
|
|
1075
|
-
var resolvedType = info.schema.getType(object.__typename);
|
|
1076
|
-
if (resolvedType == null) {
|
|
1077
|
-
throw new Error("Unable to resolve type '" + object.__typename + "'. Did you forget to include a transform that renames types? Did you delegate to the original subschema rather that the subschema config object containing the transform?");
|
|
1078
|
-
}
|
|
1079
|
-
typeName = resolvedType.name;
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
typeName = type.name;
|
|
1083
|
-
}
|
|
1084
|
-
var mergedTypeInfo = stitchingInfo.mergedTypes[typeName];
|
|
1085
|
-
var targetSubschemas;
|
|
1086
|
-
// Within the stitching context, delegation to a stitched GraphQLSchema or SubschemaConfig
|
|
1087
|
-
// will be redirected to the appropriate Subschema object, from which merge targets can be queried.
|
|
1088
|
-
if (mergedTypeInfo != null) {
|
|
1089
|
-
targetSubschemas = mergedTypeInfo.targetSubschemas.get(subschema);
|
|
1090
|
-
}
|
|
1091
|
-
// If there are no merge targets from the subschema, return.
|
|
1092
|
-
if (!targetSubschemas || !targetSubschemas.length) {
|
|
1093
|
-
return object;
|
|
1094
|
-
}
|
|
1095
|
-
return mergeFields(mergedTypeInfo, object, subschema, context, info);
|
|
1096
|
-
}
|
|
1097
|
-
function resolveExternalList(type, list, unpathedErrors, subschema, context, info, skipTypeMerging) {
|
|
1098
|
-
return list.map(function (listMember) {
|
|
1099
|
-
return resolveExternalListMember(graphql.getNullableType(type.ofType), listMember, unpathedErrors, subschema, context, info, skipTypeMerging);
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
function resolveExternalListMember(type, listMember, unpathedErrors, subschema, context, info, skipTypeMerging) {
|
|
1103
|
-
if (listMember instanceof Error) {
|
|
1104
|
-
return listMember;
|
|
1105
|
-
}
|
|
1106
|
-
if (listMember == null) {
|
|
1107
|
-
return reportUnpathedErrorsViaNull(unpathedErrors);
|
|
1108
|
-
}
|
|
1109
|
-
if ('parseValue' in type) {
|
|
1110
|
-
return type.parseValue(listMember);
|
|
1111
|
-
}
|
|
1112
|
-
else if (graphql.isCompositeType(type)) {
|
|
1113
|
-
return resolveExternalObject(type, listMember, unpathedErrors, subschema, context, info, skipTypeMerging);
|
|
1114
|
-
}
|
|
1115
|
-
else if (graphql.isListType(type)) {
|
|
1116
|
-
return resolveExternalList(type, listMember, unpathedErrors, subschema, context, info, skipTypeMerging);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
var reportedErrors = new WeakMap();
|
|
1120
|
-
function reportUnpathedErrorsViaNull(unpathedErrors) {
|
|
1121
|
-
var e_1, _a;
|
|
1122
|
-
if (unpathedErrors.length) {
|
|
1123
|
-
var unreportedErrors = [];
|
|
1124
|
-
try {
|
|
1125
|
-
for (var unpathedErrors_1 = tslib.__values(unpathedErrors), unpathedErrors_1_1 = unpathedErrors_1.next(); !unpathedErrors_1_1.done; unpathedErrors_1_1 = unpathedErrors_1.next()) {
|
|
1126
|
-
var error = unpathedErrors_1_1.value;
|
|
1127
|
-
if (!reportedErrors.has(error)) {
|
|
1128
|
-
unreportedErrors.push(error);
|
|
1129
|
-
reportedErrors.set(error, true);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1134
|
-
finally {
|
|
1135
|
-
try {
|
|
1136
|
-
if (unpathedErrors_1_1 && !unpathedErrors_1_1.done && (_a = unpathedErrors_1.return)) _a.call(unpathedErrors_1);
|
|
1137
|
-
}
|
|
1138
|
-
finally { if (e_1) throw e_1.error; }
|
|
1139
|
-
}
|
|
1140
|
-
if (unreportedErrors.length) {
|
|
1141
|
-
if (unreportedErrors.length === 1) {
|
|
1142
|
-
return unreportedErrors[0];
|
|
1143
|
-
}
|
|
1144
|
-
var combinedError = new utils.AggregateError(unreportedErrors);
|
|
1145
|
-
// We cast path as any for GraphQL.js 14 compat
|
|
1146
|
-
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
|
|
1147
|
-
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
|
|
1148
|
-
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
|
|
1149
|
-
return graphql.locatedError(combinedError, undefined, unreportedErrors[0].path);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
return null;
|
|
1153
|
-
}
|
|
1154
|
-
function getReturnType(info) {
|
|
1155
|
-
if (info == null) {
|
|
1156
|
-
throw new Error("Return type cannot be inferred without a source schema.");
|
|
1157
|
-
}
|
|
1158
|
-
return info.returnType;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
function checkResultAndHandleErrors(result, delegationContext) {
|
|
1162
|
-
var context = delegationContext.context, info = delegationContext.info, _a = delegationContext.fieldName, responseKey = _a === void 0 ? getResponseKey(info) : _a, subschema = delegationContext.subschema, _b = delegationContext.returnType, returnType = _b === void 0 ? getReturnType$1(info) : _b, skipTypeMerging = delegationContext.skipTypeMerging, onLocatedError = delegationContext.onLocatedError;
|
|
1163
|
-
var _c = mergeDataAndErrors(result.data == null ? undefined : result.data[responseKey], result.errors == null ? [] : result.errors, info != null && info.path ? graphql.responsePathAsArray(info.path) : undefined, onLocatedError), data = _c.data, unpathedErrors = _c.unpathedErrors;
|
|
1164
|
-
return resolveExternalValue(data, unpathedErrors, subschema, context, info, returnType, skipTypeMerging);
|
|
1165
|
-
}
|
|
1166
|
-
function mergeDataAndErrors(data, errors, path, onLocatedError, index) {
|
|
1167
|
-
var e_1, _a, e_2, _b;
|
|
1168
|
-
var _c;
|
|
1169
|
-
if (index === void 0) { index = 1; }
|
|
1170
|
-
if (data == null) {
|
|
1171
|
-
if (!errors.length) {
|
|
1172
|
-
return { data: null, unpathedErrors: [] };
|
|
1173
|
-
}
|
|
1174
|
-
if (errors.length === 1) {
|
|
1175
|
-
var error = onLocatedError ? onLocatedError(errors[0]) : errors[0];
|
|
1176
|
-
var newPath = path === undefined ? error.path : error.path === undefined ? path : path.concat(error.path.slice(1));
|
|
1177
|
-
return { data: utils.relocatedError(errors[0], newPath), unpathedErrors: [] };
|
|
1178
|
-
}
|
|
1179
|
-
// We cast path as any for GraphQL.js 14 compat
|
|
1180
|
-
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
|
|
1181
|
-
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
|
|
1182
|
-
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
|
|
1183
|
-
var newError = graphql.locatedError(new utils.AggregateError(errors), undefined, path);
|
|
1184
|
-
return { data: newError, unpathedErrors: [] };
|
|
1185
|
-
}
|
|
1186
|
-
if (!errors.length) {
|
|
1187
|
-
return { data: data, unpathedErrors: [] };
|
|
1188
|
-
}
|
|
1189
|
-
var unpathedErrors = [];
|
|
1190
|
-
var errorMap = new Map();
|
|
1191
|
-
try {
|
|
1192
|
-
for (var errors_1 = tslib.__values(errors), errors_1_1 = errors_1.next(); !errors_1_1.done; errors_1_1 = errors_1.next()) {
|
|
1193
|
-
var error = errors_1_1.value;
|
|
1194
|
-
var pathSegment = (_c = error.path) === null || _c === void 0 ? void 0 : _c[index];
|
|
1195
|
-
if (pathSegment != null) {
|
|
1196
|
-
var pathSegmentErrors = errorMap.get(pathSegment);
|
|
1197
|
-
if (pathSegmentErrors === undefined) {
|
|
1198
|
-
pathSegmentErrors = [error];
|
|
1199
|
-
errorMap.set(pathSegment, pathSegmentErrors);
|
|
1200
|
-
}
|
|
1201
|
-
else {
|
|
1202
|
-
pathSegmentErrors.push(error);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
else {
|
|
1206
|
-
unpathedErrors.push(error);
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1211
|
-
finally {
|
|
1212
|
-
try {
|
|
1213
|
-
if (errors_1_1 && !errors_1_1.done && (_a = errors_1.return)) _a.call(errors_1);
|
|
1214
|
-
}
|
|
1215
|
-
finally { if (e_1) throw e_1.error; }
|
|
1216
|
-
}
|
|
1217
|
-
try {
|
|
1218
|
-
for (var errorMap_1 = tslib.__values(errorMap), errorMap_1_1 = errorMap_1.next(); !errorMap_1_1.done; errorMap_1_1 = errorMap_1.next()) {
|
|
1219
|
-
var _d = tslib.__read(errorMap_1_1.value, 2), pathSegment = _d[0], pathSegmentErrors = _d[1];
|
|
1220
|
-
if (data[pathSegment] !== undefined) {
|
|
1221
|
-
var _e = mergeDataAndErrors(data[pathSegment], pathSegmentErrors, path, onLocatedError, index + 1), newData = _e.data, newErrors = _e.unpathedErrors;
|
|
1222
|
-
data[pathSegment] = newData;
|
|
1223
|
-
unpathedErrors.push.apply(unpathedErrors, tslib.__spreadArray([], tslib.__read(newErrors), false));
|
|
1224
|
-
}
|
|
1225
|
-
else {
|
|
1226
|
-
unpathedErrors.push.apply(unpathedErrors, tslib.__spreadArray([], tslib.__read(pathSegmentErrors), false));
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1231
|
-
finally {
|
|
1232
|
-
try {
|
|
1233
|
-
if (errorMap_1_1 && !errorMap_1_1.done && (_b = errorMap_1.return)) _b.call(errorMap_1);
|
|
1234
|
-
}
|
|
1235
|
-
finally { if (e_2) throw e_2.error; }
|
|
1236
|
-
}
|
|
1237
|
-
return { data: data, unpathedErrors: unpathedErrors };
|
|
1238
|
-
}
|
|
1239
|
-
function getResponseKey(info) {
|
|
1240
|
-
if (info == null) {
|
|
1241
|
-
throw new Error("Data cannot be extracted from result without an explicit key or source schema.");
|
|
1242
|
-
}
|
|
1243
|
-
return utils.getResponseKeyFromInfo(info);
|
|
1244
|
-
}
|
|
1245
|
-
function getReturnType$1(info) {
|
|
1246
|
-
if (info == null) {
|
|
1247
|
-
throw new Error("Return type cannot be inferred without a source schema.");
|
|
1248
|
-
}
|
|
1249
|
-
return info.returnType;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
var Transformer = /** @class */ (function () {
|
|
1253
|
-
function Transformer(context) {
|
|
1254
|
-
var e_1, _a;
|
|
1255
|
-
this.transformations = [];
|
|
1256
|
-
this.delegationContext = context;
|
|
1257
|
-
var transforms = context.transforms;
|
|
1258
|
-
var delegationTransforms = transforms.slice().reverse();
|
|
1259
|
-
try {
|
|
1260
|
-
for (var delegationTransforms_1 = tslib.__values(delegationTransforms), delegationTransforms_1_1 = delegationTransforms_1.next(); !delegationTransforms_1_1.done; delegationTransforms_1_1 = delegationTransforms_1.next()) {
|
|
1261
|
-
var transform = delegationTransforms_1_1.value;
|
|
1262
|
-
this.addTransform(transform, {});
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1266
|
-
finally {
|
|
1267
|
-
try {
|
|
1268
|
-
if (delegationTransforms_1_1 && !delegationTransforms_1_1.done && (_a = delegationTransforms_1.return)) _a.call(delegationTransforms_1);
|
|
1269
|
-
}
|
|
1270
|
-
finally { if (e_1) throw e_1.error; }
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
Transformer.prototype.addTransform = function (transform, context) {
|
|
1274
|
-
if (context === void 0) { context = {}; }
|
|
1275
|
-
this.transformations.push({ transform: transform, context: context });
|
|
1276
|
-
};
|
|
1277
|
-
Transformer.prototype.transformRequest = function (originalRequest) {
|
|
1278
|
-
var e_2, _a;
|
|
1279
|
-
var _b;
|
|
1280
|
-
var request = tslib.__assign(tslib.__assign({}, originalRequest), { document: prepareGatewayDocument(originalRequest.document, this.delegationContext.transformedSchema, this.delegationContext.returnType, (_b = this.delegationContext.info) === null || _b === void 0 ? void 0 : _b.schema) });
|
|
1281
|
-
try {
|
|
1282
|
-
for (var _c = tslib.__values(this.transformations), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1283
|
-
var transformation = _d.value;
|
|
1284
|
-
if (transformation.transform.transformRequest) {
|
|
1285
|
-
request = transformation.transform.transformRequest(request, this.delegationContext, transformation.context);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1290
|
-
finally {
|
|
1291
|
-
try {
|
|
1292
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1293
|
-
}
|
|
1294
|
-
finally { if (e_2) throw e_2.error; }
|
|
1295
|
-
}
|
|
1296
|
-
return finalizeGatewayRequest(request, this.delegationContext);
|
|
1297
|
-
};
|
|
1298
|
-
Transformer.prototype.transformResult = function (originalResult) {
|
|
1299
|
-
var result = originalResult;
|
|
1300
|
-
// from rigth to left
|
|
1301
|
-
for (var i = this.transformations.length - 1; i >= 0; i--) {
|
|
1302
|
-
var transformation = this.transformations[i];
|
|
1303
|
-
if (transformation.transform.transformResult) {
|
|
1304
|
-
result = transformation.transform.transformResult(result, this.delegationContext, transformation.context);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
return checkResultAndHandleErrors(result, this.delegationContext);
|
|
1308
|
-
};
|
|
1309
|
-
return Transformer;
|
|
1310
|
-
}());
|
|
1311
|
-
|
|
1312
|
-
function getDelegatingOperation(parentType, schema) {
|
|
1313
|
-
if (parentType === schema.getMutationType()) {
|
|
1314
|
-
return 'mutation';
|
|
1315
|
-
}
|
|
1316
|
-
else if (parentType === schema.getSubscriptionType()) {
|
|
1317
|
-
return 'subscription';
|
|
1318
|
-
}
|
|
1319
|
-
return 'query';
|
|
1320
|
-
}
|
|
1321
|
-
function createRequestFromInfo(_a) {
|
|
1322
|
-
var info = _a.info, rootValue = _a.rootValue, operationName = _a.operationName, _b = _a.operation, operation = _b === void 0 ? getDelegatingOperation(info.parentType, info.schema) : _b, _c = _a.fieldName, fieldName = _c === void 0 ? info.fieldName : _c, selectionSet = _a.selectionSet, _d = _a.fieldNodes, fieldNodes = _d === void 0 ? info.fieldNodes : _d, context = _a.context;
|
|
1323
|
-
return createRequest({
|
|
1324
|
-
sourceSchema: info.schema,
|
|
1325
|
-
sourceParentType: info.parentType,
|
|
1326
|
-
sourceFieldName: info.fieldName,
|
|
1327
|
-
fragments: info.fragments,
|
|
1328
|
-
variableDefinitions: info.operation.variableDefinitions,
|
|
1329
|
-
variableValues: info.variableValues,
|
|
1330
|
-
targetRootValue: rootValue,
|
|
1331
|
-
targetOperationName: operationName,
|
|
1332
|
-
targetOperation: operation,
|
|
1333
|
-
targetFieldName: fieldName,
|
|
1334
|
-
selectionSet: selectionSet,
|
|
1335
|
-
fieldNodes: fieldNodes,
|
|
1336
|
-
context: context,
|
|
1337
|
-
info: info,
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
function createRequest(_a) {
|
|
1341
|
-
var e_1, _b, e_2, _c, e_3, _d, e_4, _e;
|
|
1342
|
-
var _f, _g;
|
|
1343
|
-
var sourceSchema = _a.sourceSchema, sourceParentType = _a.sourceParentType, sourceFieldName = _a.sourceFieldName, fragments = _a.fragments, variableDefinitions = _a.variableDefinitions, variableValues = _a.variableValues, targetRootValue = _a.targetRootValue, targetOperationName = _a.targetOperationName, targetOperation = _a.targetOperation, targetFieldName = _a.targetFieldName, selectionSet = _a.selectionSet, fieldNodes = _a.fieldNodes, context = _a.context, info = _a.info;
|
|
1344
|
-
var newSelectionSet;
|
|
1345
|
-
var argumentNodeMap = Object.create(null);
|
|
1346
|
-
if (selectionSet != null) {
|
|
1347
|
-
newSelectionSet = selectionSet;
|
|
1348
|
-
}
|
|
1349
|
-
else {
|
|
1350
|
-
var selections = [];
|
|
1351
|
-
try {
|
|
1352
|
-
for (var _h = tslib.__values(fieldNodes || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1353
|
-
var fieldNode = _j.value;
|
|
1354
|
-
if (fieldNode.selectionSet) {
|
|
1355
|
-
try {
|
|
1356
|
-
for (var _k = (e_2 = void 0, tslib.__values(fieldNode.selectionSet.selections)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1357
|
-
var selection = _l.value;
|
|
1358
|
-
selections.push(selection);
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1362
|
-
finally {
|
|
1363
|
-
try {
|
|
1364
|
-
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
1365
|
-
}
|
|
1366
|
-
finally { if (e_2) throw e_2.error; }
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1372
|
-
finally {
|
|
1373
|
-
try {
|
|
1374
|
-
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
1375
|
-
}
|
|
1376
|
-
finally { if (e_1) throw e_1.error; }
|
|
1377
|
-
}
|
|
1378
|
-
newSelectionSet = selections.length
|
|
1379
|
-
? {
|
|
1380
|
-
kind: graphql.Kind.SELECTION_SET,
|
|
1381
|
-
selections: selections,
|
|
1382
|
-
}
|
|
1383
|
-
: undefined;
|
|
1384
|
-
var args = (_f = fieldNodes === null || fieldNodes === void 0 ? void 0 : fieldNodes[0]) === null || _f === void 0 ? void 0 : _f.arguments;
|
|
1385
|
-
if (args) {
|
|
1386
|
-
try {
|
|
1387
|
-
for (var args_1 = tslib.__values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
1388
|
-
var argNode = args_1_1.value;
|
|
1389
|
-
argumentNodeMap[argNode.name.value] = argNode;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1393
|
-
finally {
|
|
1394
|
-
try {
|
|
1395
|
-
if (args_1_1 && !args_1_1.done && (_d = args_1.return)) _d.call(args_1);
|
|
1396
|
-
}
|
|
1397
|
-
finally { if (e_3) throw e_3.error; }
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
var newVariables = Object.create(null);
|
|
1402
|
-
var variableDefinitionMap = Object.create(null);
|
|
1403
|
-
if (sourceSchema != null && variableDefinitions != null) {
|
|
1404
|
-
try {
|
|
1405
|
-
for (var variableDefinitions_1 = tslib.__values(variableDefinitions), variableDefinitions_1_1 = variableDefinitions_1.next(); !variableDefinitions_1_1.done; variableDefinitions_1_1 = variableDefinitions_1.next()) {
|
|
1406
|
-
var def = variableDefinitions_1_1.value;
|
|
1407
|
-
var varName = def.variable.name.value;
|
|
1408
|
-
variableDefinitionMap[varName] = def;
|
|
1409
|
-
var varType = graphql.typeFromAST(sourceSchema, def.type);
|
|
1410
|
-
var serializedValue = utils.serializeInputValue(varType, variableValues === null || variableValues === void 0 ? void 0 : variableValues[varName]);
|
|
1411
|
-
if (serializedValue !== undefined) {
|
|
1412
|
-
newVariables[varName] = serializedValue;
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1417
|
-
finally {
|
|
1418
|
-
try {
|
|
1419
|
-
if (variableDefinitions_1_1 && !variableDefinitions_1_1.done && (_e = variableDefinitions_1.return)) _e.call(variableDefinitions_1);
|
|
1420
|
-
}
|
|
1421
|
-
finally { if (e_4) throw e_4.error; }
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
if (sourceParentType != null && sourceFieldName != null) {
|
|
1425
|
-
updateArgumentsWithDefaults(sourceParentType, sourceFieldName, argumentNodeMap, variableDefinitionMap, newVariables);
|
|
1426
|
-
}
|
|
1427
|
-
var rootFieldName = targetFieldName !== null && targetFieldName !== void 0 ? targetFieldName : (_g = fieldNodes === null || fieldNodes === void 0 ? void 0 : fieldNodes[0]) === null || _g === void 0 ? void 0 : _g.name.value;
|
|
1428
|
-
if (rootFieldName === undefined) {
|
|
1429
|
-
throw new Error("Either \"targetFieldName\" or a non empty \"fieldNodes\" array must be provided.");
|
|
1430
|
-
}
|
|
1431
|
-
var rootfieldNode = {
|
|
1432
|
-
kind: graphql.Kind.FIELD,
|
|
1433
|
-
arguments: Object.values(argumentNodeMap),
|
|
1434
|
-
name: {
|
|
1435
|
-
kind: graphql.Kind.NAME,
|
|
1436
|
-
value: rootFieldName,
|
|
1437
|
-
},
|
|
1438
|
-
selectionSet: newSelectionSet,
|
|
1439
|
-
};
|
|
1440
|
-
var operationName = targetOperationName
|
|
1441
|
-
? {
|
|
1442
|
-
kind: graphql.Kind.NAME,
|
|
1443
|
-
value: targetOperationName,
|
|
1444
|
-
}
|
|
1445
|
-
: undefined;
|
|
1446
|
-
var operationDefinition = {
|
|
1447
|
-
kind: graphql.Kind.OPERATION_DEFINITION,
|
|
1448
|
-
name: operationName,
|
|
1449
|
-
operation: targetOperation,
|
|
1450
|
-
variableDefinitions: Object.values(variableDefinitionMap),
|
|
1451
|
-
selectionSet: {
|
|
1452
|
-
kind: graphql.Kind.SELECTION_SET,
|
|
1453
|
-
selections: [rootfieldNode],
|
|
1454
|
-
},
|
|
1455
|
-
};
|
|
1456
|
-
var definitions = [operationDefinition];
|
|
1457
|
-
if (fragments != null) {
|
|
1458
|
-
for (var fragmentName in fragments) {
|
|
1459
|
-
var fragment = fragments[fragmentName];
|
|
1460
|
-
definitions.push(fragment);
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
var document = {
|
|
1464
|
-
kind: graphql.Kind.DOCUMENT,
|
|
1465
|
-
definitions: definitions,
|
|
1466
|
-
};
|
|
1467
|
-
return {
|
|
1468
|
-
document: document,
|
|
1469
|
-
variables: newVariables,
|
|
1470
|
-
rootValue: targetRootValue,
|
|
1471
|
-
operationName: targetOperationName,
|
|
1472
|
-
operationType: targetOperation,
|
|
1473
|
-
context: context,
|
|
1474
|
-
info: info,
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1477
|
-
function updateArgumentsWithDefaults(sourceParentType, sourceFieldName, argumentNodeMap, variableDefinitionMap, variableValues) {
|
|
1478
|
-
var e_5, _a;
|
|
1479
|
-
var generateVariableName = utils.createVariableNameGenerator(variableDefinitionMap);
|
|
1480
|
-
var sourceField = sourceParentType.getFields()[sourceFieldName];
|
|
1481
|
-
try {
|
|
1482
|
-
for (var _b = tslib.__values(sourceField.args), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1483
|
-
var argument = _c.value;
|
|
1484
|
-
var argName = argument.name;
|
|
1485
|
-
var sourceArgType = argument.type;
|
|
1486
|
-
if (argumentNodeMap[argName] === undefined) {
|
|
1487
|
-
var defaultValue = argument.defaultValue;
|
|
1488
|
-
if (defaultValue !== undefined) {
|
|
1489
|
-
utils.updateArgument(argumentNodeMap, variableDefinitionMap, variableValues, argName, generateVariableName(argName), sourceArgType, utils.serializeInputValue(sourceArgType, defaultValue));
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1495
|
-
finally {
|
|
1496
|
-
try {
|
|
1497
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1498
|
-
}
|
|
1499
|
-
finally { if (e_5) throw e_5.error; }
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
/**
|
|
1504
|
-
* Resolver that knows how to:
|
|
1505
|
-
* a) handle aliases for proxied schemas
|
|
1506
|
-
* b) handle errors from proxied schemas
|
|
1507
|
-
* c) handle external to internal enum conversion
|
|
1508
|
-
*/
|
|
1509
|
-
function defaultMergedResolver(parent, args, context, info) {
|
|
1510
|
-
if (!parent) {
|
|
1511
|
-
return null;
|
|
1512
|
-
}
|
|
1513
|
-
var responseKey = utils.getResponseKeyFromInfo(info);
|
|
1514
|
-
// check to see if parent is not a proxied result, i.e. if parent resolver was manually overwritten
|
|
1515
|
-
// See https://github.com/ardatan/graphql-tools/issues/967
|
|
1516
|
-
if (!isExternalObject(parent)) {
|
|
1517
|
-
return graphql.defaultFieldResolver(parent, args, context, info);
|
|
1518
|
-
}
|
|
1519
|
-
var data = parent[responseKey];
|
|
1520
|
-
var unpathedErrors = getUnpathedErrors(parent);
|
|
1521
|
-
var subschema = getSubschema(parent, responseKey);
|
|
1522
|
-
return resolveExternalValue(data, unpathedErrors, subschema, context, info);
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
function isSubschemaConfig(value) {
|
|
1526
|
-
return Boolean(value === null || value === void 0 ? void 0 : value.schema);
|
|
1527
|
-
}
|
|
1528
|
-
function cloneSubschemaConfig(subschemaConfig) {
|
|
1529
|
-
var _a, _b;
|
|
1530
|
-
var newSubschemaConfig = tslib.__assign(tslib.__assign({}, subschemaConfig), { transforms: subschemaConfig.transforms != null ? tslib.__spreadArray([], tslib.__read(subschemaConfig.transforms), false) : undefined });
|
|
1531
|
-
if (newSubschemaConfig.merge != null) {
|
|
1532
|
-
newSubschemaConfig.merge = tslib.__assign({}, subschemaConfig.merge);
|
|
1533
|
-
for (var typeName in newSubschemaConfig.merge) {
|
|
1534
|
-
var mergedTypeConfig = (newSubschemaConfig.merge[typeName] = tslib.__assign({}, ((_b = (_a = subschemaConfig.merge) === null || _a === void 0 ? void 0 : _a[typeName]) !== null && _b !== void 0 ? _b : {})));
|
|
1535
|
-
if (mergedTypeConfig.entryPoints != null) {
|
|
1536
|
-
mergedTypeConfig.entryPoints = mergedTypeConfig.entryPoints.map(function (entryPoint) { return (tslib.__assign({}, entryPoint)); });
|
|
1537
|
-
}
|
|
1538
|
-
if (mergedTypeConfig.fields != null) {
|
|
1539
|
-
var fields = (mergedTypeConfig.fields = tslib.__assign({}, mergedTypeConfig.fields));
|
|
1540
|
-
for (var fieldName in fields) {
|
|
1541
|
-
fields[fieldName] = tslib.__assign({}, fields[fieldName]);
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
return newSubschemaConfig;
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
function delegateToSchema(options) {
|
|
1550
|
-
var info = options.info, schema = options.schema, rootValue = options.rootValue, operationName = options.operationName, _a = options.operation, operation = _a === void 0 ? getDelegatingOperation(info.parentType, info.schema) : _a, _b = options.fieldName, fieldName = _b === void 0 ? info.fieldName : _b, selectionSet = options.selectionSet, fieldNodes = options.fieldNodes, context = options.context;
|
|
1551
|
-
var request = createRequestFromInfo({
|
|
1552
|
-
info: info,
|
|
1553
|
-
operation: operation,
|
|
1554
|
-
fieldName: fieldName,
|
|
1555
|
-
selectionSet: selectionSet,
|
|
1556
|
-
fieldNodes: fieldNodes,
|
|
1557
|
-
rootValue: rootValue !== null && rootValue !== void 0 ? rootValue : schema.rootValue,
|
|
1558
|
-
operationName: operationName,
|
|
1559
|
-
context: context,
|
|
1560
|
-
});
|
|
1561
|
-
return delegateRequest(tslib.__assign(tslib.__assign({}, options), { request: request }));
|
|
1562
|
-
}
|
|
1563
|
-
function getDelegationReturnType(targetSchema, operation, fieldName) {
|
|
1564
|
-
var rootType = utils.getDefinedRootType(targetSchema, operation);
|
|
1565
|
-
return rootType.getFields()[fieldName].type;
|
|
1566
|
-
}
|
|
1567
|
-
function delegateRequest(options) {
|
|
1568
|
-
var delegationContext = getDelegationContext(options);
|
|
1569
|
-
var transformer = new Transformer(delegationContext);
|
|
1570
|
-
var processedRequest = transformer.transformRequest(options.request);
|
|
1571
|
-
if (options.validateRequest) {
|
|
1572
|
-
validateRequest(delegationContext, processedRequest.document);
|
|
1573
|
-
}
|
|
1574
|
-
var executor = getExecutor(delegationContext);
|
|
1575
|
-
return new valueOrPromise.ValueOrPromise(function () { return executor(processedRequest); })
|
|
1576
|
-
.then(function (originalResult) {
|
|
1577
|
-
if (utils.isAsyncIterable(originalResult)) {
|
|
1578
|
-
// "subscribe" to the subscription result and map the result through the transforms
|
|
1579
|
-
return utils.mapAsyncIterator(originalResult, function (result) { return transformer.transformResult(result); });
|
|
1580
|
-
}
|
|
1581
|
-
return transformer.transformResult(originalResult);
|
|
1582
|
-
})
|
|
1583
|
-
.resolve();
|
|
1584
|
-
}
|
|
1585
|
-
function getDelegationContext(_a) {
|
|
1586
|
-
var _b, _c, _d, _e;
|
|
1587
|
-
var request = _a.request, schema = _a.schema, fieldName = _a.fieldName, returnType = _a.returnType, args = _a.args, info = _a.info, _f = _a.transforms, transforms = _f === void 0 ? [] : _f, transformedSchema = _a.transformedSchema, _g = _a.skipTypeMerging, skipTypeMerging = _g === void 0 ? false : _g;
|
|
1588
|
-
var operation = request.operationType, context = request.context, operationName = request.operationName, document = request.document;
|
|
1589
|
-
var operationDefinition;
|
|
1590
|
-
var targetFieldName;
|
|
1591
|
-
if (fieldName == null) {
|
|
1592
|
-
operationDefinition = graphql.getOperationAST(document, operationName);
|
|
1593
|
-
if (operationDefinition == null) {
|
|
1594
|
-
throw new Error('Cannot infer main operation from the provided document.');
|
|
1595
|
-
}
|
|
1596
|
-
targetFieldName = (operationDefinition === null || operationDefinition === void 0 ? void 0 : operationDefinition.selectionSet.selections[0]).name.value;
|
|
1597
|
-
}
|
|
1598
|
-
else {
|
|
1599
|
-
targetFieldName = fieldName;
|
|
1600
|
-
}
|
|
1601
|
-
var stitchingInfo = (_b = info === null || info === void 0 ? void 0 : info.schema.extensions) === null || _b === void 0 ? void 0 : _b['stitchingInfo'];
|
|
1602
|
-
var subschemaOrSubschemaConfig = (_c = stitchingInfo === null || stitchingInfo === void 0 ? void 0 : stitchingInfo.subschemaMap.get(schema)) !== null && _c !== void 0 ? _c : schema;
|
|
1603
|
-
if (isSubschemaConfig(subschemaOrSubschemaConfig)) {
|
|
1604
|
-
var targetSchema = subschemaOrSubschemaConfig.schema;
|
|
1605
|
-
return {
|
|
1606
|
-
subschema: schema,
|
|
1607
|
-
subschemaConfig: subschemaOrSubschemaConfig,
|
|
1608
|
-
targetSchema: targetSchema,
|
|
1609
|
-
operation: operation,
|
|
1610
|
-
fieldName: targetFieldName,
|
|
1611
|
-
args: args,
|
|
1612
|
-
context: context,
|
|
1613
|
-
info: info,
|
|
1614
|
-
returnType: (_d = returnType !== null && returnType !== void 0 ? returnType : info === null || info === void 0 ? void 0 : info.returnType) !== null && _d !== void 0 ? _d : getDelegationReturnType(targetSchema, operation, targetFieldName),
|
|
1615
|
-
transforms: subschemaOrSubschemaConfig.transforms != null
|
|
1616
|
-
? subschemaOrSubschemaConfig.transforms.concat(transforms)
|
|
1617
|
-
: transforms,
|
|
1618
|
-
transformedSchema: transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : (subschemaOrSubschemaConfig instanceof Subschema ? subschemaOrSubschemaConfig.transformedSchema : targetSchema),
|
|
1619
|
-
skipTypeMerging: skipTypeMerging,
|
|
1620
|
-
};
|
|
1621
|
-
}
|
|
1622
|
-
return {
|
|
1623
|
-
subschema: schema,
|
|
1624
|
-
subschemaConfig: undefined,
|
|
1625
|
-
targetSchema: subschemaOrSubschemaConfig,
|
|
1626
|
-
operation: operation,
|
|
1627
|
-
fieldName: targetFieldName,
|
|
1628
|
-
args: args,
|
|
1629
|
-
context: context,
|
|
1630
|
-
info: info,
|
|
1631
|
-
returnType: (_e = returnType !== null && returnType !== void 0 ? returnType : info === null || info === void 0 ? void 0 : info.returnType) !== null && _e !== void 0 ? _e : getDelegationReturnType(subschemaOrSubschemaConfig, operation, targetFieldName),
|
|
1632
|
-
transforms: transforms,
|
|
1633
|
-
transformedSchema: transformedSchema !== null && transformedSchema !== void 0 ? transformedSchema : subschemaOrSubschemaConfig,
|
|
1634
|
-
skipTypeMerging: skipTypeMerging,
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
function validateRequest(delegationContext, document) {
|
|
1638
|
-
var errors = graphql.validate(delegationContext.targetSchema, document);
|
|
1639
|
-
if (errors.length > 0) {
|
|
1640
|
-
if (errors.length > 1) {
|
|
1641
|
-
var combinedError = new utils.AggregateError(errors);
|
|
1642
|
-
throw combinedError;
|
|
1643
|
-
}
|
|
1644
|
-
var error = errors[0];
|
|
1645
|
-
throw error.originalError || error;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
function getExecutor(delegationContext) {
|
|
1649
|
-
var _a, _b;
|
|
1650
|
-
var subschemaConfig = delegationContext.subschemaConfig, targetSchema = delegationContext.targetSchema, context = delegationContext.context;
|
|
1651
|
-
var executor = (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.executor) || createDefaultExecutor(targetSchema);
|
|
1652
|
-
if (subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batch) {
|
|
1653
|
-
var batchingOptions = subschemaConfig === null || subschemaConfig === void 0 ? void 0 : subschemaConfig.batchingOptions;
|
|
1654
|
-
executor = batchExecute.getBatchingExecutor((_b = (_a = context !== null && context !== void 0 ? context : globalThis) !== null && _a !== void 0 ? _a : window) !== null && _b !== void 0 ? _b : global, executor, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.dataLoaderOptions, batchingOptions === null || batchingOptions === void 0 ? void 0 : batchingOptions.extensionsReducer);
|
|
1655
|
-
}
|
|
1656
|
-
return executor;
|
|
1657
|
-
}
|
|
1658
|
-
var createDefaultExecutor = utils.memoize1(function createDefaultExecutor(schema) {
|
|
1659
|
-
return function defaultExecutor(_a) {
|
|
1660
|
-
var document = _a.document, context = _a.context, variables = _a.variables, rootValue = _a.rootValue, operationName = _a.operationName, operationType = _a.operationType;
|
|
1661
|
-
var executionArgs = {
|
|
1662
|
-
schema: schema,
|
|
1663
|
-
document: document,
|
|
1664
|
-
contextValue: context,
|
|
1665
|
-
variableValues: variables,
|
|
1666
|
-
rootValue: rootValue,
|
|
1667
|
-
operationName: operationName,
|
|
1668
|
-
};
|
|
1669
|
-
if (operationType === 'subscription') {
|
|
1670
|
-
return graphql.subscribe(executionArgs);
|
|
1671
|
-
}
|
|
1672
|
-
return graphql.execute(executionArgs);
|
|
1673
|
-
};
|
|
1674
|
-
});
|
|
1675
|
-
|
|
1676
|
-
exports.Subschema = Subschema;
|
|
1677
|
-
exports.Transformer = Transformer;
|
|
1678
|
-
exports.annotateExternalObject = annotateExternalObject;
|
|
1679
|
-
exports.applySchemaTransforms = applySchemaTransforms;
|
|
1680
|
-
exports.cloneSubschemaConfig = cloneSubschemaConfig;
|
|
1681
|
-
exports.createDefaultExecutor = createDefaultExecutor;
|
|
1682
|
-
exports.createRequest = createRequest;
|
|
1683
|
-
exports.createRequestFromInfo = createRequestFromInfo;
|
|
1684
|
-
exports.defaultMergedResolver = defaultMergedResolver;
|
|
1685
|
-
exports.delegateRequest = delegateRequest;
|
|
1686
|
-
exports.delegateToSchema = delegateToSchema;
|
|
1687
|
-
exports.getDelegatingOperation = getDelegatingOperation;
|
|
1688
|
-
exports.getSubschema = getSubschema;
|
|
1689
|
-
exports.getUnpathedErrors = getUnpathedErrors;
|
|
1690
|
-
exports.isExternalObject = isExternalObject;
|
|
1691
|
-
exports.isSubschema = isSubschema;
|
|
1692
|
-
exports.isSubschemaConfig = isSubschemaConfig;
|
|
1693
|
-
exports.mergeFields = mergeFields;
|
|
1694
|
-
exports.resolveExternalValue = resolveExternalValue;
|