@graphql-tools/utils 8.2.0 → 8.2.4

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