@graphql-tools/utils 8.2.0-alpha-aa385bc9.0 → 8.2.3

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 (59) hide show
  1. package/comments.d.ts +3 -1
  2. package/fixSchemaAst.d.ts +3 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +53 -23
  5. package/index.mjs +53 -25
  6. package/package.json +1 -1
  7. package/es5/AggregateError.d.ts +0 -10
  8. package/es5/Interfaces.d.ts +0 -242
  9. package/es5/addTypes.d.ts +0 -2
  10. package/es5/astFromType.d.ts +0 -2
  11. package/es5/astFromValueUntyped.d.ts +0 -17
  12. package/es5/build-operation-for-field.d.ts +0 -18
  13. package/es5/collectFields.d.ts +0 -5
  14. package/es5/comments.d.ts +0 -28
  15. package/es5/errors.d.ts +0 -2
  16. package/es5/executor.d.ts +0 -7
  17. package/es5/fields.d.ts +0 -5
  18. package/es5/filterSchema.d.ts +0 -12
  19. package/es5/forEachDefaultValue.d.ts +0 -3
  20. package/es5/forEachField.d.ts +0 -3
  21. package/es5/get-directives.d.ts +0 -11
  22. package/es5/get-fields-with-directives.d.ts +0 -16
  23. package/es5/get-implementing-types.d.ts +0 -2
  24. package/es5/getArgumentValues.d.ts +0 -10
  25. package/es5/getObjectTypeFromTypeMap.d.ts +0 -3
  26. package/es5/getResolversFromSchema.d.ts +0 -3
  27. package/es5/getResponseKeyFromInfo.d.ts +0 -7
  28. package/es5/heal.d.ts +0 -3
  29. package/es5/helpers.d.ts +0 -9
  30. package/es5/implementsAbstractType.d.ts +0 -3
  31. package/es5/index.d.ts +0 -48
  32. package/es5/index.js +0 -4818
  33. package/es5/index.mjs +0 -4712
  34. package/es5/inspect.d.ts +0 -4
  35. package/es5/isAsyncIterable.d.ts +0 -1
  36. package/es5/isDocumentNode.d.ts +0 -2
  37. package/es5/loaders.d.ts +0 -18
  38. package/es5/mapAsyncIterator.d.ts +0 -5
  39. package/es5/mapSchema.d.ts +0 -7
  40. package/es5/memoize.d.ts +0 -6
  41. package/es5/mergeDeep.d.ts +0 -9
  42. package/es5/observableToAsyncIterable.d.ts +0 -12
  43. package/es5/package.json +0 -35
  44. package/es5/parse-graphql-json.d.ts +0 -4
  45. package/es5/parse-graphql-sdl.d.ts +0 -13
  46. package/es5/print-schema-with-directives.d.ts +0 -21
  47. package/es5/prune.d.ts +0 -8
  48. package/es5/renameType.d.ts +0 -8
  49. package/es5/rewire.d.ts +0 -5
  50. package/es5/rootTypes.d.ts +0 -5
  51. package/es5/selectionSets.d.ts +0 -3
  52. package/es5/stub.d.ts +0 -9
  53. package/es5/transformInputValue.d.ts +0 -6
  54. package/es5/types.d.ts +0 -49
  55. package/es5/updateArgument.d.ts +0 -3
  56. package/es5/validate-documents.d.ts +0 -9
  57. package/es5/valueMatchesCriteria.d.ts +0 -1
  58. package/es5/visitResult.d.ts +0 -15
  59. package/es5/withCancel.d.ts +0 -3
package/es5/index.mjs DELETED
@@ -1,4712 +0,0 @@
1
- import { parse, isNonNullType, GraphQLError, Kind, valueFromAST, print, isObjectType, isListType, isSpecifiedDirective, astFromValue, isSpecifiedScalarType, isIntrospectionType, isInterfaceType, isUnionType, isInputObjectType, isEnumType, isScalarType, GraphQLDeprecatedDirective, specifiedRules, concatAST, validate, buildClientSchema, visit, TokenKind, Source, isTypeSystemDefinitionNode, getNamedType, GraphQLString, GraphQLNonNull, GraphQLList, GraphQLID, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLObjectType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLDirective, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, isNamedType, getNullableType, isLeafType, GraphQLSchema, isDirective, isCompositeType, doTypesOverlap, getDirectiveValues, GraphQLSkipDirective, GraphQLIncludeDirective, typeFromAST, isAbstractType, getOperationAST, getOperationRootType, TypeNameMetaFieldDef } from 'graphql';
2
- import { __spreadArray, __read, __assign, __values, __extends, __awaiter, __generator } from 'tslib';
3
-
4
- var asArray = function (fns) { return (Array.isArray(fns) ? fns : fns ? [fns] : []); };
5
- var invalidDocRegex = /\.[a-z0-9]+$/i;
6
- function isDocumentString(str) {
7
- if (typeof str !== 'string') {
8
- return false;
9
- }
10
- // XXX: is-valid-path or is-glob treat SDL as a valid path
11
- // (`scalar Date` for example)
12
- // this why checking the extension is fast enough
13
- // and prevent from parsing the string in order to find out
14
- // if the string is a SDL
15
- if (invalidDocRegex.test(str)) {
16
- return false;
17
- }
18
- try {
19
- parse(str);
20
- return true;
21
- }
22
- catch (e) { }
23
- return false;
24
- }
25
- var invalidPathRegex = /[‘“!%&^<=>`]/;
26
- function isValidPath(str) {
27
- return typeof str === 'string' && !invalidPathRegex.test(str);
28
- }
29
- function compareStrings(a, b) {
30
- if (String(a) < String(b)) {
31
- return -1;
32
- }
33
- if (String(a) > String(b)) {
34
- return 1;
35
- }
36
- return 0;
37
- }
38
- function nodeToString(a) {
39
- var _a, _b;
40
- var name;
41
- if ('alias' in a) {
42
- name = (_a = a.alias) === null || _a === void 0 ? void 0 : _a.value;
43
- }
44
- if (name == null && 'name' in a) {
45
- name = (_b = a.name) === null || _b === void 0 ? void 0 : _b.value;
46
- }
47
- if (name == null) {
48
- name = a.kind;
49
- }
50
- return name;
51
- }
52
- function compareNodes(a, b, customFn) {
53
- var aStr = nodeToString(a);
54
- var bStr = nodeToString(b);
55
- if (typeof customFn === 'function') {
56
- return customFn(aStr, bStr);
57
- }
58
- return compareStrings(aStr, bStr);
59
- }
60
- function isSome(input) {
61
- return input != null;
62
- }
63
- function assertSome(input, message) {
64
- if (message === void 0) { message = 'Value should be something'; }
65
- if (input == null) {
66
- throw new Error(message);
67
- }
68
- }
69
-
70
- // Taken from graphql-js
71
- // https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
72
- /* eslint-disable @typescript-eslint/ban-types */
73
- var MAX_ARRAY_LENGTH = 10;
74
- var MAX_RECURSIVE_DEPTH = 2;
75
- /**
76
- * Used to print values in error messages.
77
- */
78
- function inspect(value) {
79
- return formatValue(value, []);
80
- }
81
- function formatValue(value, seenValues) {
82
- switch (typeof value) {
83
- case 'string':
84
- return JSON.stringify(value);
85
- case 'function':
86
- return value.name ? "[function " + value.name + "]" : '[function]';
87
- case 'object':
88
- return formatObjectValue(value, seenValues);
89
- default:
90
- return String(value);
91
- }
92
- }
93
- function formatObjectValue(value, previouslySeenValues) {
94
- if (value === null) {
95
- return 'null';
96
- }
97
- if (previouslySeenValues.includes(value)) {
98
- return '[Circular]';
99
- }
100
- var seenValues = __spreadArray(__spreadArray([], __read(previouslySeenValues), false), [value], false);
101
- if (isJSONable(value)) {
102
- var jsonValue = value.toJSON();
103
- // check for infinite recursion
104
- if (jsonValue !== value) {
105
- return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
106
- }
107
- }
108
- else if (Array.isArray(value)) {
109
- return formatArray(value, seenValues);
110
- }
111
- return formatObject(value, seenValues);
112
- }
113
- function isJSONable(value) {
114
- return typeof value.toJSON === 'function';
115
- }
116
- function formatObject(object, seenValues) {
117
- var entries = Object.entries(object);
118
- if (entries.length === 0) {
119
- return '{}';
120
- }
121
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
122
- return '[' + getObjectTag(object) + ']';
123
- }
124
- var properties = entries.map(function (_a) {
125
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
126
- return key + ': ' + formatValue(value, seenValues);
127
- });
128
- return '{ ' + properties.join(', ') + ' }';
129
- }
130
- function formatArray(array, seenValues) {
131
- if (array.length === 0) {
132
- return '[]';
133
- }
134
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
135
- return '[Array]';
136
- }
137
- var len = Math.min(MAX_ARRAY_LENGTH, array.length);
138
- var remaining = array.length - len;
139
- var items = [];
140
- for (var i = 0; i < len; ++i) {
141
- items.push(formatValue(array[i], seenValues));
142
- }
143
- if (remaining === 1) {
144
- items.push('... 1 more item');
145
- }
146
- else if (remaining > 1) {
147
- items.push("... " + remaining + " more items");
148
- }
149
- return '[' + items.join(', ') + ']';
150
- }
151
- function getObjectTag(object) {
152
- var tag = Object.prototype.toString
153
- .call(object)
154
- .replace(/^\[object /, '')
155
- .replace(/]$/, '');
156
- if (tag === 'Object' && typeof object.constructor === 'function') {
157
- var name_1 = object.constructor.name;
158
- if (typeof name_1 === 'string' && name_1 !== '') {
159
- return name_1;
160
- }
161
- }
162
- return tag;
163
- }
164
-
165
- /**
166
- * Prepares an object map of argument values given a list of argument
167
- * definitions and list of argument AST nodes.
168
- *
169
- * Note: The returned value is a plain Object with a prototype, since it is
170
- * exposed to user code. Care should be taken to not pull values from the
171
- * Object prototype.
172
- */
173
- function getArgumentValues(def, node, variableValues) {
174
- var e_1, _a;
175
- var _b;
176
- if (variableValues === void 0) { variableValues = {}; }
177
- var variableMap = Object.entries(variableValues).reduce(function (prev, _a) {
178
- var _b;
179
- var _c = __read(_a, 2), key = _c[0], value = _c[1];
180
- return (__assign(__assign({}, prev), (_b = {}, _b[key] = value, _b)));
181
- }, {});
182
- var coercedValues = {};
183
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
184
- var argumentNodes = (_b = node.arguments) !== null && _b !== void 0 ? _b : [];
185
- var argNodeMap = argumentNodes.reduce(function (prev, arg) {
186
- var _a;
187
- return (__assign(__assign({}, prev), (_a = {}, _a[arg.name.value] = arg, _a)));
188
- }, {});
189
- try {
190
- for (var _c = __values(def.args), _d = _c.next(); !_d.done; _d = _c.next()) {
191
- var _e = _d.value, name_1 = _e.name, argType = _e.type, defaultValue = _e.defaultValue;
192
- var argumentNode = argNodeMap[name_1];
193
- if (!argumentNode) {
194
- if (defaultValue !== undefined) {
195
- coercedValues[name_1] = defaultValue;
196
- }
197
- else if (isNonNullType(argType)) {
198
- throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " + 'was not provided.', node);
199
- }
200
- continue;
201
- }
202
- var valueNode = argumentNode.value;
203
- var isNull = valueNode.kind === Kind.NULL;
204
- if (valueNode.kind === Kind.VARIABLE) {
205
- var variableName = valueNode.name.value;
206
- if (variableValues == null || !variableMap[variableName]) {
207
- if (defaultValue !== undefined) {
208
- coercedValues[name_1] = defaultValue;
209
- }
210
- else if (isNonNullType(argType)) {
211
- throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " +
212
- ("was provided the variable \"$" + variableName + "\" which was not provided a runtime value."), valueNode);
213
- }
214
- continue;
215
- }
216
- isNull = variableValues[variableName] == null;
217
- }
218
- if (isNull && isNonNullType(argType)) {
219
- throw new GraphQLError("Argument \"" + name_1 + "\" of non-null type \"" + inspect(argType) + "\" " + 'must not be null.', valueNode);
220
- }
221
- var coercedValue = valueFromAST(valueNode, argType, variableValues);
222
- if (coercedValue === undefined) {
223
- // Note: ValuesOfCorrectTypeRule validation should catch this before
224
- // execution. This is a runtime check to ensure execution does not
225
- // continue with an invalid argument value.
226
- throw new GraphQLError("Argument \"" + name_1 + "\" has invalid value " + print(valueNode) + ".", valueNode);
227
- }
228
- coercedValues[name_1] = coercedValue;
229
- }
230
- }
231
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
232
- finally {
233
- try {
234
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
235
- }
236
- finally { if (e_1) throw e_1.error; }
237
- }
238
- return coercedValues;
239
- }
240
-
241
- function getDirectivesInExtensions(node, pathToDirectivesInExtensions) {
242
- if (pathToDirectivesInExtensions === void 0) { pathToDirectivesInExtensions = ['directives']; }
243
- return pathToDirectivesInExtensions.reduce(function (acc, pathSegment) { return (acc == null ? acc : acc[pathSegment]); }, node === null || node === void 0 ? void 0 : node.extensions);
244
- }
245
- function _getDirectiveInExtensions(directivesInExtensions, directiveName) {
246
- var directiveInExtensions = directivesInExtensions.filter(function (directiveAnnotation) { return directiveAnnotation.name === directiveName; });
247
- if (!directiveInExtensions.length) {
248
- return undefined;
249
- }
250
- return directiveInExtensions.map(function (directive) { var _a; return (_a = directive.args) !== null && _a !== void 0 ? _a : {}; });
251
- }
252
- function getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions) {
253
- var e_1, _a, e_2, _b;
254
- if (pathToDirectivesInExtensions === void 0) { pathToDirectivesInExtensions = ['directives']; }
255
- var directivesInExtensions = pathToDirectivesInExtensions.reduce(function (acc, pathSegment) { return (acc == null ? acc : acc[pathSegment]); }, node === null || node === void 0 ? void 0 : node.extensions);
256
- if (directivesInExtensions === undefined) {
257
- return undefined;
258
- }
259
- if (Array.isArray(directivesInExtensions)) {
260
- return _getDirectiveInExtensions(directivesInExtensions, directiveName);
261
- }
262
- // Support condensed format by converting to longer format
263
- // The condensed format does not preserve ordering of directives when repeatable directives are used.
264
- // See https://github.com/ardatan/graphql-tools/issues/2534
265
- var reformattedDirectivesInExtensions = [];
266
- try {
267
- for (var _c = __values(Object.entries(directivesInExtensions)), _d = _c.next(); !_d.done; _d = _c.next()) {
268
- var _e = __read(_d.value, 2), name_1 = _e[0], argsOrArrayOfArgs = _e[1];
269
- if (Array.isArray(argsOrArrayOfArgs)) {
270
- try {
271
- for (var argsOrArrayOfArgs_1 = (e_2 = void 0, __values(argsOrArrayOfArgs)), argsOrArrayOfArgs_1_1 = argsOrArrayOfArgs_1.next(); !argsOrArrayOfArgs_1_1.done; argsOrArrayOfArgs_1_1 = argsOrArrayOfArgs_1.next()) {
272
- var args = argsOrArrayOfArgs_1_1.value;
273
- reformattedDirectivesInExtensions.push({ name: name_1, args: args });
274
- }
275
- }
276
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
277
- finally {
278
- try {
279
- if (argsOrArrayOfArgs_1_1 && !argsOrArrayOfArgs_1_1.done && (_b = argsOrArrayOfArgs_1.return)) _b.call(argsOrArrayOfArgs_1);
280
- }
281
- finally { if (e_2) throw e_2.error; }
282
- }
283
- }
284
- else {
285
- reformattedDirectivesInExtensions.push({ name: name_1, args: argsOrArrayOfArgs });
286
- }
287
- }
288
- }
289
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
290
- finally {
291
- try {
292
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
293
- }
294
- finally { if (e_1) throw e_1.error; }
295
- }
296
- return _getDirectiveInExtensions(reformattedDirectivesInExtensions, directiveName);
297
- }
298
- function getDirectives(schema, node, pathToDirectivesInExtensions) {
299
- var e_3, _a, e_4, _b;
300
- if (pathToDirectivesInExtensions === void 0) { pathToDirectivesInExtensions = ['directives']; }
301
- var directivesInExtensions = getDirectivesInExtensions(node, pathToDirectivesInExtensions);
302
- if (directivesInExtensions != null && directivesInExtensions.length > 0) {
303
- return directivesInExtensions;
304
- }
305
- var schemaDirectives = schema && schema.getDirectives ? schema.getDirectives() : [];
306
- var schemaDirectiveMap = schemaDirectives.reduce(function (schemaDirectiveMap, schemaDirective) {
307
- schemaDirectiveMap[schemaDirective.name] = schemaDirective;
308
- return schemaDirectiveMap;
309
- }, {});
310
- var astNodes = [];
311
- if (node.astNode) {
312
- astNodes.push(node.astNode);
313
- }
314
- if ('extensionASTNodes' in node && node.extensionASTNodes) {
315
- astNodes = __spreadArray(__spreadArray([], __read(astNodes), false), __read(node.extensionASTNodes), false);
316
- }
317
- var result = [];
318
- try {
319
- for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
320
- var astNode = astNodes_1_1.value;
321
- if (astNode.directives) {
322
- try {
323
- for (var _c = (e_4 = void 0, __values(astNode.directives)), _d = _c.next(); !_d.done; _d = _c.next()) {
324
- var directiveNode = _d.value;
325
- var schemaDirective = schemaDirectiveMap[directiveNode.name.value];
326
- if (schemaDirective) {
327
- result.push({ name: directiveNode.name.value, args: getArgumentValues(schemaDirective, directiveNode) });
328
- }
329
- }
330
- }
331
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
332
- finally {
333
- try {
334
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
335
- }
336
- finally { if (e_4) throw e_4.error; }
337
- }
338
- }
339
- }
340
- }
341
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
342
- finally {
343
- try {
344
- if (astNodes_1_1 && !astNodes_1_1.done && (_a = astNodes_1.return)) _a.call(astNodes_1);
345
- }
346
- finally { if (e_3) throw e_3.error; }
347
- }
348
- return result;
349
- }
350
- function getDirective(schema, node, directiveName, pathToDirectivesInExtensions) {
351
- var e_5, _a, e_6, _b;
352
- if (pathToDirectivesInExtensions === void 0) { pathToDirectivesInExtensions = ['directives']; }
353
- var directiveInExtensions = getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions);
354
- if (directiveInExtensions != null) {
355
- return directiveInExtensions;
356
- }
357
- var schemaDirective = schema && schema.getDirective ? schema.getDirective(directiveName) : undefined;
358
- if (schemaDirective == null) {
359
- return undefined;
360
- }
361
- var astNodes = [];
362
- if (node.astNode) {
363
- astNodes.push(node.astNode);
364
- }
365
- if ('extensionASTNodes' in node && node.extensionASTNodes) {
366
- astNodes = __spreadArray(__spreadArray([], __read(astNodes), false), __read(node.extensionASTNodes), false);
367
- }
368
- var result = [];
369
- try {
370
- for (var astNodes_2 = __values(astNodes), astNodes_2_1 = astNodes_2.next(); !astNodes_2_1.done; astNodes_2_1 = astNodes_2.next()) {
371
- var astNode = astNodes_2_1.value;
372
- if (astNode.directives) {
373
- try {
374
- for (var _c = (e_6 = void 0, __values(astNode.directives)), _d = _c.next(); !_d.done; _d = _c.next()) {
375
- var directiveNode = _d.value;
376
- if (directiveNode.name.value === directiveName) {
377
- result.push(getArgumentValues(schemaDirective, directiveNode));
378
- }
379
- }
380
- }
381
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
382
- finally {
383
- try {
384
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
385
- }
386
- finally { if (e_6) throw e_6.error; }
387
- }
388
- }
389
- }
390
- }
391
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
392
- finally {
393
- try {
394
- if (astNodes_2_1 && !astNodes_2_1.done && (_a = astNodes_2.return)) _a.call(astNodes_2);
395
- }
396
- finally { if (e_5) throw e_5.error; }
397
- }
398
- if (!result.length) {
399
- return undefined;
400
- }
401
- return result;
402
- }
403
-
404
- function parseDirectiveValue(value) {
405
- switch (value.kind) {
406
- case Kind.INT:
407
- return parseInt(value.value);
408
- case Kind.FLOAT:
409
- return parseFloat(value.value);
410
- case Kind.BOOLEAN:
411
- return Boolean(value.value);
412
- case Kind.STRING:
413
- case Kind.ENUM:
414
- return value.value;
415
- case Kind.LIST:
416
- return value.values.map(function (v) { return parseDirectiveValue(v); });
417
- case Kind.OBJECT:
418
- return value.fields.reduce(function (prev, v) {
419
- var _a;
420
- return (__assign(__assign({}, prev), (_a = {}, _a[v.name.value] = parseDirectiveValue(v.value), _a)));
421
- }, {});
422
- case Kind.NULL:
423
- return null;
424
- default:
425
- return null;
426
- }
427
- }
428
- function getFieldsWithDirectives(documentNode, options) {
429
- var e_1, _a, e_2, _b;
430
- if (options === void 0) { options = {}; }
431
- var result = {};
432
- var selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
433
- if (options.includeInputTypes) {
434
- selected = __spreadArray(__spreadArray([], __read(selected), false), ['InputObjectTypeDefinition', 'InputObjectTypeExtension'], false);
435
- }
436
- var allTypes = documentNode.definitions.filter(function (obj) { return selected.includes(obj.kind); });
437
- try {
438
- for (var allTypes_1 = __values(allTypes), allTypes_1_1 = allTypes_1.next(); !allTypes_1_1.done; allTypes_1_1 = allTypes_1.next()) {
439
- var type = allTypes_1_1.value;
440
- var typeName = type.name.value;
441
- if (type.fields == null) {
442
- continue;
443
- }
444
- try {
445
- for (var _c = (e_2 = void 0, __values(type.fields)), _d = _c.next(); !_d.done; _d = _c.next()) {
446
- var field = _d.value;
447
- if (field.directives && field.directives.length > 0) {
448
- var fieldName = field.name.value;
449
- var key = typeName + "." + fieldName;
450
- var directives = field.directives.map(function (d) { return ({
451
- name: d.name.value,
452
- args: (d.arguments || []).reduce(function (prev, arg) {
453
- var _a;
454
- return (__assign(__assign({}, prev), (_a = {}, _a[arg.name.value] = parseDirectiveValue(arg.value), _a)));
455
- }, {}),
456
- }); });
457
- result[key] = directives;
458
- }
459
- }
460
- }
461
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
462
- finally {
463
- try {
464
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
465
- }
466
- finally { if (e_2) throw e_2.error; }
467
- }
468
- }
469
- }
470
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
471
- finally {
472
- try {
473
- if (allTypes_1_1 && !allTypes_1_1.done && (_a = allTypes_1.return)) _a.call(allTypes_1);
474
- }
475
- finally { if (e_1) throw e_1.error; }
476
- }
477
- return result;
478
- }
479
-
480
- function getImplementingTypes(interfaceName, schema) {
481
- var allTypesMap = schema.getTypeMap();
482
- var result = [];
483
- for (var graphqlTypeName in allTypesMap) {
484
- var graphqlType = allTypesMap[graphqlTypeName];
485
- if (isObjectType(graphqlType)) {
486
- var allInterfaces = graphqlType.getInterfaces();
487
- if (allInterfaces.find(function (int) { return int.name === interfaceName; })) {
488
- result.push(graphqlType.name);
489
- }
490
- }
491
- }
492
- return result;
493
- }
494
-
495
- function astFromType(type) {
496
- if (isNonNullType(type)) {
497
- var innerType = astFromType(type.ofType);
498
- if (innerType.kind === Kind.NON_NULL_TYPE) {
499
- throw new Error("Invalid type node " + inspect(type) + ". Inner type of non-null type cannot be a non-null type.");
500
- }
501
- return {
502
- kind: Kind.NON_NULL_TYPE,
503
- type: innerType,
504
- };
505
- }
506
- else if (isListType(type)) {
507
- return {
508
- kind: Kind.LIST_TYPE,
509
- type: astFromType(type.ofType),
510
- };
511
- }
512
- return {
513
- kind: Kind.NAMED_TYPE,
514
- name: {
515
- kind: Kind.NAME,
516
- value: type.name,
517
- },
518
- };
519
- }
520
-
521
- /**
522
- * Produces a GraphQL Value AST given a JavaScript object.
523
- * Function will match JavaScript/JSON values to GraphQL AST schema format
524
- * by using the following mapping.
525
- *
526
- * | JSON Value | GraphQL Value |
527
- * | ------------- | -------------------- |
528
- * | Object | Input Object |
529
- * | Array | List |
530
- * | Boolean | Boolean |
531
- * | String | String |
532
- * | Number | Int / Float |
533
- * | null | NullValue |
534
- *
535
- */
536
- function astFromValueUntyped(value) {
537
- var e_1, _a;
538
- // only explicit null, not undefined, NaN
539
- if (value === null) {
540
- return { kind: Kind.NULL };
541
- }
542
- // undefined
543
- if (value === undefined) {
544
- return null;
545
- }
546
- // Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
547
- // the value is not an array, convert the value using the list's item type.
548
- if (Array.isArray(value)) {
549
- var valuesNodes = [];
550
- try {
551
- for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
552
- var item = value_1_1.value;
553
- var itemNode = astFromValueUntyped(item);
554
- if (itemNode != null) {
555
- valuesNodes.push(itemNode);
556
- }
557
- }
558
- }
559
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
560
- finally {
561
- try {
562
- if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
563
- }
564
- finally { if (e_1) throw e_1.error; }
565
- }
566
- return { kind: Kind.LIST, values: valuesNodes };
567
- }
568
- if (typeof value === 'object') {
569
- var fieldNodes = [];
570
- for (var fieldName in value) {
571
- var fieldValue = value[fieldName];
572
- var ast = astFromValueUntyped(fieldValue);
573
- if (ast) {
574
- fieldNodes.push({
575
- kind: Kind.OBJECT_FIELD,
576
- name: { kind: Kind.NAME, value: fieldName },
577
- value: ast,
578
- });
579
- }
580
- }
581
- return { kind: Kind.OBJECT, fields: fieldNodes };
582
- }
583
- // Others serialize based on their corresponding JavaScript scalar types.
584
- if (typeof value === 'boolean') {
585
- return { kind: Kind.BOOLEAN, value: value };
586
- }
587
- // JavaScript numbers can be Int or Float values.
588
- if (typeof value === 'number' && isFinite(value)) {
589
- var stringNum = String(value);
590
- return integerStringRegExp.test(stringNum)
591
- ? { kind: Kind.INT, value: stringNum }
592
- : { kind: Kind.FLOAT, value: stringNum };
593
- }
594
- if (typeof value === 'string') {
595
- return { kind: Kind.STRING, value: value };
596
- }
597
- throw new TypeError("Cannot convert value to AST: " + value + ".");
598
- }
599
- /**
600
- * IntValue:
601
- * - NegativeSign? 0
602
- * - NegativeSign? NonZeroDigit ( Digit+ )?
603
- */
604
- var integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
605
-
606
- function memoize1(fn) {
607
- var memoize1cache = new WeakMap();
608
- return function memoized(a1) {
609
- var cachedValue = memoize1cache.get(a1);
610
- if (cachedValue === undefined) {
611
- var newValue = fn(a1);
612
- memoize1cache.set(a1, newValue);
613
- return newValue;
614
- }
615
- return cachedValue;
616
- };
617
- }
618
- function memoize2(fn) {
619
- var memoize2cache = new WeakMap();
620
- return function memoized(a1, a2) {
621
- var cache2 = memoize2cache.get(a1);
622
- if (!cache2) {
623
- cache2 = new WeakMap();
624
- memoize2cache.set(a1, cache2);
625
- var newValue = fn(a1, a2);
626
- cache2.set(a2, newValue);
627
- return newValue;
628
- }
629
- var cachedValue = cache2.get(a2);
630
- if (cachedValue === undefined) {
631
- var newValue = fn(a1, a2);
632
- cache2.set(a2, newValue);
633
- return newValue;
634
- }
635
- return cachedValue;
636
- };
637
- }
638
- function memoize3(fn) {
639
- var memoize3Cache = new WeakMap();
640
- return function memoized(a1, a2, a3) {
641
- var cache2 = memoize3Cache.get(a1);
642
- if (!cache2) {
643
- cache2 = new WeakMap();
644
- memoize3Cache.set(a1, cache2);
645
- var cache3_1 = new WeakMap();
646
- cache2.set(a2, cache3_1);
647
- var newValue = fn(a1, a2, a3);
648
- cache3_1.set(a3, newValue);
649
- return newValue;
650
- }
651
- var cache3 = cache2.get(a2);
652
- if (!cache3) {
653
- cache3 = new WeakMap();
654
- cache2.set(a2, cache3);
655
- var newValue = fn(a1, a2, a3);
656
- cache3.set(a3, newValue);
657
- return newValue;
658
- }
659
- var cachedValue = cache3.get(a3);
660
- if (cachedValue === undefined) {
661
- var newValue = fn(a1, a2, a3);
662
- cache3.set(a3, newValue);
663
- return newValue;
664
- }
665
- return cachedValue;
666
- };
667
- }
668
- function memoize4(fn) {
669
- var memoize4Cache = new WeakMap();
670
- return function memoized(a1, a2, a3, a4) {
671
- var cache2 = memoize4Cache.get(a1);
672
- if (!cache2) {
673
- cache2 = new WeakMap();
674
- memoize4Cache.set(a1, cache2);
675
- var cache3_2 = new WeakMap();
676
- cache2.set(a2, cache3_2);
677
- var cache4_1 = new WeakMap();
678
- cache3_2.set(a3, cache4_1);
679
- var newValue = fn(a1, a2, a3, a4);
680
- cache4_1.set(a4, newValue);
681
- return newValue;
682
- }
683
- var cache3 = cache2.get(a2);
684
- if (!cache3) {
685
- cache3 = new WeakMap();
686
- cache2.set(a2, cache3);
687
- var cache4_2 = new WeakMap();
688
- cache3.set(a3, cache4_2);
689
- var newValue = fn(a1, a2, a3, a4);
690
- cache4_2.set(a4, newValue);
691
- return newValue;
692
- }
693
- var cache4 = cache3.get(a3);
694
- if (!cache4) {
695
- var cache4_3 = new WeakMap();
696
- cache3.set(a3, cache4_3);
697
- var newValue = fn(a1, a2, a3, a4);
698
- cache4_3.set(a4, newValue);
699
- return newValue;
700
- }
701
- var cachedValue = cache4.get(a4);
702
- if (cachedValue === undefined) {
703
- var newValue = fn(a1, a2, a3, a4);
704
- cache4.set(a4, newValue);
705
- return newValue;
706
- }
707
- return cachedValue;
708
- };
709
- }
710
- function memoize5(fn) {
711
- var memoize5Cache = new WeakMap();
712
- return function memoized(a1, a2, a3, a4, a5) {
713
- var cache2 = memoize5Cache.get(a1);
714
- if (!cache2) {
715
- cache2 = new WeakMap();
716
- memoize5Cache.set(a1, cache2);
717
- var cache3_3 = new WeakMap();
718
- cache2.set(a2, cache3_3);
719
- var cache4_4 = new WeakMap();
720
- cache3_3.set(a3, cache4_4);
721
- var cache5_1 = new WeakMap();
722
- cache4_4.set(a4, cache5_1);
723
- var newValue = fn(a1, a2, a3, a4, a5);
724
- cache5_1.set(a5, newValue);
725
- return newValue;
726
- }
727
- var cache3 = cache2.get(a2);
728
- if (!cache3) {
729
- cache3 = new WeakMap();
730
- cache2.set(a2, cache3);
731
- var cache4_5 = new WeakMap();
732
- cache3.set(a3, cache4_5);
733
- var cache5_2 = new WeakMap();
734
- cache4_5.set(a4, cache5_2);
735
- var newValue = fn(a1, a2, a3, a4, a5);
736
- cache5_2.set(a5, newValue);
737
- return newValue;
738
- }
739
- var cache4 = cache3.get(a3);
740
- if (!cache4) {
741
- cache4 = new WeakMap();
742
- cache3.set(a3, cache4);
743
- var cache5_3 = new WeakMap();
744
- cache4.set(a4, cache5_3);
745
- var newValue = fn(a1, a2, a3, a4, a5);
746
- cache5_3.set(a5, newValue);
747
- return newValue;
748
- }
749
- var cache5 = cache4.get(a4);
750
- if (!cache5) {
751
- cache5 = new WeakMap();
752
- cache4.set(a4, cache5);
753
- var newValue = fn(a1, a2, a3, a4, a5);
754
- cache5.set(a5, newValue);
755
- return newValue;
756
- }
757
- var cachedValue = cache5.get(a5);
758
- if (cachedValue === undefined) {
759
- var newValue = fn(a1, a2, a3, a4, a5);
760
- cache5.set(a5, newValue);
761
- return newValue;
762
- }
763
- return cachedValue;
764
- };
765
- }
766
- var memoize2of4cache = new WeakMap();
767
- function memoize2of4(fn) {
768
- return function memoized(a1, a2, a3, a4) {
769
- var cache2 = memoize2of4cache.get(a1);
770
- if (!cache2) {
771
- cache2 = new WeakMap();
772
- memoize2of4cache.set(a1, cache2);
773
- var newValue = fn(a1, a2, a3, a4);
774
- cache2.set(a2, newValue);
775
- return newValue;
776
- }
777
- var cachedValue = cache2.get(a2);
778
- if (cachedValue === undefined) {
779
- var newValue = fn(a1, a2, a3, a4);
780
- cache2.set(a2, newValue);
781
- return newValue;
782
- }
783
- return cachedValue;
784
- };
785
- }
786
-
787
- function getDefinedRootType(schema, operation) {
788
- var rootTypeMap = getRootTypeMap(schema);
789
- var rootType = rootTypeMap.get(operation);
790
- if (rootType == null) {
791
- throw new Error("Root type for operation \"" + operation + "\" not defined by the given schema.");
792
- }
793
- return rootType;
794
- }
795
- var getRootTypeNames = memoize1(function getRootTypeNames(schema) {
796
- var rootTypes = getRootTypes(schema);
797
- return new Set(__spreadArray([], __read(rootTypes), false).map(function (type) { return type.name; }));
798
- });
799
- var getRootTypes = memoize1(function getRootTypes(schema) {
800
- var rootTypeMap = getRootTypeMap(schema);
801
- return new Set(rootTypeMap.values());
802
- });
803
- var getRootTypeMap = memoize1(function getRootTypeMap(schema) {
804
- var rootTypeMap = new Map();
805
- var queryType = schema.getQueryType();
806
- if (queryType) {
807
- rootTypeMap.set('query', queryType);
808
- }
809
- var mutationType = schema.getMutationType();
810
- if (mutationType) {
811
- rootTypeMap.set('mutation', mutationType);
812
- }
813
- var subscriptionType = schema.getSubscriptionType();
814
- if (subscriptionType) {
815
- rootTypeMap.set('subscription', subscriptionType);
816
- }
817
- return rootTypeMap;
818
- });
819
-
820
- function getDocumentNodeFromSchema(schema, options) {
821
- var e_1, _a;
822
- if (options === void 0) { options = {}; }
823
- var pathToDirectivesInExtensions = options.pathToDirectivesInExtensions;
824
- var typesMap = schema.getTypeMap();
825
- var schemaNode = astFromSchema(schema, pathToDirectivesInExtensions);
826
- var definitions = schemaNode != null ? [schemaNode] : [];
827
- var directives = schema.getDirectives();
828
- try {
829
- for (var directives_1 = __values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
830
- var directive = directives_1_1.value;
831
- if (isSpecifiedDirective(directive)) {
832
- continue;
833
- }
834
- definitions.push(astFromDirective(directive, schema, pathToDirectivesInExtensions));
835
- }
836
- }
837
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
838
- finally {
839
- try {
840
- if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
841
- }
842
- finally { if (e_1) throw e_1.error; }
843
- }
844
- for (var typeName in typesMap) {
845
- var type = typesMap[typeName];
846
- var isPredefinedScalar = isSpecifiedScalarType(type);
847
- var isIntrospection = isIntrospectionType(type);
848
- if (isPredefinedScalar || isIntrospection) {
849
- continue;
850
- }
851
- if (isObjectType(type)) {
852
- definitions.push(astFromObjectType(type, schema, pathToDirectivesInExtensions));
853
- }
854
- else if (isInterfaceType(type)) {
855
- definitions.push(astFromInterfaceType(type, schema, pathToDirectivesInExtensions));
856
- }
857
- else if (isUnionType(type)) {
858
- definitions.push(astFromUnionType(type, schema, pathToDirectivesInExtensions));
859
- }
860
- else if (isInputObjectType(type)) {
861
- definitions.push(astFromInputObjectType(type, schema, pathToDirectivesInExtensions));
862
- }
863
- else if (isEnumType(type)) {
864
- definitions.push(astFromEnumType(type, schema, pathToDirectivesInExtensions));
865
- }
866
- else if (isScalarType(type)) {
867
- definitions.push(astFromScalarType(type, schema, pathToDirectivesInExtensions));
868
- }
869
- else {
870
- throw new Error("Unknown type " + type + ".");
871
- }
872
- }
873
- return {
874
- kind: Kind.DOCUMENT,
875
- definitions: definitions,
876
- };
877
- }
878
- // this approach uses the default schema printer rather than a custom solution, so may be more backwards compatible
879
- // currently does not allow customization of printSchema options having to do with comments.
880
- function printSchemaWithDirectives(schema, options) {
881
- if (options === void 0) { options = {}; }
882
- var documentNode = getDocumentNodeFromSchema(schema, options);
883
- return print(documentNode);
884
- }
885
- function astFromSchema(schema, pathToDirectivesInExtensions) {
886
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
887
- var _e, _f;
888
- var operationTypeMap = new Map([
889
- ['query', undefined],
890
- ['mutation', undefined],
891
- ['subscription', undefined],
892
- ]);
893
- var nodes = [];
894
- if (schema.astNode != null) {
895
- nodes.push(schema.astNode);
896
- }
897
- if (schema.extensionASTNodes != null) {
898
- try {
899
- for (var _g = __values(schema.extensionASTNodes), _h = _g.next(); !_h.done; _h = _g.next()) {
900
- var extensionASTNode = _h.value;
901
- nodes.push(extensionASTNode);
902
- }
903
- }
904
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
905
- finally {
906
- try {
907
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
908
- }
909
- finally { if (e_2) throw e_2.error; }
910
- }
911
- }
912
- try {
913
- for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
914
- var node = nodes_1_1.value;
915
- if (node.operationTypes) {
916
- try {
917
- for (var _j = (e_4 = void 0, __values(node.operationTypes)), _k = _j.next(); !_k.done; _k = _j.next()) {
918
- var operationTypeDefinitionNode = _k.value;
919
- operationTypeMap.set(operationTypeDefinitionNode.operation, operationTypeDefinitionNode);
920
- }
921
- }
922
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
923
- finally {
924
- try {
925
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
926
- }
927
- finally { if (e_4) throw e_4.error; }
928
- }
929
- }
930
- }
931
- }
932
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
933
- finally {
934
- try {
935
- if (nodes_1_1 && !nodes_1_1.done && (_b = nodes_1.return)) _b.call(nodes_1);
936
- }
937
- finally { if (e_3) throw e_3.error; }
938
- }
939
- var rootTypeMap = getRootTypeMap(schema);
940
- try {
941
- for (var operationTypeMap_1 = __values(operationTypeMap), operationTypeMap_1_1 = operationTypeMap_1.next(); !operationTypeMap_1_1.done; operationTypeMap_1_1 = operationTypeMap_1.next()) {
942
- var _l = __read(operationTypeMap_1_1.value, 2), operationTypeNode = _l[0], operationTypeDefinitionNode = _l[1];
943
- var rootType = rootTypeMap.get(operationTypeNode);
944
- if (rootType != null) {
945
- var rootTypeAST = astFromType(rootType);
946
- if (operationTypeDefinitionNode != null) {
947
- operationTypeDefinitionNode.type = rootTypeAST;
948
- }
949
- else {
950
- operationTypeMap.set(operationTypeNode, {
951
- kind: Kind.OPERATION_TYPE_DEFINITION,
952
- operation: operationTypeNode,
953
- type: rootTypeAST,
954
- });
955
- }
956
- }
957
- }
958
- }
959
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
960
- finally {
961
- try {
962
- if (operationTypeMap_1_1 && !operationTypeMap_1_1.done && (_d = operationTypeMap_1.return)) _d.call(operationTypeMap_1);
963
- }
964
- finally { if (e_5) throw e_5.error; }
965
- }
966
- var operationTypes = __spreadArray([], __read(operationTypeMap.values()), false).filter(isSome);
967
- var directives = getDirectiveNodes(schema, schema, pathToDirectivesInExtensions);
968
- if (!operationTypes.length && !directives.length) {
969
- return null;
970
- }
971
- var schemaNode = {
972
- kind: operationTypes != null ? Kind.SCHEMA_DEFINITION : Kind.SCHEMA_EXTENSION,
973
- operationTypes: operationTypes,
974
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
975
- directives: directives,
976
- };
977
- // This code is so weird because it needs to support GraphQL.js 14
978
- // In GraphQL.js 14 there is no `description` value on schemaNode
979
- schemaNode.description =
980
- ((_f = (_e = schema.astNode) === null || _e === void 0 ? void 0 : _e.description) !== null && _f !== void 0 ? _f : schema.description != null)
981
- ? {
982
- kind: Kind.STRING,
983
- value: schema.description,
984
- block: true,
985
- }
986
- : undefined;
987
- return schemaNode;
988
- }
989
- function astFromDirective(directive, schema, pathToDirectivesInExtensions) {
990
- var _a, _b, _c, _d;
991
- return {
992
- kind: Kind.DIRECTIVE_DEFINITION,
993
- description: (_b = (_a = directive.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (directive.description
994
- ? {
995
- kind: Kind.STRING,
996
- value: directive.description,
997
- }
998
- : undefined),
999
- name: {
1000
- kind: Kind.NAME,
1001
- value: directive.name,
1002
- },
1003
- arguments: (_c = directive.args) === null || _c === void 0 ? void 0 : _c.map(function (arg) { return astFromArg(arg, schema, pathToDirectivesInExtensions); }),
1004
- repeatable: directive.isRepeatable,
1005
- locations: ((_d = directive.locations) === null || _d === void 0 ? void 0 : _d.map(function (location) { return ({
1006
- kind: Kind.NAME,
1007
- value: location,
1008
- }); })) || [],
1009
- };
1010
- }
1011
- function getDirectiveNodes(entity, schema, pathToDirectivesInExtensions) {
1012
- var e_6, _a;
1013
- var directivesInExtensions = getDirectivesInExtensions(entity, pathToDirectivesInExtensions);
1014
- var nodes = [];
1015
- if (entity.astNode != null) {
1016
- nodes.push(entity.astNode);
1017
- }
1018
- if ('extensionASTNodes' in entity && entity.extensionASTNodes != null) {
1019
- nodes = nodes.concat(entity.extensionASTNodes);
1020
- }
1021
- var directives;
1022
- if (directivesInExtensions != null) {
1023
- directives = makeDirectiveNodes(schema, directivesInExtensions);
1024
- }
1025
- else {
1026
- directives = [];
1027
- try {
1028
- for (var nodes_2 = __values(nodes), nodes_2_1 = nodes_2.next(); !nodes_2_1.done; nodes_2_1 = nodes_2.next()) {
1029
- var node = nodes_2_1.value;
1030
- if (node.directives) {
1031
- directives.push.apply(directives, __spreadArray([], __read(node.directives), false));
1032
- }
1033
- }
1034
- }
1035
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1036
- finally {
1037
- try {
1038
- if (nodes_2_1 && !nodes_2_1.done && (_a = nodes_2.return)) _a.call(nodes_2);
1039
- }
1040
- finally { if (e_6) throw e_6.error; }
1041
- }
1042
- }
1043
- return directives;
1044
- }
1045
- function getDeprecatableDirectiveNodes(entity, schema, pathToDirectivesInExtensions) {
1046
- var _a, _b;
1047
- var directiveNodesBesidesDeprecated = [];
1048
- var deprecatedDirectiveNode = null;
1049
- var directivesInExtensions = getDirectivesInExtensions(entity, pathToDirectivesInExtensions);
1050
- var directives;
1051
- if (directivesInExtensions != null) {
1052
- directives = makeDirectiveNodes(schema, directivesInExtensions);
1053
- }
1054
- else {
1055
- directives = (_a = entity.astNode) === null || _a === void 0 ? void 0 : _a.directives;
1056
- }
1057
- if (directives != null) {
1058
- directiveNodesBesidesDeprecated = directives.filter(function (directive) { return directive.name.value !== 'deprecated'; });
1059
- if (entity.deprecationReason != null) {
1060
- deprecatedDirectiveNode = (_b = directives.filter(function (directive) { return directive.name.value === 'deprecated'; })) === null || _b === void 0 ? void 0 : _b[0];
1061
- }
1062
- }
1063
- if (entity.deprecationReason != null &&
1064
- deprecatedDirectiveNode == null) {
1065
- deprecatedDirectiveNode = makeDeprecatedDirective(entity.deprecationReason);
1066
- }
1067
- return deprecatedDirectiveNode == null
1068
- ? directiveNodesBesidesDeprecated
1069
- : [deprecatedDirectiveNode].concat(directiveNodesBesidesDeprecated);
1070
- }
1071
- function astFromArg(arg, schema, pathToDirectivesInExtensions) {
1072
- var _a, _b, _c;
1073
- return {
1074
- kind: Kind.INPUT_VALUE_DEFINITION,
1075
- description: (_b = (_a = arg.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (arg.description
1076
- ? {
1077
- kind: Kind.STRING,
1078
- value: arg.description,
1079
- block: true,
1080
- }
1081
- : undefined),
1082
- name: {
1083
- kind: Kind.NAME,
1084
- value: arg.name,
1085
- },
1086
- type: astFromType(arg.type),
1087
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1088
- defaultValue: arg.defaultValue !== undefined ? (_c = astFromValue(arg.defaultValue, arg.type)) !== null && _c !== void 0 ? _c : undefined : undefined,
1089
- directives: getDeprecatableDirectiveNodes(arg, schema, pathToDirectivesInExtensions),
1090
- };
1091
- }
1092
- function astFromObjectType(type, schema, pathToDirectivesInExtensions) {
1093
- var _a, _b;
1094
- return {
1095
- kind: Kind.OBJECT_TYPE_DEFINITION,
1096
- description: (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (type.description
1097
- ? {
1098
- kind: Kind.STRING,
1099
- value: type.description,
1100
- block: true,
1101
- }
1102
- : undefined),
1103
- name: {
1104
- kind: Kind.NAME,
1105
- value: type.name,
1106
- },
1107
- fields: Object.values(type.getFields()).map(function (field) { return astFromField(field, schema, pathToDirectivesInExtensions); }),
1108
- interfaces: Object.values(type.getInterfaces()).map(function (iFace) { return astFromType(iFace); }),
1109
- directives: getDirectiveNodes(type, schema, pathToDirectivesInExtensions),
1110
- };
1111
- }
1112
- function astFromInterfaceType(type, schema, pathToDirectivesInExtensions) {
1113
- var _a, _b;
1114
- var node = {
1115
- kind: Kind.INTERFACE_TYPE_DEFINITION,
1116
- description: (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (type.description
1117
- ? {
1118
- kind: Kind.STRING,
1119
- value: type.description,
1120
- block: true,
1121
- }
1122
- : undefined),
1123
- name: {
1124
- kind: Kind.NAME,
1125
- value: type.name,
1126
- },
1127
- fields: Object.values(type.getFields()).map(function (field) { return astFromField(field, schema, pathToDirectivesInExtensions); }),
1128
- directives: getDirectiveNodes(type, schema, pathToDirectivesInExtensions),
1129
- };
1130
- if ('getInterfaces' in type) {
1131
- node.interfaces = Object.values(type.getInterfaces()).map(function (iFace) { return astFromType(iFace); });
1132
- }
1133
- return node;
1134
- }
1135
- function astFromUnionType(type, schema, pathToDirectivesInExtensions) {
1136
- var _a, _b;
1137
- return {
1138
- kind: Kind.UNION_TYPE_DEFINITION,
1139
- description: (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (type.description
1140
- ? {
1141
- kind: Kind.STRING,
1142
- value: type.description,
1143
- block: true,
1144
- }
1145
- : undefined),
1146
- name: {
1147
- kind: Kind.NAME,
1148
- value: type.name,
1149
- },
1150
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1151
- directives: getDirectiveNodes(type, schema, pathToDirectivesInExtensions),
1152
- types: type.getTypes().map(function (type) { return astFromType(type); }),
1153
- };
1154
- }
1155
- function astFromInputObjectType(type, schema, pathToDirectivesInExtensions) {
1156
- var _a, _b;
1157
- return {
1158
- kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
1159
- description: (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (type.description
1160
- ? {
1161
- kind: Kind.STRING,
1162
- value: type.description,
1163
- block: true,
1164
- }
1165
- : undefined),
1166
- name: {
1167
- kind: Kind.NAME,
1168
- value: type.name,
1169
- },
1170
- fields: Object.values(type.getFields()).map(function (field) {
1171
- return astFromInputField(field, schema, pathToDirectivesInExtensions);
1172
- }),
1173
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1174
- directives: getDirectiveNodes(type, schema, pathToDirectivesInExtensions),
1175
- };
1176
- }
1177
- function astFromEnumType(type, schema, pathToDirectivesInExtensions) {
1178
- var _a, _b;
1179
- return {
1180
- kind: Kind.ENUM_TYPE_DEFINITION,
1181
- description: (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (type.description
1182
- ? {
1183
- kind: Kind.STRING,
1184
- value: type.description,
1185
- block: true,
1186
- }
1187
- : undefined),
1188
- name: {
1189
- kind: Kind.NAME,
1190
- value: type.name,
1191
- },
1192
- values: Object.values(type.getValues()).map(function (value) { return astFromEnumValue(value, schema, pathToDirectivesInExtensions); }),
1193
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1194
- directives: getDirectiveNodes(type, schema, pathToDirectivesInExtensions),
1195
- };
1196
- }
1197
- function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
1198
- var _a, _b, _c;
1199
- var directivesInExtensions = getDirectivesInExtensions(type, pathToDirectivesInExtensions);
1200
- var directives = directivesInExtensions
1201
- ? makeDirectiveNodes(schema, directivesInExtensions)
1202
- : ((_a = type.astNode) === null || _a === void 0 ? void 0 : _a.directives) || [];
1203
- if ('specifiedBy' in type && !directives.some(function (directiveNode) { return directiveNode.name.value === 'specifiedBy'; })) {
1204
- var specifiedByArgs = {
1205
- url: type['specifiedByUrl'],
1206
- };
1207
- directives.push(makeDirectiveNode('specifiedBy', specifiedByArgs));
1208
- }
1209
- return {
1210
- kind: Kind.SCALAR_TYPE_DEFINITION,
1211
- description: (_c = (_b = type.astNode) === null || _b === void 0 ? void 0 : _b.description) !== null && _c !== void 0 ? _c : (type.description
1212
- ? {
1213
- kind: Kind.STRING,
1214
- value: type.description,
1215
- block: true,
1216
- }
1217
- : undefined),
1218
- name: {
1219
- kind: Kind.NAME,
1220
- value: type.name,
1221
- },
1222
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1223
- directives: directives,
1224
- };
1225
- }
1226
- function astFromField(field, schema, pathToDirectivesInExtensions) {
1227
- var _a, _b;
1228
- return {
1229
- kind: Kind.FIELD_DEFINITION,
1230
- description: (_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (field.description
1231
- ? {
1232
- kind: Kind.STRING,
1233
- value: field.description,
1234
- block: true,
1235
- }
1236
- : undefined),
1237
- name: {
1238
- kind: Kind.NAME,
1239
- value: field.name,
1240
- },
1241
- arguments: field.args.map(function (arg) { return astFromArg(arg, schema, pathToDirectivesInExtensions); }),
1242
- type: astFromType(field.type),
1243
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1244
- directives: getDeprecatableDirectiveNodes(field, schema, pathToDirectivesInExtensions),
1245
- };
1246
- }
1247
- function astFromInputField(field, schema, pathToDirectivesInExtensions) {
1248
- var _a, _b, _c;
1249
- return {
1250
- kind: Kind.INPUT_VALUE_DEFINITION,
1251
- description: (_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (field.description
1252
- ? {
1253
- kind: Kind.STRING,
1254
- value: field.description,
1255
- block: true,
1256
- }
1257
- : undefined),
1258
- name: {
1259
- kind: Kind.NAME,
1260
- value: field.name,
1261
- },
1262
- type: astFromType(field.type),
1263
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1264
- directives: getDeprecatableDirectiveNodes(field, schema, pathToDirectivesInExtensions),
1265
- defaultValue: (_c = astFromValue(field.defaultValue, field.type)) !== null && _c !== void 0 ? _c : undefined,
1266
- };
1267
- }
1268
- function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
1269
- var _a, _b;
1270
- return {
1271
- kind: Kind.ENUM_VALUE_DEFINITION,
1272
- description: (_b = (_a = value.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : (value.description
1273
- ? {
1274
- kind: Kind.STRING,
1275
- value: value.description,
1276
- block: true,
1277
- }
1278
- : undefined),
1279
- name: {
1280
- kind: Kind.NAME,
1281
- value: value.name,
1282
- },
1283
- // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
1284
- directives: getDirectiveNodes(value, schema, pathToDirectivesInExtensions),
1285
- };
1286
- }
1287
- function makeDeprecatedDirective(deprecationReason) {
1288
- return makeDirectiveNode('deprecated', { reason: deprecationReason }, GraphQLDeprecatedDirective);
1289
- }
1290
- function makeDirectiveNode(name, args, directive) {
1291
- var e_7, _a;
1292
- var directiveArguments = [];
1293
- if (directive != null) {
1294
- try {
1295
- for (var _b = __values(directive.args), _c = _b.next(); !_c.done; _c = _b.next()) {
1296
- var arg = _c.value;
1297
- var argName = arg.name;
1298
- var argValue = args[argName];
1299
- if (argValue !== undefined) {
1300
- var value = astFromValue(argValue, arg.type);
1301
- if (value) {
1302
- directiveArguments.push({
1303
- kind: Kind.ARGUMENT,
1304
- name: {
1305
- kind: Kind.NAME,
1306
- value: argName,
1307
- },
1308
- value: value,
1309
- });
1310
- }
1311
- }
1312
- }
1313
- }
1314
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1315
- finally {
1316
- try {
1317
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1318
- }
1319
- finally { if (e_7) throw e_7.error; }
1320
- }
1321
- }
1322
- else {
1323
- for (var argName in args) {
1324
- var argValue = args[argName];
1325
- var value = astFromValueUntyped(argValue);
1326
- if (value) {
1327
- directiveArguments.push({
1328
- kind: Kind.ARGUMENT,
1329
- name: {
1330
- kind: Kind.NAME,
1331
- value: argName,
1332
- },
1333
- value: value,
1334
- });
1335
- }
1336
- }
1337
- }
1338
- return {
1339
- kind: Kind.DIRECTIVE,
1340
- name: {
1341
- kind: Kind.NAME,
1342
- value: name,
1343
- },
1344
- arguments: directiveArguments,
1345
- };
1346
- }
1347
- function makeDirectiveNodes(schema, directiveValues) {
1348
- var e_8, _a;
1349
- var directiveNodes = [];
1350
- for (var directiveName in directiveValues) {
1351
- var arrayOrSingleValue = directiveValues[directiveName];
1352
- var directive = schema === null || schema === void 0 ? void 0 : schema.getDirective(directiveName);
1353
- if (Array.isArray(arrayOrSingleValue)) {
1354
- try {
1355
- for (var arrayOrSingleValue_1 = (e_8 = void 0, __values(arrayOrSingleValue)), arrayOrSingleValue_1_1 = arrayOrSingleValue_1.next(); !arrayOrSingleValue_1_1.done; arrayOrSingleValue_1_1 = arrayOrSingleValue_1.next()) {
1356
- var value = arrayOrSingleValue_1_1.value;
1357
- directiveNodes.push(makeDirectiveNode(directiveName, value, directive));
1358
- }
1359
- }
1360
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1361
- finally {
1362
- try {
1363
- if (arrayOrSingleValue_1_1 && !arrayOrSingleValue_1_1.done && (_a = arrayOrSingleValue_1.return)) _a.call(arrayOrSingleValue_1);
1364
- }
1365
- finally { if (e_8) throw e_8.error; }
1366
- }
1367
- }
1368
- else {
1369
- directiveNodes.push(makeDirectiveNode(directiveName, arrayOrSingleValue, directive));
1370
- }
1371
- }
1372
- return directiveNodes;
1373
- }
1374
-
1375
- var AggregateErrorImpl = globalThis.AggregateError;
1376
- if (typeof AggregateErrorImpl === 'undefined') {
1377
- var AggregateErrorClass_1 = /** @class */ (function (_super) {
1378
- __extends(AggregateErrorClass, _super);
1379
- function AggregateErrorClass(errors, message) {
1380
- if (message === void 0) { message = ''; }
1381
- var _this = _super.call(this, message) || this;
1382
- _this.errors = errors;
1383
- _this.name = 'AggregateError';
1384
- Error.captureStackTrace(_this, AggregateErrorClass);
1385
- return _this;
1386
- }
1387
- return AggregateErrorClass;
1388
- }(Error));
1389
- AggregateErrorImpl = function (errors, message) {
1390
- return new AggregateErrorClass_1(errors, message);
1391
- };
1392
- }
1393
-
1394
- function validateGraphQlDocuments(schema, documentFiles, effectiveRules) {
1395
- return __awaiter(this, void 0, void 0, function () {
1396
- var allFragmentMap, documentFileObjectsToValidate, documentFiles_1, documentFiles_1_1, documentFile, definitionsToValidate, _a, _b, definitionNode, allErrors, allFragmentsDocument;
1397
- var e_1, _c, e_2, _d;
1398
- var _this = this;
1399
- return __generator(this, function (_e) {
1400
- switch (_e.label) {
1401
- case 0:
1402
- effectiveRules = effectiveRules || createDefaultRules();
1403
- allFragmentMap = new Map();
1404
- documentFileObjectsToValidate = [];
1405
- try {
1406
- for (documentFiles_1 = __values(documentFiles), documentFiles_1_1 = documentFiles_1.next(); !documentFiles_1_1.done; documentFiles_1_1 = documentFiles_1.next()) {
1407
- documentFile = documentFiles_1_1.value;
1408
- if (documentFile.document) {
1409
- definitionsToValidate = [];
1410
- try {
1411
- for (_a = (e_2 = void 0, __values(documentFile.document.definitions)), _b = _a.next(); !_b.done; _b = _a.next()) {
1412
- definitionNode = _b.value;
1413
- if (definitionNode.kind === Kind.FRAGMENT_DEFINITION) {
1414
- allFragmentMap.set(definitionNode.name.value, definitionNode);
1415
- }
1416
- else {
1417
- definitionsToValidate.push(definitionNode);
1418
- }
1419
- }
1420
- }
1421
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1422
- finally {
1423
- try {
1424
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
1425
- }
1426
- finally { if (e_2) throw e_2.error; }
1427
- }
1428
- documentFileObjectsToValidate.push({
1429
- location: documentFile.location,
1430
- document: {
1431
- kind: Kind.DOCUMENT,
1432
- definitions: definitionsToValidate,
1433
- },
1434
- });
1435
- }
1436
- }
1437
- }
1438
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1439
- finally {
1440
- try {
1441
- if (documentFiles_1_1 && !documentFiles_1_1.done && (_c = documentFiles_1.return)) _c.call(documentFiles_1);
1442
- }
1443
- finally { if (e_1) throw e_1.error; }
1444
- }
1445
- allErrors = [];
1446
- allFragmentsDocument = {
1447
- kind: Kind.DOCUMENT,
1448
- definitions: __spreadArray([], __read(allFragmentMap.values()), false),
1449
- };
1450
- return [4 /*yield*/, Promise.all(documentFileObjectsToValidate.map(function (documentFile) { return __awaiter(_this, void 0, void 0, function () {
1451
- var documentToValidate, errors;
1452
- return __generator(this, function (_a) {
1453
- documentToValidate = concatAST([allFragmentsDocument, documentFile.document]);
1454
- errors = validate(schema, documentToValidate, effectiveRules);
1455
- if (errors.length > 0) {
1456
- allErrors.push({
1457
- filePath: documentFile.location,
1458
- errors: errors,
1459
- });
1460
- }
1461
- return [2 /*return*/];
1462
- });
1463
- }); }))];
1464
- case 1:
1465
- _e.sent();
1466
- return [2 /*return*/, allErrors];
1467
- }
1468
- });
1469
- });
1470
- }
1471
- function checkValidationErrors(loadDocumentErrors) {
1472
- var e_3, _a, e_4, _b, e_5, _c;
1473
- if (loadDocumentErrors.length > 0) {
1474
- var errors = [];
1475
- try {
1476
- for (var loadDocumentErrors_1 = __values(loadDocumentErrors), loadDocumentErrors_1_1 = loadDocumentErrors_1.next(); !loadDocumentErrors_1_1.done; loadDocumentErrors_1_1 = loadDocumentErrors_1.next()) {
1477
- var loadDocumentError = loadDocumentErrors_1_1.value;
1478
- try {
1479
- for (var _d = (e_4 = void 0, __values(loadDocumentError.errors)), _e = _d.next(); !_e.done; _e = _d.next()) {
1480
- var graphQLError = _e.value;
1481
- var error = new Error();
1482
- error.name = 'GraphQLDocumentError';
1483
- error.message = error.name + ": " + graphQLError.message;
1484
- error.stack = error.message;
1485
- if (graphQLError.locations) {
1486
- try {
1487
- for (var _f = (e_5 = void 0, __values(graphQLError.locations)), _g = _f.next(); !_g.done; _g = _f.next()) {
1488
- var location_1 = _g.value;
1489
- error.stack += "\n at " + loadDocumentError.filePath + ":" + location_1.line + ":" + location_1.column;
1490
- }
1491
- }
1492
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1493
- finally {
1494
- try {
1495
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
1496
- }
1497
- finally { if (e_5) throw e_5.error; }
1498
- }
1499
- }
1500
- errors.push(error);
1501
- }
1502
- }
1503
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1504
- finally {
1505
- try {
1506
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
1507
- }
1508
- finally { if (e_4) throw e_4.error; }
1509
- }
1510
- }
1511
- }
1512
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1513
- finally {
1514
- try {
1515
- if (loadDocumentErrors_1_1 && !loadDocumentErrors_1_1.done && (_a = loadDocumentErrors_1.return)) _a.call(loadDocumentErrors_1);
1516
- }
1517
- finally { if (e_3) throw e_3.error; }
1518
- }
1519
- throw new AggregateErrorImpl(errors, "GraphQL Document Validation failed with " + errors.length + " errors;\n " + errors.map(function (error, index) { return "Error " + index + ": " + error.stack; }).join('\n\n'));
1520
- }
1521
- }
1522
- function createDefaultRules() {
1523
- var ignored = ['NoUnusedFragmentsRule', 'NoUnusedVariablesRule', 'KnownDirectivesRule'];
1524
- var v4ignored = ignored.map(function (rule) { return rule.replace(/Rule$/, ''); });
1525
- return specifiedRules.filter(function (f) { return !ignored.includes(f.name) && !v4ignored.includes(f.name); });
1526
- }
1527
-
1528
- function stripBOM(content) {
1529
- content = content.toString();
1530
- // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
1531
- // because the buffer-to-string conversion in `fs.readFileSync()`
1532
- // translates it to FEFF, the UTF-16 BOM.
1533
- if (content.charCodeAt(0) === 0xfeff) {
1534
- content = content.slice(1);
1535
- }
1536
- return content;
1537
- }
1538
- function parseBOM(content) {
1539
- return JSON.parse(stripBOM(content));
1540
- }
1541
- function parseGraphQLJSON(location, jsonContent, options) {
1542
- var parsedJson = parseBOM(jsonContent);
1543
- if (parsedJson.data) {
1544
- parsedJson = parsedJson.data;
1545
- }
1546
- if (parsedJson.kind === 'Document') {
1547
- return {
1548
- location: location,
1549
- document: parsedJson,
1550
- };
1551
- }
1552
- else if (parsedJson.__schema) {
1553
- var schema = buildClientSchema(parsedJson, options);
1554
- return {
1555
- location: location,
1556
- schema: schema,
1557
- };
1558
- }
1559
- else if (typeof parsedJson === 'string') {
1560
- return {
1561
- location: location,
1562
- rawSDL: parsedJson,
1563
- };
1564
- }
1565
- throw new Error("Not valid JSON content");
1566
- }
1567
-
1568
- var MAX_LINE_LENGTH = 80;
1569
- var commentsRegistry = {};
1570
- function resetComments() {
1571
- commentsRegistry = {};
1572
- }
1573
- function collectComment(node) {
1574
- var e_1, _a, e_2, _b, e_3, _c;
1575
- var _d;
1576
- var entityName = (_d = node.name) === null || _d === void 0 ? void 0 : _d.value;
1577
- if (entityName == null) {
1578
- return;
1579
- }
1580
- pushComment(node, entityName);
1581
- switch (node.kind) {
1582
- case 'EnumTypeDefinition':
1583
- if (node.values) {
1584
- try {
1585
- for (var _e = __values(node.values), _f = _e.next(); !_f.done; _f = _e.next()) {
1586
- var value = _f.value;
1587
- pushComment(value, entityName, value.name.value);
1588
- }
1589
- }
1590
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1591
- finally {
1592
- try {
1593
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
1594
- }
1595
- finally { if (e_1) throw e_1.error; }
1596
- }
1597
- }
1598
- break;
1599
- case 'ObjectTypeDefinition':
1600
- case 'InputObjectTypeDefinition':
1601
- case 'InterfaceTypeDefinition':
1602
- if (node.fields) {
1603
- try {
1604
- for (var _g = __values(node.fields), _h = _g.next(); !_h.done; _h = _g.next()) {
1605
- var field = _h.value;
1606
- pushComment(field, entityName, field.name.value);
1607
- if (isFieldDefinitionNode(field) && field.arguments) {
1608
- try {
1609
- for (var _j = (e_3 = void 0, __values(field.arguments)), _k = _j.next(); !_k.done; _k = _j.next()) {
1610
- var arg = _k.value;
1611
- pushComment(arg, entityName, field.name.value, arg.name.value);
1612
- }
1613
- }
1614
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1615
- finally {
1616
- try {
1617
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
1618
- }
1619
- finally { if (e_3) throw e_3.error; }
1620
- }
1621
- }
1622
- }
1623
- }
1624
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1625
- finally {
1626
- try {
1627
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
1628
- }
1629
- finally { if (e_2) throw e_2.error; }
1630
- }
1631
- }
1632
- break;
1633
- }
1634
- }
1635
- function pushComment(node, entity, field, argument) {
1636
- var comment = getDescription(node, { commentDescriptions: true });
1637
- if (typeof comment !== 'string' || comment.length === 0) {
1638
- return;
1639
- }
1640
- var keys = [entity];
1641
- if (field) {
1642
- keys.push(field);
1643
- if (argument) {
1644
- keys.push(argument);
1645
- }
1646
- }
1647
- var path = keys.join('.');
1648
- if (!commentsRegistry[path]) {
1649
- commentsRegistry[path] = [];
1650
- }
1651
- commentsRegistry[path].push(comment);
1652
- }
1653
- function printComment(comment) {
1654
- return '\n# ' + comment.replace(/\n/g, '\n# ');
1655
- }
1656
- /**
1657
- * Copyright (c) 2015-present, Facebook, Inc.
1658
- *
1659
- * This source code is licensed under the MIT license found in the
1660
- * LICENSE file in the root directory of this source tree.
1661
- */
1662
- /**
1663
- * NOTE: ==> This file has been modified just to add comments to the printed AST
1664
- * This is a temp measure, we will move to using the original non modified printer.js ASAP.
1665
- */
1666
- /**
1667
- * Given maybeArray, print an empty string if it is null or empty, otherwise
1668
- * print all items together separated by separator if provided
1669
- */
1670
- function join(maybeArray, separator) {
1671
- return maybeArray ? maybeArray.filter(function (x) { return x; }).join(separator || '') : '';
1672
- }
1673
- function hasMultilineItems(maybeArray) {
1674
- var _a;
1675
- return (_a = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.some(function (str) { return str.includes('\n'); })) !== null && _a !== void 0 ? _a : false;
1676
- }
1677
- function addDescription(cb) {
1678
- return function (node, _key, _parent, path, ancestors) {
1679
- var _a;
1680
- var keys = [];
1681
- var parent = path.reduce(function (prev, key) {
1682
- if (['fields', 'arguments', 'values'].includes(key) && prev.name) {
1683
- keys.push(prev.name.value);
1684
- }
1685
- return prev[key];
1686
- }, ancestors[0]);
1687
- var key = __spreadArray(__spreadArray([], __read(keys), false), [(_a = parent === null || parent === void 0 ? void 0 : parent.name) === null || _a === void 0 ? void 0 : _a.value], false).filter(Boolean).join('.');
1688
- var items = [];
1689
- if (node.kind.includes('Definition') && commentsRegistry[key]) {
1690
- items.push.apply(items, __spreadArray([], __read(commentsRegistry[key]), false));
1691
- }
1692
- return join(__spreadArray(__spreadArray([], __read(items.map(printComment)), false), [node.description, cb(node, _key, _parent, path, ancestors)], false), '\n');
1693
- };
1694
- }
1695
- function indent(maybeString) {
1696
- return maybeString && " " + maybeString.replace(/\n/g, '\n ');
1697
- }
1698
- /**
1699
- * Given array, print each item on its own line, wrapped in an
1700
- * indented "{ }" block.
1701
- */
1702
- function block(array) {
1703
- return array && array.length !== 0 ? "{\n" + indent(join(array, '\n')) + "\n}" : '';
1704
- }
1705
- /**
1706
- * If maybeString is not null or empty, then wrap with start and end, otherwise
1707
- * print an empty string.
1708
- */
1709
- function wrap(start, maybeString, end) {
1710
- return maybeString ? start + maybeString + (end || '') : '';
1711
- }
1712
- /**
1713
- * Print a block string in the indented block form by adding a leading and
1714
- * trailing blank line. However, if a block string starts with whitespace and is
1715
- * a single-line, adding a leading blank line would strip that whitespace.
1716
- */
1717
- function printBlockString(value, isDescription) {
1718
- if (isDescription === void 0) { isDescription = false; }
1719
- var escaped = value.replace(/"""/g, '\\"""');
1720
- return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1
1721
- ? "\"\"\"" + escaped.replace(/"$/, '"\n') + "\"\"\""
1722
- : "\"\"\"\n" + (isDescription ? escaped : indent(escaped)) + "\n\"\"\"";
1723
- }
1724
- var printDocASTReducer = {
1725
- Name: { leave: function (node) { return node.value; } },
1726
- Variable: { leave: function (node) { return '$' + node.name; } },
1727
- // Document
1728
- Document: {
1729
- leave: function (node) { return join(node.definitions, '\n\n'); },
1730
- },
1731
- OperationDefinition: {
1732
- leave: function (node) {
1733
- var varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
1734
- var prefix = join([node.operation, join([node.name, varDefs]), join(node.directives, ' ')], ' ');
1735
- // the query short form.
1736
- return prefix + ' ' + node.selectionSet;
1737
- },
1738
- },
1739
- VariableDefinition: {
1740
- leave: function (_a) {
1741
- var variable = _a.variable, type = _a.type, defaultValue = _a.defaultValue, directives = _a.directives;
1742
- return variable + ': ' + type + wrap(' = ', defaultValue) + wrap(' ', join(directives, ' '));
1743
- },
1744
- },
1745
- SelectionSet: { leave: function (_a) {
1746
- var selections = _a.selections;
1747
- return block(selections);
1748
- } },
1749
- Field: {
1750
- leave: function (_a) {
1751
- var alias = _a.alias, name = _a.name, args = _a.arguments, directives = _a.directives, selectionSet = _a.selectionSet;
1752
- var prefix = wrap('', alias, ': ') + name;
1753
- var argsLine = prefix + wrap('(', join(args, ', '), ')');
1754
- if (argsLine.length > MAX_LINE_LENGTH) {
1755
- argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
1756
- }
1757
- return join([argsLine, join(directives, ' '), selectionSet], ' ');
1758
- },
1759
- },
1760
- Argument: { leave: function (_a) {
1761
- var name = _a.name, value = _a.value;
1762
- return name + ': ' + value;
1763
- } },
1764
- // Fragments
1765
- FragmentSpread: {
1766
- leave: function (_a) {
1767
- var name = _a.name, directives = _a.directives;
1768
- return '...' + name + wrap(' ', join(directives, ' '));
1769
- },
1770
- },
1771
- InlineFragment: {
1772
- leave: function (_a) {
1773
- var typeCondition = _a.typeCondition, directives = _a.directives, selectionSet = _a.selectionSet;
1774
- return join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' ');
1775
- },
1776
- },
1777
- FragmentDefinition: {
1778
- leave: function (_a) {
1779
- var name = _a.name, typeCondition = _a.typeCondition, variableDefinitions = _a.variableDefinitions, directives = _a.directives, selectionSet = _a.selectionSet;
1780
- // Note: fragment variable definitions are experimental and may be changed
1781
- // or removed in the future.
1782
- return "fragment " + name + wrap('(', join(variableDefinitions, ', '), ')') + " " +
1783
- ("on " + typeCondition + " " + wrap('', join(directives, ' '), ' ')) +
1784
- selectionSet;
1785
- },
1786
- },
1787
- // Value
1788
- IntValue: { leave: function (_a) {
1789
- var value = _a.value;
1790
- return value;
1791
- } },
1792
- FloatValue: { leave: function (_a) {
1793
- var value = _a.value;
1794
- return value;
1795
- } },
1796
- StringValue: {
1797
- leave: function (_a) {
1798
- var value = _a.value, isBlockString = _a.block;
1799
- return (isBlockString ? printBlockString(value) : JSON.stringify(value));
1800
- },
1801
- },
1802
- BooleanValue: { leave: function (_a) {
1803
- var value = _a.value;
1804
- return (value ? 'true' : 'false');
1805
- } },
1806
- NullValue: { leave: function () { return 'null'; } },
1807
- EnumValue: { leave: function (_a) {
1808
- var value = _a.value;
1809
- return value;
1810
- } },
1811
- ListValue: { leave: function (_a) {
1812
- var values = _a.values;
1813
- return '[' + join(values, ', ') + ']';
1814
- } },
1815
- ObjectValue: { leave: function (_a) {
1816
- var fields = _a.fields;
1817
- return '{' + join(fields, ', ') + '}';
1818
- } },
1819
- ObjectField: { leave: function (_a) {
1820
- var name = _a.name, value = _a.value;
1821
- return name + ': ' + value;
1822
- } },
1823
- // Directive
1824
- Directive: {
1825
- leave: function (_a) {
1826
- var name = _a.name, args = _a.arguments;
1827
- return '@' + name + wrap('(', join(args, ', '), ')');
1828
- },
1829
- },
1830
- // Type
1831
- NamedType: { leave: function (_a) {
1832
- var name = _a.name;
1833
- return name;
1834
- } },
1835
- ListType: { leave: function (_a) {
1836
- var type = _a.type;
1837
- return '[' + type + ']';
1838
- } },
1839
- NonNullType: { leave: function (_a) {
1840
- var type = _a.type;
1841
- return type + '!';
1842
- } },
1843
- // Type System Definitions
1844
- SchemaDefinition: {
1845
- leave: function (_a) {
1846
- var description = _a.description, directives = _a.directives, operationTypes = _a.operationTypes;
1847
- return wrap('', description, '\n') + join(['schema', join(directives, ' '), block(operationTypes)], ' ');
1848
- },
1849
- },
1850
- OperationTypeDefinition: {
1851
- leave: function (_a) {
1852
- var operation = _a.operation, type = _a.type;
1853
- return operation + ': ' + type;
1854
- },
1855
- },
1856
- ScalarTypeDefinition: {
1857
- leave: function (_a) {
1858
- var description = _a.description, name = _a.name, directives = _a.directives;
1859
- return wrap('', description, '\n') + join(['scalar', name, join(directives, ' ')], ' ');
1860
- },
1861
- },
1862
- ObjectTypeDefinition: {
1863
- leave: function (_a) {
1864
- var description = _a.description, name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
1865
- return wrap('', description, '\n') +
1866
- join(['type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
1867
- },
1868
- },
1869
- FieldDefinition: {
1870
- leave: function (_a) {
1871
- var description = _a.description, name = _a.name, args = _a.arguments, type = _a.type, directives = _a.directives;
1872
- return wrap('', description, '\n') +
1873
- name +
1874
- (hasMultilineItems(args)
1875
- ? wrap('(\n', indent(join(args, '\n')), '\n)')
1876
- : wrap('(', join(args, ', '), ')')) +
1877
- ': ' +
1878
- type +
1879
- wrap(' ', join(directives, ' '));
1880
- },
1881
- },
1882
- InputValueDefinition: {
1883
- leave: function (_a) {
1884
- var description = _a.description, name = _a.name, type = _a.type, defaultValue = _a.defaultValue, directives = _a.directives;
1885
- return wrap('', description, '\n') + join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' ');
1886
- },
1887
- },
1888
- InterfaceTypeDefinition: {
1889
- leave: function (_a) {
1890
- var description = _a.description, name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
1891
- return wrap('', description, '\n') +
1892
- join(['interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
1893
- },
1894
- },
1895
- UnionTypeDefinition: {
1896
- leave: function (_a) {
1897
- var description = _a.description, name = _a.name, directives = _a.directives, types = _a.types;
1898
- return wrap('', description, '\n') + join(['union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' ');
1899
- },
1900
- },
1901
- EnumTypeDefinition: {
1902
- leave: function (_a) {
1903
- var description = _a.description, name = _a.name, directives = _a.directives, values = _a.values;
1904
- return wrap('', description, '\n') + join(['enum', name, join(directives, ' '), block(values)], ' ');
1905
- },
1906
- },
1907
- EnumValueDefinition: {
1908
- leave: function (_a) {
1909
- var description = _a.description, name = _a.name, directives = _a.directives;
1910
- return wrap('', description, '\n') + join([name, join(directives, ' ')], ' ');
1911
- },
1912
- },
1913
- InputObjectTypeDefinition: {
1914
- leave: function (_a) {
1915
- var description = _a.description, name = _a.name, directives = _a.directives, fields = _a.fields;
1916
- return wrap('', description, '\n') + join(['input', name, join(directives, ' '), block(fields)], ' ');
1917
- },
1918
- },
1919
- DirectiveDefinition: {
1920
- leave: function (_a) {
1921
- var description = _a.description, name = _a.name, args = _a.arguments, repeatable = _a.repeatable, locations = _a.locations;
1922
- return wrap('', description, '\n') +
1923
- 'directive @' +
1924
- name +
1925
- (hasMultilineItems(args)
1926
- ? wrap('(\n', indent(join(args, '\n')), '\n)')
1927
- : wrap('(', join(args, ', '), ')')) +
1928
- (repeatable ? ' repeatable' : '') +
1929
- ' on ' +
1930
- join(locations, ' | ');
1931
- },
1932
- },
1933
- SchemaExtension: {
1934
- leave: function (_a) {
1935
- var directives = _a.directives, operationTypes = _a.operationTypes;
1936
- return join(['extend schema', join(directives, ' '), block(operationTypes)], ' ');
1937
- },
1938
- },
1939
- ScalarTypeExtension: {
1940
- leave: function (_a) {
1941
- var name = _a.name, directives = _a.directives;
1942
- return join(['extend scalar', name, join(directives, ' ')], ' ');
1943
- },
1944
- },
1945
- ObjectTypeExtension: {
1946
- leave: function (_a) {
1947
- var name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
1948
- return join(['extend type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
1949
- },
1950
- },
1951
- InterfaceTypeExtension: {
1952
- leave: function (_a) {
1953
- var name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
1954
- return join(['extend interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
1955
- },
1956
- },
1957
- UnionTypeExtension: {
1958
- leave: function (_a) {
1959
- var name = _a.name, directives = _a.directives, types = _a.types;
1960
- return join(['extend union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' ');
1961
- },
1962
- },
1963
- EnumTypeExtension: {
1964
- leave: function (_a) {
1965
- var name = _a.name, directives = _a.directives, values = _a.values;
1966
- return join(['extend enum', name, join(directives, ' '), block(values)], ' ');
1967
- },
1968
- },
1969
- InputObjectTypeExtension: {
1970
- leave: function (_a) {
1971
- var name = _a.name, directives = _a.directives, fields = _a.fields;
1972
- return join(['extend input', name, join(directives, ' '), block(fields)], ' ');
1973
- },
1974
- },
1975
- };
1976
- var printDocASTReducerWithComments = Object.keys(printDocASTReducer).reduce(function (prev, key) {
1977
- var _a;
1978
- return (__assign(__assign({}, prev), (_a = {}, _a[key] = {
1979
- leave: addDescription(printDocASTReducer[key].leave),
1980
- }, _a)));
1981
- }, {});
1982
- /**
1983
- * Converts an AST into a string, using one set of reasonable
1984
- * formatting rules.
1985
- */
1986
- function printWithComments(ast) {
1987
- return visit(ast, printDocASTReducerWithComments);
1988
- }
1989
- function isFieldDefinitionNode(node) {
1990
- return node.kind === 'FieldDefinition';
1991
- }
1992
- // graphql < v13 and > v15 does not export getDescription
1993
- function getDescription(node, options) {
1994
- if (node.description != null) {
1995
- return node.description.value;
1996
- }
1997
- if (options === null || options === void 0 ? void 0 : options.commentDescriptions) {
1998
- var rawValue = getLeadingCommentBlock(node);
1999
- if (rawValue !== undefined) {
2000
- return dedentBlockStringValue("\n" + rawValue);
2001
- }
2002
- }
2003
- }
2004
- function getLeadingCommentBlock(node) {
2005
- var loc = node.loc;
2006
- if (!loc) {
2007
- return;
2008
- }
2009
- var comments = [];
2010
- var token = loc.startToken.prev;
2011
- while (token != null &&
2012
- token.kind === TokenKind.COMMENT &&
2013
- token.next != null &&
2014
- token.prev != null &&
2015
- token.line + 1 === token.next.line &&
2016
- token.line !== token.prev.line) {
2017
- var value = String(token.value);
2018
- comments.push(value);
2019
- token = token.prev;
2020
- }
2021
- return comments.length > 0 ? comments.reverse().join('\n') : undefined;
2022
- }
2023
- function dedentBlockStringValue(rawString) {
2024
- // Expand a block string's raw value into independent lines.
2025
- var lines = rawString.split(/\r\n|[\n\r]/g);
2026
- // Remove common indentation from all lines but first.
2027
- var commonIndent = getBlockStringIndentation(lines);
2028
- if (commonIndent !== 0) {
2029
- for (var i = 1; i < lines.length; i++) {
2030
- lines[i] = lines[i].slice(commonIndent);
2031
- }
2032
- }
2033
- // Remove leading and trailing blank lines.
2034
- while (lines.length > 0 && isBlank(lines[0])) {
2035
- lines.shift();
2036
- }
2037
- while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
2038
- lines.pop();
2039
- }
2040
- // Return a string of the lines joined with U+000A.
2041
- return lines.join('\n');
2042
- }
2043
- /**
2044
- * @internal
2045
- */
2046
- function getBlockStringIndentation(lines) {
2047
- var commonIndent = null;
2048
- for (var i = 1; i < lines.length; i++) {
2049
- var line = lines[i];
2050
- var indent_1 = leadingWhitespace(line);
2051
- if (indent_1 === line.length) {
2052
- continue; // skip empty lines
2053
- }
2054
- if (commonIndent === null || indent_1 < commonIndent) {
2055
- commonIndent = indent_1;
2056
- if (commonIndent === 0) {
2057
- break;
2058
- }
2059
- }
2060
- }
2061
- return commonIndent === null ? 0 : commonIndent;
2062
- }
2063
- function leadingWhitespace(str) {
2064
- var i = 0;
2065
- while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
2066
- i++;
2067
- }
2068
- return i;
2069
- }
2070
- function isBlank(str) {
2071
- return leadingWhitespace(str) === str.length;
2072
- }
2073
-
2074
- function parseGraphQLSDL(location, rawSDL, options) {
2075
- if (options === void 0) { options = {}; }
2076
- var document;
2077
- try {
2078
- if (options.commentDescriptions && rawSDL.includes('#')) {
2079
- document = transformCommentsToDescriptions(rawSDL, options);
2080
- // If noLocation=true, we need to make sure to print and parse it again, to remove locations,
2081
- // since `transformCommentsToDescriptions` must have locations set in order to transform the comments
2082
- // into descriptions.
2083
- if (options.noLocation) {
2084
- document = parse(print(document), options);
2085
- }
2086
- }
2087
- else {
2088
- document = parse(new Source(rawSDL, location), options);
2089
- }
2090
- }
2091
- catch (e) {
2092
- if (e.message.includes('EOF') && rawSDL.replace(/(\#[^*]*)/g, '').trim() === '') {
2093
- document = {
2094
- kind: Kind.DOCUMENT,
2095
- definitions: [],
2096
- };
2097
- }
2098
- else {
2099
- throw e;
2100
- }
2101
- }
2102
- return {
2103
- location: location,
2104
- document: document,
2105
- };
2106
- }
2107
- function transformCommentsToDescriptions(sourceSdl, options) {
2108
- if (options === void 0) { options = {}; }
2109
- var parsedDoc = parse(sourceSdl, __assign(__assign({}, options), { noLocation: false }));
2110
- var modifiedDoc = visit(parsedDoc, {
2111
- leave: function (node) {
2112
- if (isDescribable(node)) {
2113
- var rawValue = getLeadingCommentBlock(node);
2114
- if (rawValue !== undefined) {
2115
- var commentsBlock = dedentBlockStringValue('\n' + rawValue);
2116
- var isBlock = commentsBlock.includes('\n');
2117
- if (!node.description) {
2118
- return __assign(__assign({}, node), { description: {
2119
- kind: Kind.STRING,
2120
- value: commentsBlock,
2121
- block: isBlock,
2122
- } });
2123
- }
2124
- else {
2125
- return __assign(__assign({}, node), { description: __assign(__assign({}, node.description), { value: node.description.value + '\n' + commentsBlock, block: true }) });
2126
- }
2127
- }
2128
- }
2129
- },
2130
- });
2131
- return modifiedDoc;
2132
- }
2133
- function isDescribable(node) {
2134
- return (isTypeSystemDefinitionNode(node) ||
2135
- node.kind === Kind.FIELD_DEFINITION ||
2136
- node.kind === Kind.INPUT_VALUE_DEFINITION ||
2137
- node.kind === Kind.ENUM_VALUE_DEFINITION);
2138
- }
2139
-
2140
- var operationVariables = [];
2141
- var fieldTypeMap = new Map();
2142
- function addOperationVariable(variable) {
2143
- operationVariables.push(variable);
2144
- }
2145
- function resetOperationVariables() {
2146
- operationVariables = [];
2147
- }
2148
- function resetFieldMap() {
2149
- fieldTypeMap = new Map();
2150
- }
2151
- function buildOperationNodeForField(_a) {
2152
- var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, _b = _a.ignore, ignore = _b === void 0 ? [] : _b, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _c = _a.selectedFields, selectedFields = _c === void 0 ? true : _c;
2153
- resetOperationVariables();
2154
- resetFieldMap();
2155
- var rootTypeNames = getRootTypeNames(schema);
2156
- var operationNode = buildOperationAndCollectVariables({
2157
- schema: schema,
2158
- fieldName: field,
2159
- kind: kind,
2160
- models: models || [],
2161
- ignore: ignore,
2162
- depthLimit: depthLimit || Infinity,
2163
- circularReferenceDepth: circularReferenceDepth || 1,
2164
- argNames: argNames,
2165
- selectedFields: selectedFields,
2166
- rootTypeNames: rootTypeNames,
2167
- });
2168
- // attach variables
2169
- operationNode.variableDefinitions = __spreadArray([], __read(operationVariables), false);
2170
- resetOperationVariables();
2171
- resetFieldMap();
2172
- return operationNode;
2173
- }
2174
- function buildOperationAndCollectVariables(_a) {
2175
- var e_1, _b;
2176
- var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
2177
- var type = getDefinedRootType(schema, kind);
2178
- var field = type.getFields()[fieldName];
2179
- var operationName = fieldName + "_" + kind;
2180
- if (field.args) {
2181
- try {
2182
- for (var _c = __values(field.args), _d = _c.next(); !_d.done; _d = _c.next()) {
2183
- var arg = _d.value;
2184
- var argName = arg.name;
2185
- if (!argNames || argNames.includes(argName)) {
2186
- addOperationVariable(resolveVariable(arg, argName));
2187
- }
2188
- }
2189
- }
2190
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2191
- finally {
2192
- try {
2193
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2194
- }
2195
- finally { if (e_1) throw e_1.error; }
2196
- }
2197
- }
2198
- return {
2199
- kind: Kind.OPERATION_DEFINITION,
2200
- operation: kind,
2201
- name: {
2202
- kind: 'Name',
2203
- value: operationName,
2204
- },
2205
- variableDefinitions: [],
2206
- selectionSet: {
2207
- kind: Kind.SELECTION_SET,
2208
- selections: [
2209
- resolveField({
2210
- type: type,
2211
- field: field,
2212
- models: models,
2213
- firstCall: true,
2214
- path: [],
2215
- ancestors: [],
2216
- ignore: ignore,
2217
- depthLimit: depthLimit,
2218
- circularReferenceDepth: circularReferenceDepth,
2219
- schema: schema,
2220
- depth: 0,
2221
- argNames: argNames,
2222
- selectedFields: selectedFields,
2223
- rootTypeNames: rootTypeNames,
2224
- }),
2225
- ],
2226
- },
2227
- };
2228
- }
2229
- function resolveSelectionSet(_a) {
2230
- var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
2231
- if (typeof selectedFields === 'boolean' && depth > depthLimit) {
2232
- return;
2233
- }
2234
- if (isUnionType(type)) {
2235
- var types = type.getTypes();
2236
- return {
2237
- kind: Kind.SELECTION_SET,
2238
- selections: types
2239
- .filter(function (t) {
2240
- return !hasCircularRef(__spreadArray(__spreadArray([], __read(ancestors), false), [t], false), {
2241
- depth: circularReferenceDepth,
2242
- });
2243
- })
2244
- .map(function (t) {
2245
- return {
2246
- kind: Kind.INLINE_FRAGMENT,
2247
- typeCondition: {
2248
- kind: Kind.NAMED_TYPE,
2249
- name: {
2250
- kind: Kind.NAME,
2251
- value: t.name,
2252
- },
2253
- },
2254
- selectionSet: resolveSelectionSet({
2255
- parent: type,
2256
- type: t,
2257
- models: models,
2258
- path: path,
2259
- ancestors: ancestors,
2260
- ignore: ignore,
2261
- depthLimit: depthLimit,
2262
- circularReferenceDepth: circularReferenceDepth,
2263
- schema: schema,
2264
- depth: depth,
2265
- argNames: argNames,
2266
- selectedFields: selectedFields,
2267
- rootTypeNames: rootTypeNames,
2268
- }),
2269
- };
2270
- })
2271
- .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
2272
- };
2273
- }
2274
- if (isInterfaceType(type)) {
2275
- var types = Object.values(schema.getTypeMap()).filter(function (t) { return isObjectType(t) && t.getInterfaces().includes(type); });
2276
- return {
2277
- kind: Kind.SELECTION_SET,
2278
- selections: types
2279
- .filter(function (t) {
2280
- return !hasCircularRef(__spreadArray(__spreadArray([], __read(ancestors), false), [t], false), {
2281
- depth: circularReferenceDepth,
2282
- });
2283
- })
2284
- .map(function (t) {
2285
- return {
2286
- kind: Kind.INLINE_FRAGMENT,
2287
- typeCondition: {
2288
- kind: Kind.NAMED_TYPE,
2289
- name: {
2290
- kind: Kind.NAME,
2291
- value: t.name,
2292
- },
2293
- },
2294
- selectionSet: resolveSelectionSet({
2295
- parent: type,
2296
- type: t,
2297
- models: models,
2298
- path: path,
2299
- ancestors: ancestors,
2300
- ignore: ignore,
2301
- depthLimit: depthLimit,
2302
- circularReferenceDepth: circularReferenceDepth,
2303
- schema: schema,
2304
- depth: depth,
2305
- argNames: argNames,
2306
- selectedFields: selectedFields,
2307
- rootTypeNames: rootTypeNames,
2308
- }),
2309
- };
2310
- })
2311
- .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
2312
- };
2313
- }
2314
- if (isObjectType(type) && !rootTypeNames.has(type.name)) {
2315
- var isIgnored = ignore.includes(type.name) || ignore.includes(parent.name + "." + path[path.length - 1]);
2316
- var isModel = models.includes(type.name);
2317
- if (!firstCall && isModel && !isIgnored) {
2318
- return {
2319
- kind: Kind.SELECTION_SET,
2320
- selections: [
2321
- {
2322
- kind: Kind.FIELD,
2323
- name: {
2324
- kind: Kind.NAME,
2325
- value: 'id',
2326
- },
2327
- },
2328
- ],
2329
- };
2330
- }
2331
- var fields_1 = type.getFields();
2332
- return {
2333
- kind: Kind.SELECTION_SET,
2334
- selections: Object.keys(fields_1)
2335
- .filter(function (fieldName) {
2336
- return !hasCircularRef(__spreadArray(__spreadArray([], __read(ancestors), false), [getNamedType(fields_1[fieldName].type)], false), {
2337
- depth: circularReferenceDepth,
2338
- });
2339
- })
2340
- .map(function (fieldName) {
2341
- var selectedSubFields = typeof selectedFields === 'object' ? selectedFields[fieldName] : true;
2342
- if (selectedSubFields) {
2343
- return resolveField({
2344
- type: type,
2345
- field: fields_1[fieldName],
2346
- models: models,
2347
- path: __spreadArray(__spreadArray([], __read(path), false), [fieldName], false),
2348
- ancestors: ancestors,
2349
- ignore: ignore,
2350
- depthLimit: depthLimit,
2351
- circularReferenceDepth: circularReferenceDepth,
2352
- schema: schema,
2353
- depth: depth,
2354
- argNames: argNames,
2355
- selectedFields: selectedSubFields,
2356
- rootTypeNames: rootTypeNames,
2357
- });
2358
- }
2359
- return null;
2360
- })
2361
- .filter(function (f) {
2362
- var _a, _b;
2363
- if (f == null) {
2364
- return false;
2365
- }
2366
- else if ('selectionSet' in f) {
2367
- return !!((_b = (_a = f.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length);
2368
- }
2369
- return true;
2370
- }),
2371
- };
2372
- }
2373
- }
2374
- function resolveVariable(arg, name) {
2375
- function resolveVariableType(type) {
2376
- if (isListType(type)) {
2377
- return {
2378
- kind: Kind.LIST_TYPE,
2379
- type: resolveVariableType(type.ofType),
2380
- };
2381
- }
2382
- if (isNonNullType(type)) {
2383
- return {
2384
- kind: Kind.NON_NULL_TYPE,
2385
- // for v16 compatibility
2386
- type: resolveVariableType(type.ofType),
2387
- };
2388
- }
2389
- return {
2390
- kind: Kind.NAMED_TYPE,
2391
- name: {
2392
- kind: Kind.NAME,
2393
- value: type.name,
2394
- },
2395
- };
2396
- }
2397
- return {
2398
- kind: Kind.VARIABLE_DEFINITION,
2399
- variable: {
2400
- kind: Kind.VARIABLE,
2401
- name: {
2402
- kind: Kind.NAME,
2403
- value: name || arg.name,
2404
- },
2405
- },
2406
- type: resolveVariableType(arg.type),
2407
- };
2408
- }
2409
- function getArgumentName(name, path) {
2410
- return __spreadArray(__spreadArray([], __read(path), false), [name], false).join('_');
2411
- }
2412
- function resolveField(_a) {
2413
- var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
2414
- var namedType = getNamedType(field.type);
2415
- var args = [];
2416
- var removeField = false;
2417
- if (field.args && field.args.length) {
2418
- args = field.args
2419
- .map(function (arg) {
2420
- var argumentName = getArgumentName(arg.name, path);
2421
- if (argNames && !argNames.includes(argumentName)) {
2422
- if (isNonNullType(arg.type)) {
2423
- removeField = true;
2424
- }
2425
- return null;
2426
- }
2427
- if (!firstCall) {
2428
- addOperationVariable(resolveVariable(arg, argumentName));
2429
- }
2430
- return {
2431
- kind: Kind.ARGUMENT,
2432
- name: {
2433
- kind: Kind.NAME,
2434
- value: arg.name,
2435
- },
2436
- value: {
2437
- kind: Kind.VARIABLE,
2438
- name: {
2439
- kind: Kind.NAME,
2440
- value: getArgumentName(arg.name, path),
2441
- },
2442
- },
2443
- };
2444
- })
2445
- .filter(Boolean);
2446
- }
2447
- if (removeField) {
2448
- return null;
2449
- }
2450
- var fieldPath = __spreadArray(__spreadArray([], __read(path), false), [field.name], false);
2451
- var fieldPathStr = fieldPath.join('.');
2452
- var fieldName = field.name;
2453
- if (fieldTypeMap.has(fieldPathStr) && fieldTypeMap.get(fieldPathStr) !== field.type.toString()) {
2454
- fieldName += field.type.toString().replace('!', 'NonNull');
2455
- }
2456
- fieldTypeMap.set(fieldPathStr, field.type.toString());
2457
- if (!isScalarType(namedType) && !isEnumType(namedType)) {
2458
- return __assign(__assign({ kind: Kind.FIELD, name: {
2459
- kind: Kind.NAME,
2460
- value: field.name,
2461
- } }, (fieldName !== field.name && { alias: { kind: Kind.NAME, value: fieldName } })), { selectionSet: resolveSelectionSet({
2462
- parent: type,
2463
- type: namedType,
2464
- models: models,
2465
- firstCall: firstCall,
2466
- path: fieldPath,
2467
- ancestors: __spreadArray(__spreadArray([], __read(ancestors), false), [type], false),
2468
- ignore: ignore,
2469
- depthLimit: depthLimit,
2470
- circularReferenceDepth: circularReferenceDepth,
2471
- schema: schema,
2472
- depth: depth + 1,
2473
- argNames: argNames,
2474
- selectedFields: selectedFields,
2475
- rootTypeNames: rootTypeNames,
2476
- }) || undefined, arguments: args });
2477
- }
2478
- return __assign(__assign({ kind: Kind.FIELD, name: {
2479
- kind: Kind.NAME,
2480
- value: field.name,
2481
- } }, (fieldName !== field.name && { alias: { kind: Kind.NAME, value: fieldName } })), { arguments: args });
2482
- }
2483
- function hasCircularRef(types, config) {
2484
- if (config === void 0) { config = {
2485
- depth: 1,
2486
- }; }
2487
- var type = types[types.length - 1];
2488
- if (isScalarType(type)) {
2489
- return false;
2490
- }
2491
- var size = types.filter(function (t) { return t.name === type.name; }).length;
2492
- return size > config.depth;
2493
- }
2494
-
2495
- var MapperKind;
2496
- (function (MapperKind) {
2497
- MapperKind["TYPE"] = "MapperKind.TYPE";
2498
- MapperKind["SCALAR_TYPE"] = "MapperKind.SCALAR_TYPE";
2499
- MapperKind["ENUM_TYPE"] = "MapperKind.ENUM_TYPE";
2500
- MapperKind["COMPOSITE_TYPE"] = "MapperKind.COMPOSITE_TYPE";
2501
- MapperKind["OBJECT_TYPE"] = "MapperKind.OBJECT_TYPE";
2502
- MapperKind["INPUT_OBJECT_TYPE"] = "MapperKind.INPUT_OBJECT_TYPE";
2503
- MapperKind["ABSTRACT_TYPE"] = "MapperKind.ABSTRACT_TYPE";
2504
- MapperKind["UNION_TYPE"] = "MapperKind.UNION_TYPE";
2505
- MapperKind["INTERFACE_TYPE"] = "MapperKind.INTERFACE_TYPE";
2506
- MapperKind["ROOT_OBJECT"] = "MapperKind.ROOT_OBJECT";
2507
- MapperKind["QUERY"] = "MapperKind.QUERY";
2508
- MapperKind["MUTATION"] = "MapperKind.MUTATION";
2509
- MapperKind["SUBSCRIPTION"] = "MapperKind.SUBSCRIPTION";
2510
- MapperKind["DIRECTIVE"] = "MapperKind.DIRECTIVE";
2511
- MapperKind["FIELD"] = "MapperKind.FIELD";
2512
- MapperKind["COMPOSITE_FIELD"] = "MapperKind.COMPOSITE_FIELD";
2513
- MapperKind["OBJECT_FIELD"] = "MapperKind.OBJECT_FIELD";
2514
- MapperKind["ROOT_FIELD"] = "MapperKind.ROOT_FIELD";
2515
- MapperKind["QUERY_ROOT_FIELD"] = "MapperKind.QUERY_ROOT_FIELD";
2516
- MapperKind["MUTATION_ROOT_FIELD"] = "MapperKind.MUTATION_ROOT_FIELD";
2517
- MapperKind["SUBSCRIPTION_ROOT_FIELD"] = "MapperKind.SUBSCRIPTION_ROOT_FIELD";
2518
- MapperKind["INTERFACE_FIELD"] = "MapperKind.INTERFACE_FIELD";
2519
- MapperKind["INPUT_OBJECT_FIELD"] = "MapperKind.INPUT_OBJECT_FIELD";
2520
- MapperKind["ARGUMENT"] = "MapperKind.ARGUMENT";
2521
- MapperKind["ENUM_VALUE"] = "MapperKind.ENUM_VALUE";
2522
- })(MapperKind || (MapperKind = {}));
2523
-
2524
- function getObjectTypeFromTypeMap(typeMap, type) {
2525
- if (type) {
2526
- var maybeObjectType = typeMap[type.name];
2527
- if (isObjectType(maybeObjectType)) {
2528
- return maybeObjectType;
2529
- }
2530
- }
2531
- }
2532
-
2533
- function createNamedStub(name, type) {
2534
- var constructor;
2535
- if (type === 'object') {
2536
- constructor = GraphQLObjectType;
2537
- }
2538
- else if (type === 'interface') {
2539
- constructor = GraphQLInterfaceType;
2540
- }
2541
- else {
2542
- constructor = GraphQLInputObjectType;
2543
- }
2544
- return new constructor({
2545
- name: name,
2546
- fields: {
2547
- _fake: {
2548
- type: GraphQLString,
2549
- },
2550
- },
2551
- });
2552
- }
2553
- function createStub(node, type) {
2554
- switch (node.kind) {
2555
- case Kind.LIST_TYPE:
2556
- return new GraphQLList(createStub(node.type, type));
2557
- case Kind.NON_NULL_TYPE:
2558
- return new GraphQLNonNull(createStub(node.type, type));
2559
- default:
2560
- if (type === 'output') {
2561
- return createNamedStub(node.name.value, 'object');
2562
- }
2563
- return createNamedStub(node.name.value, 'input');
2564
- }
2565
- }
2566
- function isNamedStub(type) {
2567
- if ('getFields' in type) {
2568
- var fields = type.getFields();
2569
- // eslint-disable-next-line no-unreachable-loop
2570
- for (var fieldName in fields) {
2571
- var field = fields[fieldName];
2572
- return field.name === '_fake';
2573
- }
2574
- }
2575
- return false;
2576
- }
2577
- function getBuiltInForStub(type) {
2578
- switch (type.name) {
2579
- case GraphQLInt.name:
2580
- return GraphQLInt;
2581
- case GraphQLFloat.name:
2582
- return GraphQLFloat;
2583
- case GraphQLString.name:
2584
- return GraphQLString;
2585
- case GraphQLBoolean.name:
2586
- return GraphQLBoolean;
2587
- case GraphQLID.name:
2588
- return GraphQLID;
2589
- default:
2590
- return type;
2591
- }
2592
- }
2593
-
2594
- function rewireTypes(originalTypeMap, directives) {
2595
- var referenceTypeMap = Object.create(null);
2596
- for (var typeName in originalTypeMap) {
2597
- referenceTypeMap[typeName] = originalTypeMap[typeName];
2598
- }
2599
- var newTypeMap = Object.create(null);
2600
- for (var typeName in referenceTypeMap) {
2601
- var namedType = referenceTypeMap[typeName];
2602
- if (namedType == null || typeName.startsWith('__')) {
2603
- continue;
2604
- }
2605
- var newName = namedType.name;
2606
- if (newName.startsWith('__')) {
2607
- continue;
2608
- }
2609
- if (newTypeMap[newName] != null) {
2610
- throw new Error("Duplicate schema type name " + newName);
2611
- }
2612
- newTypeMap[newName] = namedType;
2613
- }
2614
- for (var typeName in newTypeMap) {
2615
- newTypeMap[typeName] = rewireNamedType(newTypeMap[typeName]);
2616
- }
2617
- var newDirectives = directives.map(function (directive) { return rewireDirective(directive); });
2618
- return {
2619
- typeMap: newTypeMap,
2620
- directives: newDirectives,
2621
- };
2622
- function rewireDirective(directive) {
2623
- if (isSpecifiedDirective(directive)) {
2624
- return directive;
2625
- }
2626
- var directiveConfig = directive.toConfig();
2627
- directiveConfig.args = rewireArgs(directiveConfig.args);
2628
- return new GraphQLDirective(directiveConfig);
2629
- }
2630
- function rewireArgs(args) {
2631
- var rewiredArgs = {};
2632
- for (var argName in args) {
2633
- var arg = args[argName];
2634
- var rewiredArgType = rewireType(arg.type);
2635
- if (rewiredArgType != null) {
2636
- arg.type = rewiredArgType;
2637
- rewiredArgs[argName] = arg;
2638
- }
2639
- }
2640
- return rewiredArgs;
2641
- }
2642
- function rewireNamedType(type) {
2643
- if (isObjectType(type)) {
2644
- var config_1 = type.toConfig();
2645
- var newConfig = __assign(__assign({}, config_1), { fields: function () { return rewireFields(config_1.fields); }, interfaces: function () { return rewireNamedTypes(config_1.interfaces); } });
2646
- return new GraphQLObjectType(newConfig);
2647
- }
2648
- else if (isInterfaceType(type)) {
2649
- var config_2 = type.toConfig();
2650
- var newConfig = __assign(__assign({}, config_2), { fields: function () { return rewireFields(config_2.fields); } });
2651
- if ('interfaces' in newConfig) {
2652
- newConfig.interfaces = function () {
2653
- return rewireNamedTypes(config_2.interfaces);
2654
- };
2655
- }
2656
- return new GraphQLInterfaceType(newConfig);
2657
- }
2658
- else if (isUnionType(type)) {
2659
- var config_3 = type.toConfig();
2660
- var newConfig = __assign(__assign({}, config_3), { types: function () { return rewireNamedTypes(config_3.types); } });
2661
- return new GraphQLUnionType(newConfig);
2662
- }
2663
- else if (isInputObjectType(type)) {
2664
- var config_4 = type.toConfig();
2665
- var newConfig = __assign(__assign({}, config_4), { fields: function () { return rewireInputFields(config_4.fields); } });
2666
- return new GraphQLInputObjectType(newConfig);
2667
- }
2668
- else if (isEnumType(type)) {
2669
- var enumConfig = type.toConfig();
2670
- return new GraphQLEnumType(enumConfig);
2671
- }
2672
- else if (isScalarType(type)) {
2673
- if (isSpecifiedScalarType(type)) {
2674
- return type;
2675
- }
2676
- var scalarConfig = type.toConfig();
2677
- return new GraphQLScalarType(scalarConfig);
2678
- }
2679
- throw new Error("Unexpected schema type: " + type);
2680
- }
2681
- function rewireFields(fields) {
2682
- var rewiredFields = {};
2683
- for (var fieldName in fields) {
2684
- var field = fields[fieldName];
2685
- var rewiredFieldType = rewireType(field.type);
2686
- if (rewiredFieldType != null && field.args) {
2687
- field.type = rewiredFieldType;
2688
- field.args = rewireArgs(field.args);
2689
- rewiredFields[fieldName] = field;
2690
- }
2691
- }
2692
- return rewiredFields;
2693
- }
2694
- function rewireInputFields(fields) {
2695
- var rewiredFields = {};
2696
- for (var fieldName in fields) {
2697
- var field = fields[fieldName];
2698
- var rewiredFieldType = rewireType(field.type);
2699
- if (rewiredFieldType != null) {
2700
- field.type = rewiredFieldType;
2701
- rewiredFields[fieldName] = field;
2702
- }
2703
- }
2704
- return rewiredFields;
2705
- }
2706
- function rewireNamedTypes(namedTypes) {
2707
- var e_1, _a;
2708
- var rewiredTypes = [];
2709
- try {
2710
- for (var namedTypes_1 = __values(namedTypes), namedTypes_1_1 = namedTypes_1.next(); !namedTypes_1_1.done; namedTypes_1_1 = namedTypes_1.next()) {
2711
- var namedType = namedTypes_1_1.value;
2712
- var rewiredType = rewireType(namedType);
2713
- if (rewiredType != null) {
2714
- rewiredTypes.push(rewiredType);
2715
- }
2716
- }
2717
- }
2718
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2719
- finally {
2720
- try {
2721
- if (namedTypes_1_1 && !namedTypes_1_1.done && (_a = namedTypes_1.return)) _a.call(namedTypes_1);
2722
- }
2723
- finally { if (e_1) throw e_1.error; }
2724
- }
2725
- return rewiredTypes;
2726
- }
2727
- function rewireType(type) {
2728
- if (isListType(type)) {
2729
- var rewiredType = rewireType(type.ofType);
2730
- return rewiredType != null ? new GraphQLList(rewiredType) : null;
2731
- }
2732
- else if (isNonNullType(type)) {
2733
- var rewiredType = rewireType(type.ofType);
2734
- return rewiredType != null ? new GraphQLNonNull(rewiredType) : null;
2735
- }
2736
- else if (isNamedType(type)) {
2737
- var rewiredType = referenceTypeMap[type.name];
2738
- if (rewiredType === undefined) {
2739
- rewiredType = isNamedStub(type) ? getBuiltInForStub(type) : rewireNamedType(type);
2740
- newTypeMap[rewiredType.name] = referenceTypeMap[type.name] = rewiredType;
2741
- }
2742
- return rewiredType != null ? newTypeMap[rewiredType.name] : null;
2743
- }
2744
- return null;
2745
- }
2746
- }
2747
-
2748
- function transformInputValue(type, value, inputLeafValueTransformer, inputObjectValueTransformer) {
2749
- if (inputLeafValueTransformer === void 0) { inputLeafValueTransformer = null; }
2750
- if (inputObjectValueTransformer === void 0) { inputObjectValueTransformer = null; }
2751
- if (value == null) {
2752
- return value;
2753
- }
2754
- var nullableType = getNullableType(type);
2755
- if (isLeafType(nullableType)) {
2756
- return inputLeafValueTransformer != null ? inputLeafValueTransformer(nullableType, value) : value;
2757
- }
2758
- else if (isListType(nullableType)) {
2759
- return value.map(function (listMember) {
2760
- return transformInputValue(nullableType.ofType, listMember, inputLeafValueTransformer, inputObjectValueTransformer);
2761
- });
2762
- }
2763
- else if (isInputObjectType(nullableType)) {
2764
- var fields = nullableType.getFields();
2765
- var newValue = {};
2766
- for (var key in value) {
2767
- var field = fields[key];
2768
- if (field != null) {
2769
- newValue[key] = transformInputValue(field.type, value[key], inputLeafValueTransformer, inputObjectValueTransformer);
2770
- }
2771
- }
2772
- return inputObjectValueTransformer != null ? inputObjectValueTransformer(nullableType, newValue) : newValue;
2773
- }
2774
- // unreachable, no other possible return value
2775
- }
2776
- function serializeInputValue(type, value) {
2777
- return transformInputValue(type, value, function (t, v) { return t.serialize(v); });
2778
- }
2779
- function parseInputValue(type, value) {
2780
- return transformInputValue(type, value, function (t, v) { return t.parseValue(v); });
2781
- }
2782
- function parseInputValueLiteral(type, value) {
2783
- return transformInputValue(type, value, function (t, v) { return t.parseLiteral(v, {}); });
2784
- }
2785
-
2786
- function mapSchema(schema, schemaMapper) {
2787
- if (schemaMapper === void 0) { schemaMapper = {}; }
2788
- var newTypeMap = mapArguments(mapFields(mapTypes(mapDefaultValues(mapEnumValues(mapTypes(mapDefaultValues(schema.getTypeMap(), schema, serializeInputValue), schema, schemaMapper, function (type) {
2789
- return isLeafType(type);
2790
- }), schema, schemaMapper), schema, parseInputValue), schema, schemaMapper, function (type) { return !isLeafType(type); }), schema, schemaMapper), schema, schemaMapper);
2791
- var originalDirectives = schema.getDirectives();
2792
- var newDirectives = mapDirectives(originalDirectives, schema, schemaMapper);
2793
- var _a = rewireTypes(newTypeMap, newDirectives), typeMap = _a.typeMap, directives = _a.directives;
2794
- return new GraphQLSchema(__assign(__assign({}, schema.toConfig()), { query: getObjectTypeFromTypeMap(typeMap, getObjectTypeFromTypeMap(newTypeMap, schema.getQueryType())), mutation: getObjectTypeFromTypeMap(typeMap, getObjectTypeFromTypeMap(newTypeMap, schema.getMutationType())), subscription: getObjectTypeFromTypeMap(typeMap, getObjectTypeFromTypeMap(newTypeMap, schema.getSubscriptionType())), types: Object.values(typeMap), directives: directives }));
2795
- }
2796
- function mapTypes(originalTypeMap, schema, schemaMapper, testFn) {
2797
- if (testFn === void 0) { testFn = function () { return true; }; }
2798
- var newTypeMap = {};
2799
- for (var typeName in originalTypeMap) {
2800
- if (!typeName.startsWith('__')) {
2801
- var originalType = originalTypeMap[typeName];
2802
- if (originalType == null || !testFn(originalType)) {
2803
- newTypeMap[typeName] = originalType;
2804
- continue;
2805
- }
2806
- var typeMapper = getTypeMapper(schema, schemaMapper, typeName);
2807
- if (typeMapper == null) {
2808
- newTypeMap[typeName] = originalType;
2809
- continue;
2810
- }
2811
- var maybeNewType = typeMapper(originalType, schema);
2812
- if (maybeNewType === undefined) {
2813
- newTypeMap[typeName] = originalType;
2814
- continue;
2815
- }
2816
- newTypeMap[typeName] = maybeNewType;
2817
- }
2818
- }
2819
- return newTypeMap;
2820
- }
2821
- function mapEnumValues(originalTypeMap, schema, schemaMapper) {
2822
- var _a;
2823
- var enumValueMapper = getEnumValueMapper(schemaMapper);
2824
- if (!enumValueMapper) {
2825
- return originalTypeMap;
2826
- }
2827
- return mapTypes(originalTypeMap, schema, (_a = {},
2828
- _a[MapperKind.ENUM_TYPE] = function (type) {
2829
- var config = type.toConfig();
2830
- var originalEnumValueConfigMap = config.values;
2831
- var newEnumValueConfigMap = {};
2832
- for (var externalValue in originalEnumValueConfigMap) {
2833
- var originalEnumValueConfig = originalEnumValueConfigMap[externalValue];
2834
- var mappedEnumValue = enumValueMapper(originalEnumValueConfig, type.name, schema, externalValue);
2835
- if (mappedEnumValue === undefined) {
2836
- newEnumValueConfigMap[externalValue] = originalEnumValueConfig;
2837
- }
2838
- else if (Array.isArray(mappedEnumValue)) {
2839
- var _a = __read(mappedEnumValue, 2), newExternalValue = _a[0], newEnumValueConfig = _a[1];
2840
- newEnumValueConfigMap[newExternalValue] =
2841
- newEnumValueConfig === undefined ? originalEnumValueConfig : newEnumValueConfig;
2842
- }
2843
- else if (mappedEnumValue !== null) {
2844
- newEnumValueConfigMap[externalValue] = mappedEnumValue;
2845
- }
2846
- }
2847
- return correctASTNodes(new GraphQLEnumType(__assign(__assign({}, config), { values: newEnumValueConfigMap })));
2848
- },
2849
- _a), function (type) { return isEnumType(type); });
2850
- }
2851
- function mapDefaultValues(originalTypeMap, schema, fn) {
2852
- var _a, _b;
2853
- var newTypeMap = mapArguments(originalTypeMap, schema, (_a = {},
2854
- _a[MapperKind.ARGUMENT] = function (argumentConfig) {
2855
- if (argumentConfig.defaultValue === undefined) {
2856
- return argumentConfig;
2857
- }
2858
- var maybeNewType = getNewType(originalTypeMap, argumentConfig.type);
2859
- if (maybeNewType != null) {
2860
- return __assign(__assign({}, argumentConfig), { defaultValue: fn(maybeNewType, argumentConfig.defaultValue) });
2861
- }
2862
- },
2863
- _a));
2864
- return mapFields(newTypeMap, schema, (_b = {},
2865
- _b[MapperKind.INPUT_OBJECT_FIELD] = function (inputFieldConfig) {
2866
- if (inputFieldConfig.defaultValue === undefined) {
2867
- return inputFieldConfig;
2868
- }
2869
- var maybeNewType = getNewType(newTypeMap, inputFieldConfig.type);
2870
- if (maybeNewType != null) {
2871
- return __assign(__assign({}, inputFieldConfig), { defaultValue: fn(maybeNewType, inputFieldConfig.defaultValue) });
2872
- }
2873
- },
2874
- _b));
2875
- }
2876
- function getNewType(newTypeMap, type) {
2877
- if (isListType(type)) {
2878
- var newType = getNewType(newTypeMap, type.ofType);
2879
- return newType != null ? new GraphQLList(newType) : null;
2880
- }
2881
- else if (isNonNullType(type)) {
2882
- var newType = getNewType(newTypeMap, type.ofType);
2883
- return newType != null ? new GraphQLNonNull(newType) : null;
2884
- }
2885
- else if (isNamedType(type)) {
2886
- var newType = newTypeMap[type.name];
2887
- return newType != null ? newType : null;
2888
- }
2889
- return null;
2890
- }
2891
- function mapFields(originalTypeMap, schema, schemaMapper) {
2892
- var newTypeMap = {};
2893
- for (var typeName in originalTypeMap) {
2894
- if (!typeName.startsWith('__')) {
2895
- var originalType = originalTypeMap[typeName];
2896
- if (!isObjectType(originalType) && !isInterfaceType(originalType) && !isInputObjectType(originalType)) {
2897
- newTypeMap[typeName] = originalType;
2898
- continue;
2899
- }
2900
- var fieldMapper = getFieldMapper(schema, schemaMapper, typeName);
2901
- if (fieldMapper == null) {
2902
- newTypeMap[typeName] = originalType;
2903
- continue;
2904
- }
2905
- var config = originalType.toConfig();
2906
- var originalFieldConfigMap = config.fields;
2907
- var newFieldConfigMap = {};
2908
- for (var fieldName in originalFieldConfigMap) {
2909
- var originalFieldConfig = originalFieldConfigMap[fieldName];
2910
- var mappedField = fieldMapper(originalFieldConfig, fieldName, typeName, schema);
2911
- if (mappedField === undefined) {
2912
- newFieldConfigMap[fieldName] = originalFieldConfig;
2913
- }
2914
- else if (Array.isArray(mappedField)) {
2915
- var _a = __read(mappedField, 2), newFieldName = _a[0], newFieldConfig = _a[1];
2916
- if (newFieldConfig.astNode != null) {
2917
- newFieldConfig.astNode = __assign(__assign({}, newFieldConfig.astNode), { name: __assign(__assign({}, newFieldConfig.astNode.name), { value: newFieldName }) });
2918
- }
2919
- newFieldConfigMap[newFieldName] = newFieldConfig === undefined ? originalFieldConfig : newFieldConfig;
2920
- }
2921
- else if (mappedField !== null) {
2922
- newFieldConfigMap[fieldName] = mappedField;
2923
- }
2924
- }
2925
- if (isObjectType(originalType)) {
2926
- newTypeMap[typeName] = correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
2927
- }
2928
- else if (isInterfaceType(originalType)) {
2929
- newTypeMap[typeName] = correctASTNodes(new GraphQLInterfaceType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
2930
- }
2931
- else {
2932
- newTypeMap[typeName] = correctASTNodes(new GraphQLInputObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
2933
- }
2934
- }
2935
- }
2936
- return newTypeMap;
2937
- }
2938
- function mapArguments(originalTypeMap, schema, schemaMapper) {
2939
- var e_1, _a;
2940
- var newTypeMap = {};
2941
- for (var typeName in originalTypeMap) {
2942
- if (!typeName.startsWith('__')) {
2943
- var originalType = originalTypeMap[typeName];
2944
- if (!isObjectType(originalType) && !isInterfaceType(originalType)) {
2945
- newTypeMap[typeName] = originalType;
2946
- continue;
2947
- }
2948
- var argumentMapper = getArgumentMapper(schemaMapper);
2949
- if (argumentMapper == null) {
2950
- newTypeMap[typeName] = originalType;
2951
- continue;
2952
- }
2953
- var config = originalType.toConfig();
2954
- var originalFieldConfigMap = config.fields;
2955
- var newFieldConfigMap = {};
2956
- for (var fieldName in originalFieldConfigMap) {
2957
- var originalFieldConfig = originalFieldConfigMap[fieldName];
2958
- var originalArgumentConfigMap = originalFieldConfig.args;
2959
- if (originalArgumentConfigMap == null) {
2960
- newFieldConfigMap[fieldName] = originalFieldConfig;
2961
- continue;
2962
- }
2963
- var argumentNames = Object.keys(originalArgumentConfigMap);
2964
- if (!argumentNames.length) {
2965
- newFieldConfigMap[fieldName] = originalFieldConfig;
2966
- continue;
2967
- }
2968
- var newArgumentConfigMap = {};
2969
- try {
2970
- for (var argumentNames_1 = (e_1 = void 0, __values(argumentNames)), argumentNames_1_1 = argumentNames_1.next(); !argumentNames_1_1.done; argumentNames_1_1 = argumentNames_1.next()) {
2971
- var argumentName = argumentNames_1_1.value;
2972
- var originalArgumentConfig = originalArgumentConfigMap[argumentName];
2973
- var mappedArgument = argumentMapper(originalArgumentConfig, fieldName, typeName, schema);
2974
- if (mappedArgument === undefined) {
2975
- newArgumentConfigMap[argumentName] = originalArgumentConfig;
2976
- }
2977
- else if (Array.isArray(mappedArgument)) {
2978
- var _b = __read(mappedArgument, 2), newArgumentName = _b[0], newArgumentConfig = _b[1];
2979
- newArgumentConfigMap[newArgumentName] = newArgumentConfig;
2980
- }
2981
- else if (mappedArgument !== null) {
2982
- newArgumentConfigMap[argumentName] = mappedArgument;
2983
- }
2984
- }
2985
- }
2986
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2987
- finally {
2988
- try {
2989
- if (argumentNames_1_1 && !argumentNames_1_1.done && (_a = argumentNames_1.return)) _a.call(argumentNames_1);
2990
- }
2991
- finally { if (e_1) throw e_1.error; }
2992
- }
2993
- newFieldConfigMap[fieldName] = __assign(__assign({}, originalFieldConfig), { args: newArgumentConfigMap });
2994
- }
2995
- if (isObjectType(originalType)) {
2996
- newTypeMap[typeName] = new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap }));
2997
- }
2998
- else if (isInterfaceType(originalType)) {
2999
- newTypeMap[typeName] = new GraphQLInterfaceType(__assign(__assign({}, config), { fields: newFieldConfigMap }));
3000
- }
3001
- else {
3002
- newTypeMap[typeName] = new GraphQLInputObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap }));
3003
- }
3004
- }
3005
- }
3006
- return newTypeMap;
3007
- }
3008
- function mapDirectives(originalDirectives, schema, schemaMapper) {
3009
- var e_2, _a;
3010
- var directiveMapper = getDirectiveMapper(schemaMapper);
3011
- if (directiveMapper == null) {
3012
- return originalDirectives.slice();
3013
- }
3014
- var newDirectives = [];
3015
- try {
3016
- for (var originalDirectives_1 = __values(originalDirectives), originalDirectives_1_1 = originalDirectives_1.next(); !originalDirectives_1_1.done; originalDirectives_1_1 = originalDirectives_1.next()) {
3017
- var directive = originalDirectives_1_1.value;
3018
- var mappedDirective = directiveMapper(directive, schema);
3019
- if (mappedDirective === undefined) {
3020
- newDirectives.push(directive);
3021
- }
3022
- else if (mappedDirective !== null) {
3023
- newDirectives.push(mappedDirective);
3024
- }
3025
- }
3026
- }
3027
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3028
- finally {
3029
- try {
3030
- if (originalDirectives_1_1 && !originalDirectives_1_1.done && (_a = originalDirectives_1.return)) _a.call(originalDirectives_1);
3031
- }
3032
- finally { if (e_2) throw e_2.error; }
3033
- }
3034
- return newDirectives;
3035
- }
3036
- function getTypeSpecifiers(schema, typeName) {
3037
- var _a, _b, _c;
3038
- var type = schema.getType(typeName);
3039
- var specifiers = [MapperKind.TYPE];
3040
- if (isObjectType(type)) {
3041
- specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.OBJECT_TYPE);
3042
- if (typeName === ((_a = schema.getQueryType()) === null || _a === void 0 ? void 0 : _a.name)) {
3043
- specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.QUERY);
3044
- }
3045
- else if (typeName === ((_b = schema.getMutationType()) === null || _b === void 0 ? void 0 : _b.name)) {
3046
- specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.MUTATION);
3047
- }
3048
- else if (typeName === ((_c = schema.getSubscriptionType()) === null || _c === void 0 ? void 0 : _c.name)) {
3049
- specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.SUBSCRIPTION);
3050
- }
3051
- }
3052
- else if (isInputObjectType(type)) {
3053
- specifiers.push(MapperKind.INPUT_OBJECT_TYPE);
3054
- }
3055
- else if (isInterfaceType(type)) {
3056
- specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.ABSTRACT_TYPE, MapperKind.INTERFACE_TYPE);
3057
- }
3058
- else if (isUnionType(type)) {
3059
- specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.ABSTRACT_TYPE, MapperKind.UNION_TYPE);
3060
- }
3061
- else if (isEnumType(type)) {
3062
- specifiers.push(MapperKind.ENUM_TYPE);
3063
- }
3064
- else if (isScalarType(type)) {
3065
- specifiers.push(MapperKind.SCALAR_TYPE);
3066
- }
3067
- return specifiers;
3068
- }
3069
- function getTypeMapper(schema, schemaMapper, typeName) {
3070
- var specifiers = getTypeSpecifiers(schema, typeName);
3071
- var typeMapper;
3072
- var stack = __spreadArray([], __read(specifiers), false);
3073
- while (!typeMapper && stack.length > 0) {
3074
- // It is safe to use the ! operator here as we check the length.
3075
- var next = stack.pop();
3076
- typeMapper = schemaMapper[next];
3077
- }
3078
- return typeMapper != null ? typeMapper : null;
3079
- }
3080
- function getFieldSpecifiers(schema, typeName) {
3081
- var _a, _b, _c;
3082
- var type = schema.getType(typeName);
3083
- var specifiers = [MapperKind.FIELD];
3084
- if (isObjectType(type)) {
3085
- specifiers.push(MapperKind.COMPOSITE_FIELD, MapperKind.OBJECT_FIELD);
3086
- if (typeName === ((_a = schema.getQueryType()) === null || _a === void 0 ? void 0 : _a.name)) {
3087
- specifiers.push(MapperKind.ROOT_FIELD, MapperKind.QUERY_ROOT_FIELD);
3088
- }
3089
- else if (typeName === ((_b = schema.getMutationType()) === null || _b === void 0 ? void 0 : _b.name)) {
3090
- specifiers.push(MapperKind.ROOT_FIELD, MapperKind.MUTATION_ROOT_FIELD);
3091
- }
3092
- else if (typeName === ((_c = schema.getSubscriptionType()) === null || _c === void 0 ? void 0 : _c.name)) {
3093
- specifiers.push(MapperKind.ROOT_FIELD, MapperKind.SUBSCRIPTION_ROOT_FIELD);
3094
- }
3095
- }
3096
- else if (isInterfaceType(type)) {
3097
- specifiers.push(MapperKind.COMPOSITE_FIELD, MapperKind.INTERFACE_FIELD);
3098
- }
3099
- else if (isInputObjectType(type)) {
3100
- specifiers.push(MapperKind.INPUT_OBJECT_FIELD);
3101
- }
3102
- return specifiers;
3103
- }
3104
- function getFieldMapper(schema, schemaMapper, typeName) {
3105
- var specifiers = getFieldSpecifiers(schema, typeName);
3106
- var fieldMapper;
3107
- var stack = __spreadArray([], __read(specifiers), false);
3108
- while (!fieldMapper && stack.length > 0) {
3109
- // It is safe to use the ! operator here as we check the length.
3110
- var next = stack.pop();
3111
- // TODO: fix this as unknown cast
3112
- fieldMapper = schemaMapper[next];
3113
- }
3114
- return fieldMapper !== null && fieldMapper !== void 0 ? fieldMapper : null;
3115
- }
3116
- function getArgumentMapper(schemaMapper) {
3117
- var argumentMapper = schemaMapper[MapperKind.ARGUMENT];
3118
- return argumentMapper != null ? argumentMapper : null;
3119
- }
3120
- function getDirectiveMapper(schemaMapper) {
3121
- var directiveMapper = schemaMapper[MapperKind.DIRECTIVE];
3122
- return directiveMapper != null ? directiveMapper : null;
3123
- }
3124
- function getEnumValueMapper(schemaMapper) {
3125
- var enumValueMapper = schemaMapper[MapperKind.ENUM_VALUE];
3126
- return enumValueMapper != null ? enumValueMapper : null;
3127
- }
3128
- function correctASTNodes(type) {
3129
- if (isObjectType(type)) {
3130
- var config = type.toConfig();
3131
- if (config.astNode != null) {
3132
- var fields = [];
3133
- for (var fieldName in config.fields) {
3134
- var fieldConfig = config.fields[fieldName];
3135
- if (fieldConfig.astNode != null) {
3136
- fields.push(fieldConfig.astNode);
3137
- }
3138
- }
3139
- config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.OBJECT_TYPE_DEFINITION, fields: fields });
3140
- }
3141
- if (config.extensionASTNodes != null) {
3142
- config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.OBJECT_TYPE_EXTENSION, fields: undefined })); });
3143
- }
3144
- return new GraphQLObjectType(config);
3145
- }
3146
- else if (isInterfaceType(type)) {
3147
- var config = type.toConfig();
3148
- if (config.astNode != null) {
3149
- var fields = [];
3150
- for (var fieldName in config.fields) {
3151
- var fieldConfig = config.fields[fieldName];
3152
- if (fieldConfig.astNode != null) {
3153
- fields.push(fieldConfig.astNode);
3154
- }
3155
- }
3156
- config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.INTERFACE_TYPE_DEFINITION, fields: fields });
3157
- }
3158
- if (config.extensionASTNodes != null) {
3159
- config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.INTERFACE_TYPE_EXTENSION, fields: undefined })); });
3160
- }
3161
- return new GraphQLInterfaceType(config);
3162
- }
3163
- else if (isInputObjectType(type)) {
3164
- var config = type.toConfig();
3165
- if (config.astNode != null) {
3166
- var fields = [];
3167
- for (var fieldName in config.fields) {
3168
- var fieldConfig = config.fields[fieldName];
3169
- if (fieldConfig.astNode != null) {
3170
- fields.push(fieldConfig.astNode);
3171
- }
3172
- }
3173
- config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, fields: fields });
3174
- }
3175
- if (config.extensionASTNodes != null) {
3176
- config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.INPUT_OBJECT_TYPE_EXTENSION, fields: undefined })); });
3177
- }
3178
- return new GraphQLInputObjectType(config);
3179
- }
3180
- else if (isEnumType(type)) {
3181
- var config = type.toConfig();
3182
- if (config.astNode != null) {
3183
- var values = [];
3184
- for (var enumKey in config.values) {
3185
- var enumValueConfig = config.values[enumKey];
3186
- if (enumValueConfig.astNode != null) {
3187
- values.push(enumValueConfig.astNode);
3188
- }
3189
- }
3190
- config.astNode = __assign(__assign({}, config.astNode), { values: values });
3191
- }
3192
- if (config.extensionASTNodes != null) {
3193
- config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { values: undefined })); });
3194
- }
3195
- return new GraphQLEnumType(config);
3196
- }
3197
- else {
3198
- return type;
3199
- }
3200
- }
3201
-
3202
- function filterSchema(_a) {
3203
- var _b;
3204
- var schema = _a.schema, _c = _a.typeFilter, typeFilter = _c === void 0 ? function () { return true; } : _c, _d = _a.fieldFilter, fieldFilter = _d === void 0 ? undefined : _d, _e = _a.rootFieldFilter, rootFieldFilter = _e === void 0 ? undefined : _e, _f = _a.objectFieldFilter, objectFieldFilter = _f === void 0 ? undefined : _f, _g = _a.interfaceFieldFilter, interfaceFieldFilter = _g === void 0 ? undefined : _g, _h = _a.inputObjectFieldFilter, inputObjectFieldFilter = _h === void 0 ? undefined : _h, _j = _a.argumentFilter, argumentFilter = _j === void 0 ? undefined : _j;
3205
- var filteredSchema = mapSchema(schema, (_b = {},
3206
- _b[MapperKind.QUERY] = function (type) { return filterRootFields(type, 'Query', rootFieldFilter, argumentFilter); },
3207
- _b[MapperKind.MUTATION] = function (type) {
3208
- return filterRootFields(type, 'Mutation', rootFieldFilter, argumentFilter);
3209
- },
3210
- _b[MapperKind.SUBSCRIPTION] = function (type) {
3211
- return filterRootFields(type, 'Subscription', rootFieldFilter, argumentFilter);
3212
- },
3213
- _b[MapperKind.OBJECT_TYPE] = function (type) {
3214
- return typeFilter(type.name, type)
3215
- ? filterElementFields(GraphQLObjectType, type, objectFieldFilter || fieldFilter, argumentFilter)
3216
- : null;
3217
- },
3218
- _b[MapperKind.INTERFACE_TYPE] = function (type) {
3219
- return typeFilter(type.name, type)
3220
- ? filterElementFields(GraphQLInterfaceType, type, interfaceFieldFilter || fieldFilter, argumentFilter)
3221
- : null;
3222
- },
3223
- _b[MapperKind.INPUT_OBJECT_TYPE] = function (type) {
3224
- return typeFilter(type.name, type)
3225
- ? filterElementFields(GraphQLInputObjectType, type, inputObjectFieldFilter || fieldFilter)
3226
- : null;
3227
- },
3228
- _b[MapperKind.UNION_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
3229
- _b[MapperKind.ENUM_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
3230
- _b[MapperKind.SCALAR_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
3231
- _b));
3232
- return filteredSchema;
3233
- }
3234
- function filterRootFields(type, operation, rootFieldFilter, argumentFilter) {
3235
- if (rootFieldFilter || argumentFilter) {
3236
- var config = type.toConfig();
3237
- for (var fieldName in config.fields) {
3238
- var field = config.fields[fieldName];
3239
- if (rootFieldFilter && !rootFieldFilter(operation, fieldName, config.fields[fieldName])) {
3240
- delete config.fields[fieldName];
3241
- }
3242
- else if (argumentFilter && field.args) {
3243
- for (var argName in field.args) {
3244
- if (!argumentFilter(operation, fieldName, argName, field.args[argName])) {
3245
- delete field.args[argName];
3246
- }
3247
- }
3248
- }
3249
- }
3250
- return new GraphQLObjectType(config);
3251
- }
3252
- return type;
3253
- }
3254
- function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilter) {
3255
- if (fieldFilter || argumentFilter) {
3256
- var config = type.toConfig();
3257
- for (var fieldName in config.fields) {
3258
- var field = config.fields[fieldName];
3259
- if (fieldFilter && !fieldFilter(type.name, fieldName, config.fields[fieldName])) {
3260
- delete config.fields[fieldName];
3261
- }
3262
- else if (argumentFilter && 'args' in field) {
3263
- for (var argName in field.args) {
3264
- if (!argumentFilter(type.name, fieldName, argName, field.args[argName])) {
3265
- delete field.args[argName];
3266
- }
3267
- }
3268
- }
3269
- }
3270
- return new ElementConstructor(config);
3271
- }
3272
- }
3273
-
3274
- // Update any references to named schema types that disagree with the named
3275
- // types found in schema.getTypeMap().
3276
- //
3277
- // healSchema and its callers (visitSchema/visitSchemaDirectives) all modify the schema in place.
3278
- // Therefore, private variables (such as the stored implementation map and the proper root types)
3279
- // are not updated.
3280
- //
3281
- // If this causes issues, the schema could be more aggressively healed as follows:
3282
- //
3283
- // healSchema(schema);
3284
- // const config = schema.toConfig()
3285
- // const healedSchema = new GraphQLSchema({
3286
- // ...config,
3287
- // query: schema.getType('<desired new root query type name>'),
3288
- // mutation: schema.getType('<desired new root mutation type name>'),
3289
- // subscription: schema.getType('<desired new root subscription type name>'),
3290
- // });
3291
- //
3292
- // One can then also -- if necessary -- assign the correct private variables to the initial schema
3293
- // as follows:
3294
- // Object.assign(schema, healedSchema);
3295
- //
3296
- // These steps are not taken automatically to preserve backwards compatibility with graphql-tools v4.
3297
- // See https://github.com/ardatan/graphql-tools/issues/1462
3298
- //
3299
- // They were briefly taken in v5, but can now be phased out as they were only required when other
3300
- // areas of the codebase were using healSchema and visitSchema more extensively.
3301
- //
3302
- function healSchema(schema) {
3303
- healTypes(schema.getTypeMap(), schema.getDirectives());
3304
- return schema;
3305
- }
3306
- function healTypes(originalTypeMap, directives) {
3307
- var e_1, _a;
3308
- var actualNamedTypeMap = Object.create(null);
3309
- // If any of the .name properties of the GraphQLNamedType objects in
3310
- // schema.getTypeMap() have changed, the keys of the type map need to
3311
- // be updated accordingly.
3312
- for (var typeName in originalTypeMap) {
3313
- var namedType = originalTypeMap[typeName];
3314
- if (namedType == null || typeName.startsWith('__')) {
3315
- continue;
3316
- }
3317
- var actualName = namedType.name;
3318
- if (actualName.startsWith('__')) {
3319
- continue;
3320
- }
3321
- if (actualName in actualNamedTypeMap) {
3322
- throw new Error("Duplicate schema type name " + actualName);
3323
- }
3324
- actualNamedTypeMap[actualName] = namedType;
3325
- // Note: we are deliberately leaving namedType in the schema by its
3326
- // original name (which might be different from actualName), so that
3327
- // references by that name can be healed.
3328
- }
3329
- // Now add back every named type by its actual name.
3330
- for (var typeName in actualNamedTypeMap) {
3331
- var namedType = actualNamedTypeMap[typeName];
3332
- originalTypeMap[typeName] = namedType;
3333
- }
3334
- try {
3335
- // Directive declaration argument types can refer to named types.
3336
- for (var directives_1 = __values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
3337
- var decl = directives_1_1.value;
3338
- decl.args = decl.args.filter(function (arg) {
3339
- arg.type = healType(arg.type);
3340
- return arg.type !== null;
3341
- });
3342
- }
3343
- }
3344
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3345
- finally {
3346
- try {
3347
- if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
3348
- }
3349
- finally { if (e_1) throw e_1.error; }
3350
- }
3351
- for (var typeName in originalTypeMap) {
3352
- var namedType = originalTypeMap[typeName];
3353
- // Heal all named types, except for dangling references, kept only to redirect.
3354
- if (!typeName.startsWith('__') && typeName in actualNamedTypeMap) {
3355
- if (namedType != null) {
3356
- healNamedType(namedType);
3357
- }
3358
- }
3359
- }
3360
- for (var typeName in originalTypeMap) {
3361
- if (!typeName.startsWith('__') && !(typeName in actualNamedTypeMap)) {
3362
- delete originalTypeMap[typeName];
3363
- }
3364
- }
3365
- function healNamedType(type) {
3366
- if (isObjectType(type)) {
3367
- healFields(type);
3368
- healInterfaces(type);
3369
- return;
3370
- }
3371
- else if (isInterfaceType(type)) {
3372
- healFields(type);
3373
- if ('getInterfaces' in type) {
3374
- healInterfaces(type);
3375
- }
3376
- return;
3377
- }
3378
- else if (isUnionType(type)) {
3379
- healUnderlyingTypes(type);
3380
- return;
3381
- }
3382
- else if (isInputObjectType(type)) {
3383
- healInputFields(type);
3384
- return;
3385
- }
3386
- else if (isLeafType(type)) {
3387
- return;
3388
- }
3389
- throw new Error("Unexpected schema type: " + type);
3390
- }
3391
- function healFields(type) {
3392
- var e_2, _a;
3393
- var fieldMap = type.getFields();
3394
- try {
3395
- for (var _b = __values(Object.entries(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
3396
- var _d = __read(_c.value, 2), key = _d[0], field = _d[1];
3397
- field.args
3398
- .map(function (arg) {
3399
- arg.type = healType(arg.type);
3400
- return arg.type === null ? null : arg;
3401
- })
3402
- .filter(Boolean);
3403
- field.type = healType(field.type);
3404
- if (field.type === null) {
3405
- delete fieldMap[key];
3406
- }
3407
- }
3408
- }
3409
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3410
- finally {
3411
- try {
3412
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3413
- }
3414
- finally { if (e_2) throw e_2.error; }
3415
- }
3416
- }
3417
- function healInterfaces(type) {
3418
- if ('getInterfaces' in type) {
3419
- var interfaces = type.getInterfaces();
3420
- interfaces.push.apply(interfaces, __spreadArray([], __read(interfaces
3421
- .splice(0)
3422
- .map(function (iface) { return healType(iface); })
3423
- .filter(Boolean)), false));
3424
- }
3425
- }
3426
- function healInputFields(type) {
3427
- var e_3, _a;
3428
- var fieldMap = type.getFields();
3429
- try {
3430
- for (var _b = __values(Object.entries(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
3431
- var _d = __read(_c.value, 2), key = _d[0], field = _d[1];
3432
- field.type = healType(field.type);
3433
- if (field.type === null) {
3434
- delete fieldMap[key];
3435
- }
3436
- }
3437
- }
3438
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
3439
- finally {
3440
- try {
3441
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3442
- }
3443
- finally { if (e_3) throw e_3.error; }
3444
- }
3445
- }
3446
- function healUnderlyingTypes(type) {
3447
- var types = type.getTypes();
3448
- types.push.apply(types, __spreadArray([], __read(types
3449
- .splice(0)
3450
- .map(function (t) { return healType(t); })
3451
- .filter(Boolean)), false));
3452
- }
3453
- function healType(type) {
3454
- // Unwrap the two known wrapper types
3455
- if (isListType(type)) {
3456
- var healedType = healType(type.ofType);
3457
- return healedType != null ? new GraphQLList(healedType) : null;
3458
- }
3459
- else if (isNonNullType(type)) {
3460
- var healedType = healType(type.ofType);
3461
- return healedType != null ? new GraphQLNonNull(healedType) : null;
3462
- }
3463
- else if (isNamedType(type)) {
3464
- // If a type annotation on a field or an argument or a union member is
3465
- // any `GraphQLNamedType` with a `name`, then it must end up identical
3466
- // to `schema.getType(name)`, since `schema.getTypeMap()` is the source
3467
- // of truth for all named schema types.
3468
- // Note that new types can still be simply added by adding a field, as
3469
- // the official type will be undefined, not null.
3470
- var officialType = originalTypeMap[type.name];
3471
- if (officialType && type !== officialType) {
3472
- return officialType;
3473
- }
3474
- }
3475
- return type;
3476
- }
3477
- }
3478
-
3479
- function getResolversFromSchema(schema) {
3480
- var e_1, _a;
3481
- var _b, _c;
3482
- var resolvers = Object.create(null);
3483
- var typeMap = schema.getTypeMap();
3484
- for (var typeName in typeMap) {
3485
- if (!typeName.startsWith('__')) {
3486
- var type = typeMap[typeName];
3487
- if (isScalarType(type)) {
3488
- if (!isSpecifiedScalarType(type)) {
3489
- var config = type.toConfig();
3490
- delete config.astNode; // avoid AST duplication elsewhere
3491
- resolvers[typeName] = new GraphQLScalarType(config);
3492
- }
3493
- }
3494
- else if (isEnumType(type)) {
3495
- resolvers[typeName] = {};
3496
- var values = type.getValues();
3497
- try {
3498
- for (var values_1 = (e_1 = void 0, __values(values)), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
3499
- var value = values_1_1.value;
3500
- resolvers[typeName][value.name] = value.value;
3501
- }
3502
- }
3503
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3504
- finally {
3505
- try {
3506
- if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
3507
- }
3508
- finally { if (e_1) throw e_1.error; }
3509
- }
3510
- }
3511
- else if (isInterfaceType(type)) {
3512
- if (type.resolveType != null) {
3513
- resolvers[typeName] = {
3514
- __resolveType: type.resolveType,
3515
- };
3516
- }
3517
- }
3518
- else if (isUnionType(type)) {
3519
- if (type.resolveType != null) {
3520
- resolvers[typeName] = {
3521
- __resolveType: type.resolveType,
3522
- };
3523
- }
3524
- }
3525
- else if (isObjectType(type)) {
3526
- resolvers[typeName] = {};
3527
- if (type.isTypeOf != null) {
3528
- resolvers[typeName].__isTypeOf = type.isTypeOf;
3529
- }
3530
- var fields = type.getFields();
3531
- for (var fieldName in fields) {
3532
- var field = fields[fieldName];
3533
- if (field.subscribe != null) {
3534
- resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
3535
- resolvers[typeName][fieldName].subscribe = field.subscribe;
3536
- }
3537
- if (field.resolve != null &&
3538
- ((_b = field.resolve) === null || _b === void 0 ? void 0 : _b.name) !== 'defaultFieldResolver' &&
3539
- ((_c = field.resolve) === null || _c === void 0 ? void 0 : _c.name) !== 'defaultMergedResolver') {
3540
- resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
3541
- resolvers[typeName][fieldName].resolve = field.resolve;
3542
- }
3543
- }
3544
- }
3545
- }
3546
- }
3547
- return resolvers;
3548
- }
3549
-
3550
- function forEachField(schema, fn) {
3551
- var typeMap = schema.getTypeMap();
3552
- for (var typeName in typeMap) {
3553
- var type = typeMap[typeName];
3554
- // TODO: maybe have an option to include these?
3555
- if (!getNamedType(type).name.startsWith('__') && isObjectType(type)) {
3556
- var fields = type.getFields();
3557
- for (var fieldName in fields) {
3558
- var field = fields[fieldName];
3559
- fn(field, typeName, fieldName);
3560
- }
3561
- }
3562
- }
3563
- }
3564
-
3565
- function forEachDefaultValue(schema, fn) {
3566
- var e_1, _a;
3567
- var typeMap = schema.getTypeMap();
3568
- for (var typeName in typeMap) {
3569
- var type = typeMap[typeName];
3570
- if (!getNamedType(type).name.startsWith('__')) {
3571
- if (isObjectType(type)) {
3572
- var fields = type.getFields();
3573
- for (var fieldName in fields) {
3574
- var field = fields[fieldName];
3575
- try {
3576
- for (var _b = (e_1 = void 0, __values(field.args)), _c = _b.next(); !_c.done; _c = _b.next()) {
3577
- var arg = _c.value;
3578
- arg.defaultValue = fn(arg.type, arg.defaultValue);
3579
- }
3580
- }
3581
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3582
- finally {
3583
- try {
3584
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3585
- }
3586
- finally { if (e_1) throw e_1.error; }
3587
- }
3588
- }
3589
- }
3590
- else if (isInputObjectType(type)) {
3591
- var fields = type.getFields();
3592
- for (var fieldName in fields) {
3593
- var field = fields[fieldName];
3594
- field.defaultValue = fn(field.type, field.defaultValue);
3595
- }
3596
- }
3597
- }
3598
- }
3599
- }
3600
-
3601
- // addTypes uses toConfig to create a new schema with a new or replaced
3602
- function addTypes(schema, newTypesOrDirectives) {
3603
- var e_1, _a, e_2, _b, e_3, _c;
3604
- var config = schema.toConfig();
3605
- var originalTypeMap = {};
3606
- try {
3607
- for (var _d = __values(config.types), _e = _d.next(); !_e.done; _e = _d.next()) {
3608
- var type = _e.value;
3609
- originalTypeMap[type.name] = type;
3610
- }
3611
- }
3612
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3613
- finally {
3614
- try {
3615
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
3616
- }
3617
- finally { if (e_1) throw e_1.error; }
3618
- }
3619
- var originalDirectiveMap = {};
3620
- try {
3621
- for (var _f = __values(config.directives), _g = _f.next(); !_g.done; _g = _f.next()) {
3622
- var directive = _g.value;
3623
- originalDirectiveMap[directive.name] = directive;
3624
- }
3625
- }
3626
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3627
- finally {
3628
- try {
3629
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
3630
- }
3631
- finally { if (e_2) throw e_2.error; }
3632
- }
3633
- try {
3634
- for (var newTypesOrDirectives_1 = __values(newTypesOrDirectives), newTypesOrDirectives_1_1 = newTypesOrDirectives_1.next(); !newTypesOrDirectives_1_1.done; newTypesOrDirectives_1_1 = newTypesOrDirectives_1.next()) {
3635
- var newTypeOrDirective = newTypesOrDirectives_1_1.value;
3636
- if (isNamedType(newTypeOrDirective)) {
3637
- originalTypeMap[newTypeOrDirective.name] = newTypeOrDirective;
3638
- }
3639
- else if (isDirective(newTypeOrDirective)) {
3640
- originalDirectiveMap[newTypeOrDirective.name] = newTypeOrDirective;
3641
- }
3642
- }
3643
- }
3644
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
3645
- finally {
3646
- try {
3647
- if (newTypesOrDirectives_1_1 && !newTypesOrDirectives_1_1.done && (_c = newTypesOrDirectives_1.return)) _c.call(newTypesOrDirectives_1);
3648
- }
3649
- finally { if (e_3) throw e_3.error; }
3650
- }
3651
- var _h = rewireTypes(originalTypeMap, Object.values(originalDirectiveMap)), typeMap = _h.typeMap, directives = _h.directives;
3652
- return new GraphQLSchema(__assign(__assign({}, config), { query: getObjectTypeFromTypeMap(typeMap, schema.getQueryType()), mutation: getObjectTypeFromTypeMap(typeMap, schema.getMutationType()), subscription: getObjectTypeFromTypeMap(typeMap, schema.getSubscriptionType()), types: Object.values(typeMap), directives: directives }));
3653
- }
3654
-
3655
- /**
3656
- * Prunes the provided schema, removing unused and empty types
3657
- * @param schema The schema to prune
3658
- * @param options Additional options for removing unused types from the schema
3659
- */
3660
- function pruneSchema(schema, options) {
3661
- var e_1, _a, _b;
3662
- if (options === void 0) { options = {}; }
3663
- var pruningContext = {
3664
- schema: schema,
3665
- unusedTypes: Object.create(null),
3666
- implementations: Object.create(null),
3667
- };
3668
- for (var typeName in schema.getTypeMap()) {
3669
- var type = schema.getType(typeName);
3670
- if (type && 'getInterfaces' in type) {
3671
- try {
3672
- for (var _c = (e_1 = void 0, __values(type.getInterfaces())), _d = _c.next(); !_d.done; _d = _c.next()) {
3673
- var iface = _d.value;
3674
- var implementations = getImplementations(pruningContext, iface);
3675
- if (implementations == null) {
3676
- pruningContext.implementations[iface.name] = Object.create(null);
3677
- }
3678
- pruningContext.implementations[iface.name][type.name] = true;
3679
- }
3680
- }
3681
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3682
- finally {
3683
- try {
3684
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
3685
- }
3686
- finally { if (e_1) throw e_1.error; }
3687
- }
3688
- }
3689
- }
3690
- visitTypes(pruningContext, schema);
3691
- return mapSchema(schema, (_b = {},
3692
- _b[MapperKind.TYPE] = function (type) {
3693
- // If we should NOT prune the type, return it immediately as unmodified
3694
- if (options.skipPruning && options.skipPruning(type)) {
3695
- return type;
3696
- }
3697
- if (isObjectType(type) || isInputObjectType(type)) {
3698
- if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
3699
- (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
3700
- return null;
3701
- }
3702
- }
3703
- else if (isUnionType(type)) {
3704
- if ((!type.getTypes().length && !options.skipEmptyUnionPruning) ||
3705
- (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
3706
- return null;
3707
- }
3708
- }
3709
- else if (isInterfaceType(type)) {
3710
- var implementations = getImplementations(pruningContext, type);
3711
- if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
3712
- (implementations && !Object.keys(implementations).length && !options.skipUnimplementedInterfacesPruning) ||
3713
- (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
3714
- return null;
3715
- }
3716
- }
3717
- else {
3718
- if (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning) {
3719
- return null;
3720
- }
3721
- }
3722
- },
3723
- _b));
3724
- }
3725
- function visitOutputType(visitedTypes, pruningContext, type) {
3726
- var e_2, _a, e_3, _b, e_4, _c;
3727
- if (visitedTypes[type.name]) {
3728
- return;
3729
- }
3730
- visitedTypes[type.name] = true;
3731
- pruningContext.unusedTypes[type.name] = false;
3732
- if (isObjectType(type) || isInterfaceType(type)) {
3733
- var fields = type.getFields();
3734
- for (var fieldName in fields) {
3735
- var field = fields[fieldName];
3736
- var namedType = getNamedType(field.type);
3737
- visitOutputType(visitedTypes, pruningContext, namedType);
3738
- try {
3739
- for (var _d = (e_2 = void 0, __values(field.args)), _e = _d.next(); !_e.done; _e = _d.next()) {
3740
- var arg = _e.value;
3741
- var type_1 = getNamedType(arg.type);
3742
- visitInputType(visitedTypes, pruningContext, type_1);
3743
- }
3744
- }
3745
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3746
- finally {
3747
- try {
3748
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
3749
- }
3750
- finally { if (e_2) throw e_2.error; }
3751
- }
3752
- }
3753
- if (isInterfaceType(type)) {
3754
- var implementations = getImplementations(pruningContext, type);
3755
- if (implementations) {
3756
- for (var typeName in implementations) {
3757
- visitOutputType(visitedTypes, pruningContext, pruningContext.schema.getType(typeName));
3758
- }
3759
- }
3760
- }
3761
- if ('getInterfaces' in type) {
3762
- try {
3763
- for (var _f = __values(type.getInterfaces()), _g = _f.next(); !_g.done; _g = _f.next()) {
3764
- var iFace = _g.value;
3765
- visitOutputType(visitedTypes, pruningContext, iFace);
3766
- }
3767
- }
3768
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
3769
- finally {
3770
- try {
3771
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
3772
- }
3773
- finally { if (e_3) throw e_3.error; }
3774
- }
3775
- }
3776
- }
3777
- else if (isUnionType(type)) {
3778
- var types = type.getTypes();
3779
- try {
3780
- for (var types_1 = __values(types), types_1_1 = types_1.next(); !types_1_1.done; types_1_1 = types_1.next()) {
3781
- var type_2 = types_1_1.value;
3782
- visitOutputType(visitedTypes, pruningContext, type_2);
3783
- }
3784
- }
3785
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
3786
- finally {
3787
- try {
3788
- if (types_1_1 && !types_1_1.done && (_c = types_1.return)) _c.call(types_1);
3789
- }
3790
- finally { if (e_4) throw e_4.error; }
3791
- }
3792
- }
3793
- }
3794
- /**
3795
- * Get the implementations of an interface. May return undefined.
3796
- */
3797
- function getImplementations(pruningContext, type) {
3798
- return pruningContext.implementations[type.name];
3799
- }
3800
- function visitInputType(visitedTypes, pruningContext, type) {
3801
- if (visitedTypes[type.name]) {
3802
- return;
3803
- }
3804
- pruningContext.unusedTypes[type.name] = false;
3805
- visitedTypes[type.name] = true;
3806
- if (isInputObjectType(type)) {
3807
- var fields = type.getFields();
3808
- for (var fieldName in fields) {
3809
- var field = fields[fieldName];
3810
- var namedType = getNamedType(field.type);
3811
- visitInputType(visitedTypes, pruningContext, namedType);
3812
- }
3813
- }
3814
- }
3815
- function visitTypes(pruningContext, schema) {
3816
- var e_5, _a, e_6, _b, e_7, _c;
3817
- for (var typeName in schema.getTypeMap()) {
3818
- if (!typeName.startsWith('__')) {
3819
- pruningContext.unusedTypes[typeName] = true;
3820
- }
3821
- }
3822
- var visitedTypes = Object.create(null);
3823
- var rootTypes = getRootTypes(schema);
3824
- try {
3825
- for (var rootTypes_1 = __values(rootTypes), rootTypes_1_1 = rootTypes_1.next(); !rootTypes_1_1.done; rootTypes_1_1 = rootTypes_1.next()) {
3826
- var rootType = rootTypes_1_1.value;
3827
- visitOutputType(visitedTypes, pruningContext, rootType);
3828
- }
3829
- }
3830
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
3831
- finally {
3832
- try {
3833
- if (rootTypes_1_1 && !rootTypes_1_1.done && (_a = rootTypes_1.return)) _a.call(rootTypes_1);
3834
- }
3835
- finally { if (e_5) throw e_5.error; }
3836
- }
3837
- try {
3838
- for (var _d = __values(schema.getDirectives()), _e = _d.next(); !_e.done; _e = _d.next()) {
3839
- var directive = _e.value;
3840
- try {
3841
- for (var _f = (e_7 = void 0, __values(directive.args)), _g = _f.next(); !_g.done; _g = _f.next()) {
3842
- var arg = _g.value;
3843
- var type = getNamedType(arg.type);
3844
- visitInputType(visitedTypes, pruningContext, type);
3845
- }
3846
- }
3847
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
3848
- finally {
3849
- try {
3850
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
3851
- }
3852
- finally { if (e_7) throw e_7.error; }
3853
- }
3854
- }
3855
- }
3856
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
3857
- finally {
3858
- try {
3859
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
3860
- }
3861
- finally { if (e_6) throw e_6.error; }
3862
- }
3863
- }
3864
-
3865
- // eslint-disable-next-line @typescript-eslint/ban-types
3866
- function mergeDeep(sources, respectPrototype) {
3867
- var e_1, _a, e_2, _b, _c, _d;
3868
- if (respectPrototype === void 0) { respectPrototype = false; }
3869
- var target = sources[0] || {};
3870
- var output = {};
3871
- if (respectPrototype) {
3872
- Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(target)));
3873
- }
3874
- try {
3875
- for (var sources_1 = __values(sources), sources_1_1 = sources_1.next(); !sources_1_1.done; sources_1_1 = sources_1.next()) {
3876
- var source = sources_1_1.value;
3877
- if (isObject(target) && isObject(source)) {
3878
- if (respectPrototype) {
3879
- var outputPrototype = Object.getPrototypeOf(output);
3880
- var sourcePrototype = Object.getPrototypeOf(source);
3881
- if (sourcePrototype) {
3882
- try {
3883
- for (var _e = (e_2 = void 0, __values(Object.getOwnPropertyNames(sourcePrototype))), _f = _e.next(); !_f.done; _f = _e.next()) {
3884
- var key = _f.value;
3885
- var descriptor = Object.getOwnPropertyDescriptor(sourcePrototype, key);
3886
- if (isSome(descriptor)) {
3887
- Object.defineProperty(outputPrototype, key, descriptor);
3888
- }
3889
- }
3890
- }
3891
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3892
- finally {
3893
- try {
3894
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
3895
- }
3896
- finally { if (e_2) throw e_2.error; }
3897
- }
3898
- }
3899
- }
3900
- for (var key in source) {
3901
- if (isObject(source[key])) {
3902
- if (!(key in output)) {
3903
- Object.assign(output, (_c = {}, _c[key] = source[key], _c));
3904
- }
3905
- else {
3906
- output[key] = mergeDeep([output[key], source[key]], respectPrototype);
3907
- }
3908
- }
3909
- else {
3910
- Object.assign(output, (_d = {}, _d[key] = source[key], _d));
3911
- }
3912
- }
3913
- }
3914
- }
3915
- }
3916
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3917
- finally {
3918
- try {
3919
- if (sources_1_1 && !sources_1_1.done && (_a = sources_1.return)) _a.call(sources_1);
3920
- }
3921
- finally { if (e_1) throw e_1.error; }
3922
- }
3923
- return output;
3924
- }
3925
- function isObject(item) {
3926
- return item && typeof item === 'object' && !Array.isArray(item);
3927
- }
3928
-
3929
- function parseSelectionSet(selectionSet, options) {
3930
- var query = parse(selectionSet, options).definitions[0];
3931
- return query.selectionSet;
3932
- }
3933
-
3934
- /**
3935
- * Get the key under which the result of this resolver will be placed in the response JSON. Basically, just
3936
- * resolves aliases.
3937
- * @param info The info argument to the resolver.
3938
- */
3939
- function getResponseKeyFromInfo(info) {
3940
- return info.fieldNodes[0].alias != null ? info.fieldNodes[0].alias.value : info.fieldName;
3941
- }
3942
-
3943
- function appendObjectFields(schema, typeName, additionalFields) {
3944
- var _a;
3945
- if (schema.getType(typeName) == null) {
3946
- return addTypes(schema, [
3947
- new GraphQLObjectType({
3948
- name: typeName,
3949
- fields: additionalFields,
3950
- }),
3951
- ]);
3952
- }
3953
- return mapSchema(schema, (_a = {},
3954
- _a[MapperKind.OBJECT_TYPE] = function (type) {
3955
- if (type.name === typeName) {
3956
- var config = type.toConfig();
3957
- var originalFieldConfigMap = config.fields;
3958
- var newFieldConfigMap = {};
3959
- for (var fieldName in originalFieldConfigMap) {
3960
- newFieldConfigMap[fieldName] = originalFieldConfigMap[fieldName];
3961
- }
3962
- for (var fieldName in additionalFields) {
3963
- newFieldConfigMap[fieldName] = additionalFields[fieldName];
3964
- }
3965
- return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
3966
- }
3967
- },
3968
- _a));
3969
- }
3970
- function removeObjectFields(schema, typeName, testFn) {
3971
- var _a;
3972
- var removedFields = {};
3973
- var newSchema = mapSchema(schema, (_a = {},
3974
- _a[MapperKind.OBJECT_TYPE] = function (type) {
3975
- if (type.name === typeName) {
3976
- var config = type.toConfig();
3977
- var originalFieldConfigMap = config.fields;
3978
- var newFieldConfigMap = {};
3979
- for (var fieldName in originalFieldConfigMap) {
3980
- var originalFieldConfig = originalFieldConfigMap[fieldName];
3981
- if (testFn(fieldName, originalFieldConfig)) {
3982
- removedFields[fieldName] = originalFieldConfig;
3983
- }
3984
- else {
3985
- newFieldConfigMap[fieldName] = originalFieldConfig;
3986
- }
3987
- }
3988
- return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
3989
- }
3990
- },
3991
- _a));
3992
- return [newSchema, removedFields];
3993
- }
3994
- function selectObjectFields(schema, typeName, testFn) {
3995
- var _a;
3996
- var selectedFields = {};
3997
- mapSchema(schema, (_a = {},
3998
- _a[MapperKind.OBJECT_TYPE] = function (type) {
3999
- if (type.name === typeName) {
4000
- var config = type.toConfig();
4001
- var originalFieldConfigMap = config.fields;
4002
- for (var fieldName in originalFieldConfigMap) {
4003
- var originalFieldConfig = originalFieldConfigMap[fieldName];
4004
- if (testFn(fieldName, originalFieldConfig)) {
4005
- selectedFields[fieldName] = originalFieldConfig;
4006
- }
4007
- }
4008
- }
4009
- return undefined;
4010
- },
4011
- _a));
4012
- return selectedFields;
4013
- }
4014
- function modifyObjectFields(schema, typeName, testFn, newFields) {
4015
- var _a;
4016
- var removedFields = {};
4017
- var newSchema = mapSchema(schema, (_a = {},
4018
- _a[MapperKind.OBJECT_TYPE] = function (type) {
4019
- if (type.name === typeName) {
4020
- var config = type.toConfig();
4021
- var originalFieldConfigMap = config.fields;
4022
- var newFieldConfigMap = {};
4023
- for (var fieldName in originalFieldConfigMap) {
4024
- var originalFieldConfig = originalFieldConfigMap[fieldName];
4025
- if (testFn(fieldName, originalFieldConfig)) {
4026
- removedFields[fieldName] = originalFieldConfig;
4027
- }
4028
- else {
4029
- newFieldConfigMap[fieldName] = originalFieldConfig;
4030
- }
4031
- }
4032
- for (var fieldName in newFields) {
4033
- var fieldConfig = newFields[fieldName];
4034
- newFieldConfigMap[fieldName] = fieldConfig;
4035
- }
4036
- return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap })));
4037
- }
4038
- },
4039
- _a));
4040
- return [newSchema, removedFields];
4041
- }
4042
-
4043
- function renameType(type, newTypeName) {
4044
- if (isObjectType(type)) {
4045
- return new GraphQLObjectType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4046
- ? type.astNode
4047
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4048
- ? type.extensionASTNodes
4049
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4050
- }
4051
- else if (isInterfaceType(type)) {
4052
- return new GraphQLInterfaceType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4053
- ? type.astNode
4054
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4055
- ? type.extensionASTNodes
4056
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4057
- }
4058
- else if (isUnionType(type)) {
4059
- return new GraphQLUnionType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4060
- ? type.astNode
4061
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4062
- ? type.extensionASTNodes
4063
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4064
- }
4065
- else if (isInputObjectType(type)) {
4066
- return new GraphQLInputObjectType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4067
- ? type.astNode
4068
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4069
- ? type.extensionASTNodes
4070
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4071
- }
4072
- else if (isEnumType(type)) {
4073
- return new GraphQLEnumType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4074
- ? type.astNode
4075
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4076
- ? type.extensionASTNodes
4077
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4078
- }
4079
- else if (isScalarType(type)) {
4080
- return new GraphQLScalarType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
4081
- ? type.astNode
4082
- : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
4083
- ? type.extensionASTNodes
4084
- : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
4085
- }
4086
- throw new Error("Unknown type " + type + ".");
4087
- }
4088
-
4089
- /**
4090
- * Given an AsyncIterable and a callback function, return an AsyncIterator
4091
- * which produces values mapped via calling the callback function.
4092
- */
4093
- function mapAsyncIterator(iterator, callback, rejectCallback) {
4094
- var _a;
4095
- var $return;
4096
- var abruptClose;
4097
- if (typeof iterator.return === 'function') {
4098
- $return = iterator.return;
4099
- abruptClose = function (error) {
4100
- var rethrow = function () { return Promise.reject(error); };
4101
- return $return.call(iterator).then(rethrow, rethrow);
4102
- };
4103
- }
4104
- function mapResult(result) {
4105
- return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
4106
- }
4107
- var mapReject;
4108
- if (rejectCallback) {
4109
- // Capture rejectCallback to ensure it cannot be null.
4110
- var reject_1 = rejectCallback;
4111
- mapReject = function (error) { return asyncMapValue(error, reject_1).then(iteratorResult, abruptClose); };
4112
- }
4113
- return _a = {
4114
- next: function () {
4115
- return iterator.next().then(mapResult, mapReject);
4116
- },
4117
- return: function () {
4118
- return $return
4119
- ? $return.call(iterator).then(mapResult, mapReject)
4120
- : Promise.resolve({ value: undefined, done: true });
4121
- },
4122
- throw: function (error) {
4123
- if (typeof iterator.throw === 'function') {
4124
- return iterator.throw(error).then(mapResult, mapReject);
4125
- }
4126
- return Promise.reject(error).catch(abruptClose);
4127
- }
4128
- },
4129
- _a[Symbol.asyncIterator] = function () {
4130
- return this;
4131
- },
4132
- _a;
4133
- }
4134
- function asyncMapValue(value, callback) {
4135
- return new Promise(function (resolve) { return resolve(callback(value)); });
4136
- }
4137
- function iteratorResult(value) {
4138
- return { value: value, done: false };
4139
- }
4140
-
4141
- function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
4142
- argumentNodes[argName] = {
4143
- kind: Kind.ARGUMENT,
4144
- name: {
4145
- kind: Kind.NAME,
4146
- value: argName,
4147
- },
4148
- value: {
4149
- kind: Kind.VARIABLE,
4150
- name: {
4151
- kind: Kind.NAME,
4152
- value: varName,
4153
- },
4154
- },
4155
- };
4156
- variableDefinitionsMap[varName] = {
4157
- kind: Kind.VARIABLE_DEFINITION,
4158
- variable: {
4159
- kind: Kind.VARIABLE,
4160
- name: {
4161
- kind: Kind.NAME,
4162
- value: varName,
4163
- },
4164
- },
4165
- type: astFromType(type),
4166
- };
4167
- if (value !== undefined) {
4168
- variableValues[varName] = value;
4169
- return;
4170
- }
4171
- // including the variable in the map with value of `undefined`
4172
- // will actually be translated by graphql-js into `null`
4173
- // see https://github.com/graphql/graphql-js/issues/2533
4174
- if (varName in variableValues) {
4175
- delete variableValues[varName];
4176
- }
4177
- }
4178
- function createVariableNameGenerator(variableDefinitionMap) {
4179
- var varCounter = 0;
4180
- return function (argName) {
4181
- var varName;
4182
- do {
4183
- varName = "_v" + (varCounter++).toString() + "_" + argName;
4184
- } while (varName in variableDefinitionMap);
4185
- return varName;
4186
- };
4187
- }
4188
-
4189
- function implementsAbstractType(schema, typeA, typeB) {
4190
- if (typeB == null || typeA == null) {
4191
- return false;
4192
- }
4193
- else if (typeA === typeB) {
4194
- return true;
4195
- }
4196
- else if (isCompositeType(typeA) && isCompositeType(typeB)) {
4197
- return doTypesOverlap(schema, typeA, typeB);
4198
- }
4199
- return false;
4200
- }
4201
-
4202
- function relocatedError(originalError, path) {
4203
- return new GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
4204
- }
4205
-
4206
- function observableToAsyncIterable(observable) {
4207
- var _a;
4208
- var pullQueue = [];
4209
- var pushQueue = [];
4210
- var listening = true;
4211
- var pushValue = function (value) {
4212
- if (pullQueue.length !== 0) {
4213
- // It is safe to use the ! operator here as we check the length.
4214
- pullQueue.shift()({ value: value, done: false });
4215
- }
4216
- else {
4217
- pushQueue.push({ value: value, done: false });
4218
- }
4219
- };
4220
- var pushError = function (error) {
4221
- if (pullQueue.length !== 0) {
4222
- // It is safe to use the ! operator here as we check the length.
4223
- pullQueue.shift()({ value: { errors: [error] }, done: false });
4224
- }
4225
- else {
4226
- pushQueue.push({ value: { errors: [error] }, done: false });
4227
- }
4228
- };
4229
- var pushDone = function () {
4230
- if (pullQueue.length !== 0) {
4231
- // It is safe to use the ! operator here as we check the length.
4232
- pullQueue.shift()({ done: true });
4233
- }
4234
- else {
4235
- pushQueue.push({ done: true });
4236
- }
4237
- };
4238
- var pullValue = function () {
4239
- return new Promise(function (resolve) {
4240
- if (pushQueue.length !== 0) {
4241
- var element = pushQueue.shift();
4242
- // either {value: {errors: [...]}} or {value: ...}
4243
- resolve(element);
4244
- }
4245
- else {
4246
- pullQueue.push(resolve);
4247
- }
4248
- });
4249
- };
4250
- var subscription = observable.subscribe({
4251
- next: function (value) {
4252
- pushValue(value);
4253
- },
4254
- error: function (err) {
4255
- pushError(err);
4256
- },
4257
- complete: function () {
4258
- pushDone();
4259
- },
4260
- });
4261
- var emptyQueue = function () {
4262
- var e_1, _a;
4263
- if (listening) {
4264
- listening = false;
4265
- subscription.unsubscribe();
4266
- try {
4267
- for (var pullQueue_1 = __values(pullQueue), pullQueue_1_1 = pullQueue_1.next(); !pullQueue_1_1.done; pullQueue_1_1 = pullQueue_1.next()) {
4268
- var resolve = pullQueue_1_1.value;
4269
- resolve({ value: undefined, done: true });
4270
- }
4271
- }
4272
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4273
- finally {
4274
- try {
4275
- if (pullQueue_1_1 && !pullQueue_1_1.done && (_a = pullQueue_1.return)) _a.call(pullQueue_1);
4276
- }
4277
- finally { if (e_1) throw e_1.error; }
4278
- }
4279
- pullQueue.length = 0;
4280
- pushQueue.length = 0;
4281
- }
4282
- };
4283
- return _a = {
4284
- next: function () {
4285
- // return is a defined method, so it is safe to call it.
4286
- return listening ? pullValue() : this.return();
4287
- },
4288
- return: function () {
4289
- emptyQueue();
4290
- return Promise.resolve({ value: undefined, done: true });
4291
- },
4292
- throw: function (error) {
4293
- emptyQueue();
4294
- return Promise.reject(error);
4295
- }
4296
- },
4297
- _a[Symbol.asyncIterator] = function () {
4298
- return this;
4299
- },
4300
- _a;
4301
- }
4302
-
4303
- // Taken from GraphQL-JS v16 for backwards compat
4304
- function collectFields(schema, fragments, variableValues, runtimeType, selectionSet, fields, visitedFragmentNames) {
4305
- var e_1, _a;
4306
- try {
4307
- for (var _b = __values(selectionSet.selections), _c = _b.next(); !_c.done; _c = _b.next()) {
4308
- var selection = _c.value;
4309
- switch (selection.kind) {
4310
- case Kind.FIELD: {
4311
- if (!shouldIncludeNode(variableValues, selection)) {
4312
- continue;
4313
- }
4314
- var name_1 = getFieldEntryKey(selection);
4315
- var fieldList = fields.get(name_1);
4316
- if (fieldList !== undefined) {
4317
- fieldList.push(selection);
4318
- }
4319
- else {
4320
- fields.set(name_1, [selection]);
4321
- }
4322
- break;
4323
- }
4324
- case Kind.INLINE_FRAGMENT: {
4325
- if (!shouldIncludeNode(variableValues, selection) ||
4326
- !doesFragmentConditionMatch(schema, selection, runtimeType)) {
4327
- continue;
4328
- }
4329
- collectFields(schema, fragments, variableValues, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
4330
- break;
4331
- }
4332
- case Kind.FRAGMENT_SPREAD: {
4333
- var fragName = selection.name.value;
4334
- if (visitedFragmentNames.has(fragName) || !shouldIncludeNode(variableValues, selection)) {
4335
- continue;
4336
- }
4337
- visitedFragmentNames.add(fragName);
4338
- var fragment = fragments[fragName];
4339
- if (!fragment || !doesFragmentConditionMatch(schema, fragment, runtimeType)) {
4340
- continue;
4341
- }
4342
- collectFields(schema, fragments, variableValues, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
4343
- break;
4344
- }
4345
- }
4346
- }
4347
- }
4348
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4349
- finally {
4350
- try {
4351
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4352
- }
4353
- finally { if (e_1) throw e_1.error; }
4354
- }
4355
- return fields;
4356
- }
4357
- /**
4358
- * Determines if a field should be included based on the `@include` and `@skip`
4359
- * directives, where `@skip` has higher precedence than `@include`.
4360
- */
4361
- function shouldIncludeNode(variableValues, node) {
4362
- var skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues);
4363
- if ((skip === null || skip === void 0 ? void 0 : skip['if']) === true) {
4364
- return false;
4365
- }
4366
- var include = getDirectiveValues(GraphQLIncludeDirective, node, variableValues);
4367
- if ((include === null || include === void 0 ? void 0 : include['if']) === false) {
4368
- return false;
4369
- }
4370
- return true;
4371
- }
4372
- /**
4373
- * Determines if a fragment is applicable to the given type.
4374
- */
4375
- function doesFragmentConditionMatch(schema, fragment, type) {
4376
- var typeConditionNode = fragment.typeCondition;
4377
- if (!typeConditionNode) {
4378
- return true;
4379
- }
4380
- var conditionalType = typeFromAST(schema, typeConditionNode);
4381
- if (conditionalType === type) {
4382
- return true;
4383
- }
4384
- if (isAbstractType(conditionalType)) {
4385
- var possibleTypes = schema.getPossibleTypes(conditionalType);
4386
- return possibleTypes.includes(type);
4387
- }
4388
- return false;
4389
- }
4390
- /**
4391
- * Implements the logic to compute the key of a given field's entry
4392
- */
4393
- function getFieldEntryKey(node) {
4394
- return node.alias ? node.alias.value : node.name.value;
4395
- }
4396
- var collectSubFields = memoize5(function collectSubFields(schema, fragments, variableValues, type, fieldNodes) {
4397
- var e_2, _a;
4398
- var subFieldNodes = new Map();
4399
- var visitedFragmentNames = new Set();
4400
- try {
4401
- for (var fieldNodes_1 = __values(fieldNodes), fieldNodes_1_1 = fieldNodes_1.next(); !fieldNodes_1_1.done; fieldNodes_1_1 = fieldNodes_1.next()) {
4402
- var fieldNode = fieldNodes_1_1.value;
4403
- if (fieldNode.selectionSet) {
4404
- collectFields(schema, fragments, variableValues, type, fieldNode.selectionSet, subFieldNodes, visitedFragmentNames);
4405
- }
4406
- }
4407
- }
4408
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
4409
- finally {
4410
- try {
4411
- if (fieldNodes_1_1 && !fieldNodes_1_1.done && (_a = fieldNodes_1.return)) _a.call(fieldNodes_1);
4412
- }
4413
- finally { if (e_2) throw e_2.error; }
4414
- }
4415
- return subFieldNodes;
4416
- });
4417
-
4418
- function visitData(data, enter, leave) {
4419
- if (Array.isArray(data)) {
4420
- return data.map(function (value) { return visitData(value, enter, leave); });
4421
- }
4422
- else if (typeof data === 'object') {
4423
- var newData = enter != null ? enter(data) : data;
4424
- if (newData != null) {
4425
- for (var key in newData) {
4426
- var value = newData[key];
4427
- newData[key] = visitData(value, enter, leave);
4428
- }
4429
- }
4430
- return leave != null ? leave(newData) : newData;
4431
- }
4432
- return data;
4433
- }
4434
- function visitErrors(errors, visitor) {
4435
- return errors.map(function (error) { return visitor(error); });
4436
- }
4437
- function visitResult(result, request, schema, resultVisitorMap, errorVisitorMap) {
4438
- var fragments = request.document.definitions.reduce(function (acc, def) {
4439
- if (def.kind === Kind.FRAGMENT_DEFINITION) {
4440
- acc[def.name.value] = def;
4441
- }
4442
- return acc;
4443
- }, {});
4444
- var variableValues = request.variables || {};
4445
- var errorInfo = {
4446
- segmentInfoMap: new Map(),
4447
- unpathedErrors: new Set(),
4448
- };
4449
- var data = result.data;
4450
- var errors = result.errors;
4451
- var visitingErrors = errors != null && errorVisitorMap != null;
4452
- var operationDocumentNode = getOperationAST(request.document, undefined);
4453
- if (data != null && operationDocumentNode != null) {
4454
- result.data = visitRoot(data, operationDocumentNode, schema, fragments, variableValues, resultVisitorMap, visitingErrors ? errors : undefined, errorInfo);
4455
- }
4456
- if (errors != null && errorVisitorMap) {
4457
- result.errors = visitErrorsByType(errors, errorVisitorMap, errorInfo);
4458
- }
4459
- return result;
4460
- }
4461
- function visitErrorsByType(errors, errorVisitorMap, errorInfo) {
4462
- var segmentInfoMap = errorInfo.segmentInfoMap;
4463
- var unpathedErrors = errorInfo.unpathedErrors;
4464
- var unpathedErrorVisitor = errorVisitorMap['__unpathed'];
4465
- return errors.map(function (originalError) {
4466
- var pathSegmentsInfo = segmentInfoMap.get(originalError);
4467
- var newError = pathSegmentsInfo == null
4468
- ? originalError
4469
- : pathSegmentsInfo.reduceRight(function (acc, segmentInfo) {
4470
- var typeName = segmentInfo.type.name;
4471
- var typeVisitorMap = errorVisitorMap[typeName];
4472
- if (typeVisitorMap == null) {
4473
- return acc;
4474
- }
4475
- var errorVisitor = typeVisitorMap[segmentInfo.fieldName];
4476
- return errorVisitor == null ? acc : errorVisitor(acc, segmentInfo.pathIndex);
4477
- }, originalError);
4478
- if (unpathedErrorVisitor && unpathedErrors.has(originalError)) {
4479
- return unpathedErrorVisitor(newError);
4480
- }
4481
- return newError;
4482
- });
4483
- }
4484
- function visitRoot(root, operation, schema, fragments, variableValues, resultVisitorMap, errors, errorInfo) {
4485
- var operationRootType = getOperationRootType(schema, operation);
4486
- var collectedFields = collectFields(schema, fragments, variableValues, operationRootType, operation.selectionSet, new Map(), new Set());
4487
- return visitObjectValue(root, operationRootType, collectedFields, schema, fragments, variableValues, resultVisitorMap, 0, errors, errorInfo);
4488
- }
4489
- function visitObjectValue(object, type, fieldNodeMap, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo) {
4490
- var e_1, _a, e_2, _b, e_3, _c;
4491
- var fieldMap = type.getFields();
4492
- var typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[type.name];
4493
- var enterObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__enter;
4494
- var newObject = enterObject != null ? enterObject(object) : object;
4495
- var sortedErrors;
4496
- var errorMap = null;
4497
- if (errors != null) {
4498
- sortedErrors = sortErrorsByPathSegment(errors, pathIndex);
4499
- errorMap = sortedErrors.errorMap;
4500
- try {
4501
- for (var _d = __values(sortedErrors.unpathedErrors), _e = _d.next(); !_e.done; _e = _d.next()) {
4502
- var error = _e.value;
4503
- errorInfo.unpathedErrors.add(error);
4504
- }
4505
- }
4506
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4507
- finally {
4508
- try {
4509
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
4510
- }
4511
- finally { if (e_1) throw e_1.error; }
4512
- }
4513
- }
4514
- try {
4515
- for (var fieldNodeMap_1 = __values(fieldNodeMap), fieldNodeMap_1_1 = fieldNodeMap_1.next(); !fieldNodeMap_1_1.done; fieldNodeMap_1_1 = fieldNodeMap_1.next()) {
4516
- var _f = __read(fieldNodeMap_1_1.value, 2), responseKey = _f[0], subFieldNodes = _f[1];
4517
- var fieldName = subFieldNodes[0].name.value;
4518
- var fieldType = fieldName === '__typename' ? TypeNameMetaFieldDef.type : fieldMap[fieldName].type;
4519
- var newPathIndex = pathIndex + 1;
4520
- var fieldErrors = void 0;
4521
- if (errorMap) {
4522
- fieldErrors = errorMap[responseKey];
4523
- if (fieldErrors != null) {
4524
- delete errorMap[responseKey];
4525
- }
4526
- addPathSegmentInfo(type, fieldName, newPathIndex, fieldErrors, errorInfo);
4527
- }
4528
- var newValue = visitFieldValue(object[responseKey], fieldType, subFieldNodes, schema, fragments, variableValues, resultVisitorMap, newPathIndex, fieldErrors, errorInfo);
4529
- updateObject(newObject, responseKey, newValue, typeVisitorMap, fieldName);
4530
- }
4531
- }
4532
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
4533
- finally {
4534
- try {
4535
- if (fieldNodeMap_1_1 && !fieldNodeMap_1_1.done && (_b = fieldNodeMap_1.return)) _b.call(fieldNodeMap_1);
4536
- }
4537
- finally { if (e_2) throw e_2.error; }
4538
- }
4539
- var oldTypename = newObject.__typename;
4540
- if (oldTypename != null) {
4541
- updateObject(newObject, '__typename', oldTypename, typeVisitorMap, '__typename');
4542
- }
4543
- if (errorMap) {
4544
- for (var errorsKey in errorMap) {
4545
- var errors_2 = errorMap[errorsKey];
4546
- try {
4547
- for (var errors_1 = (e_3 = void 0, __values(errors_2)), errors_1_1 = errors_1.next(); !errors_1_1.done; errors_1_1 = errors_1.next()) {
4548
- var error = errors_1_1.value;
4549
- errorInfo.unpathedErrors.add(error);
4550
- }
4551
- }
4552
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
4553
- finally {
4554
- try {
4555
- if (errors_1_1 && !errors_1_1.done && (_c = errors_1.return)) _c.call(errors_1);
4556
- }
4557
- finally { if (e_3) throw e_3.error; }
4558
- }
4559
- }
4560
- }
4561
- var leaveObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__leave;
4562
- return leaveObject != null ? leaveObject(newObject) : newObject;
4563
- }
4564
- function updateObject(object, responseKey, newValue, typeVisitorMap, fieldName) {
4565
- if (typeVisitorMap == null) {
4566
- object[responseKey] = newValue;
4567
- return;
4568
- }
4569
- var fieldVisitor = typeVisitorMap[fieldName];
4570
- if (fieldVisitor == null) {
4571
- object[responseKey] = newValue;
4572
- return;
4573
- }
4574
- var visitedValue = fieldVisitor(newValue);
4575
- if (visitedValue === undefined) {
4576
- delete object[responseKey];
4577
- return;
4578
- }
4579
- object[responseKey] = visitedValue;
4580
- }
4581
- function visitListValue(list, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo) {
4582
- return list.map(function (listMember) {
4583
- return visitFieldValue(listMember, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex + 1, errors, errorInfo);
4584
- });
4585
- }
4586
- function visitFieldValue(value, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo) {
4587
- if (errors === void 0) { errors = []; }
4588
- if (value == null) {
4589
- return value;
4590
- }
4591
- var nullableType = getNullableType(returnType);
4592
- if (isListType(nullableType)) {
4593
- return visitListValue(value, nullableType.ofType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
4594
- }
4595
- else if (isAbstractType(nullableType)) {
4596
- var finalType = schema.getType(value.__typename);
4597
- var collectedFields = collectSubFields(schema, fragments, variableValues, finalType, fieldNodes);
4598
- return visitObjectValue(value, finalType, collectedFields, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
4599
- }
4600
- else if (isObjectType(nullableType)) {
4601
- var collectedFields = collectSubFields(schema, fragments, variableValues, nullableType, fieldNodes);
4602
- return visitObjectValue(value, nullableType, collectedFields, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
4603
- }
4604
- var typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[nullableType.name];
4605
- if (typeVisitorMap == null) {
4606
- return value;
4607
- }
4608
- var visitedValue = typeVisitorMap(value);
4609
- return visitedValue === undefined ? value : visitedValue;
4610
- }
4611
- function sortErrorsByPathSegment(errors, pathIndex) {
4612
- var e_4, _a;
4613
- var _b;
4614
- var errorMap = Object.create(null);
4615
- var unpathedErrors = new Set();
4616
- try {
4617
- for (var errors_3 = __values(errors), errors_3_1 = errors_3.next(); !errors_3_1.done; errors_3_1 = errors_3.next()) {
4618
- var error = errors_3_1.value;
4619
- var pathSegment = (_b = error.path) === null || _b === void 0 ? void 0 : _b[pathIndex];
4620
- if (pathSegment == null) {
4621
- unpathedErrors.add(error);
4622
- continue;
4623
- }
4624
- if (pathSegment in errorMap) {
4625
- errorMap[pathSegment].push(error);
4626
- }
4627
- else {
4628
- errorMap[pathSegment] = [error];
4629
- }
4630
- }
4631
- }
4632
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
4633
- finally {
4634
- try {
4635
- if (errors_3_1 && !errors_3_1.done && (_a = errors_3.return)) _a.call(errors_3);
4636
- }
4637
- finally { if (e_4) throw e_4.error; }
4638
- }
4639
- return {
4640
- errorMap: errorMap,
4641
- unpathedErrors: unpathedErrors,
4642
- };
4643
- }
4644
- function addPathSegmentInfo(type, fieldName, pathIndex, errors, errorInfo) {
4645
- var e_5, _a;
4646
- if (errors === void 0) { errors = []; }
4647
- try {
4648
- for (var errors_4 = __values(errors), errors_4_1 = errors_4.next(); !errors_4_1.done; errors_4_1 = errors_4.next()) {
4649
- var error = errors_4_1.value;
4650
- var segmentInfo = {
4651
- type: type,
4652
- fieldName: fieldName,
4653
- pathIndex: pathIndex,
4654
- };
4655
- var pathSegmentsInfo = errorInfo.segmentInfoMap.get(error);
4656
- if (pathSegmentsInfo == null) {
4657
- errorInfo.segmentInfoMap.set(error, [segmentInfo]);
4658
- }
4659
- else {
4660
- pathSegmentsInfo.push(segmentInfo);
4661
- }
4662
- }
4663
- }
4664
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
4665
- finally {
4666
- try {
4667
- if (errors_4_1 && !errors_4_1.done && (_a = errors_4.return)) _a.call(errors_4);
4668
- }
4669
- finally { if (e_5) throw e_5.error; }
4670
- }
4671
- }
4672
-
4673
- function valueMatchesCriteria(value, criteria) {
4674
- if (value == null) {
4675
- return value === criteria;
4676
- }
4677
- else if (Array.isArray(value)) {
4678
- return Array.isArray(criteria) && value.every(function (val, index) { return valueMatchesCriteria(val, criteria[index]); });
4679
- }
4680
- else if (typeof value === 'object') {
4681
- return (typeof criteria === 'object' &&
4682
- criteria &&
4683
- Object.keys(criteria).every(function (propertyName) { return valueMatchesCriteria(value[propertyName], criteria[propertyName]); }));
4684
- }
4685
- else if (criteria instanceof RegExp) {
4686
- return criteria.test(value);
4687
- }
4688
- return value === criteria;
4689
- }
4690
-
4691
- function isAsyncIterable(value) {
4692
- return typeof value === 'object' && value != null && Symbol.asyncIterator in value;
4693
- }
4694
-
4695
- function isDocumentNode(object) {
4696
- return object && typeof object === 'object' && 'kind' in object && object.kind === Kind.DOCUMENT;
4697
- }
4698
-
4699
- function withCancel(asyncIteratorLike, onCancel) {
4700
- var asyncIterator = asyncIteratorLike[Symbol.asyncIterator]();
4701
- if (!asyncIterator.return) {
4702
- asyncIterator.return = function () { return Promise.resolve({ value: undefined, done: true }); };
4703
- }
4704
- var savedReturn = asyncIterator.return.bind(asyncIterator);
4705
- asyncIterator.return = function () {
4706
- onCancel();
4707
- return savedReturn();
4708
- };
4709
- return asyncIterator;
4710
- }
4711
-
4712
- export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, collectFields, collectSubFields, compareNodes, compareStrings, correctASTNodes, createNamedStub, createStub, createVariableNameGenerator, dedentBlockStringValue, filterSchema, forEachDefaultValue, forEachField, getArgumentValues, getBlockStringIndentation, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDescription, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, healSchema, healTypes, implementsAbstractType, inspect, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isNamedStub, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, memoize1, memoize2, memoize2of4, memoize3, memoize4, memoize5, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };