@graphql-tools/utils 8.7.0 → 8.8.0-alpha-b76ec274.0

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 (161) hide show
  1. package/cjs/AggregateError.js +25 -0
  2. package/cjs/Interfaces.js +31 -0
  3. package/cjs/addTypes.js +62 -0
  4. package/cjs/astFromType.js +31 -0
  5. package/cjs/astFromValueUntyped.js +78 -0
  6. package/cjs/build-operation-for-field.js +351 -0
  7. package/cjs/collectFields.js +98 -0
  8. package/cjs/comments.js +380 -0
  9. package/cjs/errors.js +22 -0
  10. package/cjs/executor.js +2 -0
  11. package/cjs/fields.js +115 -0
  12. package/cjs/filterSchema.js +66 -0
  13. package/cjs/fixSchemaAst.js +26 -0
  14. package/cjs/forEachDefaultValue.js +29 -0
  15. package/cjs/forEachField.js +19 -0
  16. package/cjs/get-directives.js +103 -0
  17. package/cjs/get-fields-with-directives.js +52 -0
  18. package/cjs/get-implementing-types.js +19 -0
  19. package/cjs/getArgumentValues.js +76 -0
  20. package/cjs/getObjectTypeFromTypeMap.js +13 -0
  21. package/cjs/getOperationASTFromRequest.js +16 -0
  22. package/cjs/getResolversFromSchema.js +73 -0
  23. package/cjs/getResponseKeyFromInfo.js +12 -0
  24. package/cjs/heal.js +177 -0
  25. package/cjs/helpers.js +76 -0
  26. package/cjs/implementsAbstractType.js +17 -0
  27. package/cjs/index.js +53 -0
  28. package/cjs/inspect.js +107 -0
  29. package/cjs/isAsyncIterable.js +10 -0
  30. package/cjs/isDocumentNode.js +8 -0
  31. package/cjs/loaders.js +2 -0
  32. package/cjs/mapAsyncIterator.js +53 -0
  33. package/cjs/mapSchema.js +470 -0
  34. package/cjs/memoize.js +189 -0
  35. package/cjs/mergeDeep.js +45 -0
  36. package/cjs/observableToAsyncIterable.js +85 -0
  37. package/cjs/package.json +1 -0
  38. package/cjs/parse-graphql-json.js +44 -0
  39. package/cjs/parse-graphql-sdl.js +84 -0
  40. package/cjs/print-schema-with-directives.js +494 -0
  41. package/cjs/prune.js +133 -0
  42. package/cjs/renameType.js +152 -0
  43. package/cjs/rewire.js +159 -0
  44. package/cjs/rootTypes.js +37 -0
  45. package/cjs/selectionSets.js +9 -0
  46. package/cjs/stub.js +68 -0
  47. package/cjs/transformInputValue.js +55 -0
  48. package/cjs/types.js +27 -0
  49. package/cjs/updateArgument.js +54 -0
  50. package/cjs/validate-documents.js +76 -0
  51. package/cjs/valueMatchesCriteria.js +21 -0
  52. package/cjs/visitResult.js +219 -0
  53. package/cjs/withCancel.js +56 -0
  54. package/esm/AggregateError.js +21 -0
  55. package/esm/Interfaces.js +28 -0
  56. package/esm/addTypes.js +58 -0
  57. package/esm/astFromType.js +27 -0
  58. package/esm/astFromValueUntyped.js +74 -0
  59. package/esm/build-operation-for-field.js +347 -0
  60. package/esm/collectFields.js +94 -0
  61. package/esm/comments.js +367 -0
  62. package/esm/errors.js +17 -0
  63. package/esm/executor.js +1 -0
  64. package/esm/fields.js +108 -0
  65. package/esm/filterSchema.js +62 -0
  66. package/esm/fixSchemaAst.js +22 -0
  67. package/esm/forEachDefaultValue.js +25 -0
  68. package/esm/forEachField.js +15 -0
  69. package/esm/get-directives.js +96 -0
  70. package/esm/get-fields-with-directives.js +48 -0
  71. package/esm/get-implementing-types.js +15 -0
  72. package/esm/getArgumentValues.js +72 -0
  73. package/esm/getObjectTypeFromTypeMap.js +9 -0
  74. package/esm/getOperationASTFromRequest.js +12 -0
  75. package/esm/getResolversFromSchema.js +69 -0
  76. package/esm/getResponseKeyFromInfo.js +8 -0
  77. package/esm/heal.js +172 -0
  78. package/esm/helpers.js +65 -0
  79. package/esm/implementsAbstractType.js +13 -0
  80. package/esm/index.js +50 -0
  81. package/esm/inspect.js +103 -0
  82. package/esm/isAsyncIterable.js +6 -0
  83. package/esm/isDocumentNode.js +4 -0
  84. package/esm/loaders.js +1 -0
  85. package/esm/mapAsyncIterator.js +49 -0
  86. package/esm/mapSchema.js +465 -0
  87. package/esm/memoize.js +180 -0
  88. package/esm/mergeDeep.js +41 -0
  89. package/esm/observableToAsyncIterable.js +81 -0
  90. package/esm/parse-graphql-json.js +40 -0
  91. package/esm/parse-graphql-sdl.js +78 -0
  92. package/esm/print-schema-with-directives.js +472 -0
  93. package/esm/prune.js +129 -0
  94. package/esm/renameType.js +148 -0
  95. package/esm/rewire.js +155 -0
  96. package/esm/rootTypes.js +33 -0
  97. package/esm/selectionSets.js +5 -0
  98. package/esm/stub.js +61 -0
  99. package/esm/transformInputValue.js +48 -0
  100. package/esm/types.js +24 -0
  101. package/esm/updateArgument.js +49 -0
  102. package/esm/validate-documents.js +70 -0
  103. package/esm/valueMatchesCriteria.js +17 -0
  104. package/esm/visitResult.js +213 -0
  105. package/esm/withCancel.js +51 -0
  106. package/package.json +31 -10
  107. package/{AggregateError.d.ts → typings/AggregateError.d.ts} +0 -0
  108. package/{Interfaces.d.ts → typings/Interfaces.d.ts} +0 -0
  109. package/{addTypes.d.ts → typings/addTypes.d.ts} +0 -0
  110. package/{astFromType.d.ts → typings/astFromType.d.ts} +0 -0
  111. package/{astFromValueUntyped.d.ts → typings/astFromValueUntyped.d.ts} +0 -0
  112. package/{build-operation-for-field.d.ts → typings/build-operation-for-field.d.ts} +0 -0
  113. package/{collectFields.d.ts → typings/collectFields.d.ts} +0 -0
  114. package/{comments.d.ts → typings/comments.d.ts} +0 -0
  115. package/{errors.d.ts → typings/errors.d.ts} +1 -1
  116. package/{executor.d.ts → typings/executor.d.ts} +1 -1
  117. package/{fields.d.ts → typings/fields.d.ts} +0 -0
  118. package/{filterSchema.d.ts → typings/filterSchema.d.ts} +1 -1
  119. package/{fixSchemaAst.d.ts → typings/fixSchemaAst.d.ts} +1 -1
  120. package/{forEachDefaultValue.d.ts → typings/forEachDefaultValue.d.ts} +1 -1
  121. package/{forEachField.d.ts → typings/forEachField.d.ts} +1 -1
  122. package/{get-directives.d.ts → typings/get-directives.d.ts} +0 -0
  123. package/{get-fields-with-directives.d.ts → typings/get-fields-with-directives.d.ts} +0 -0
  124. package/{get-implementing-types.d.ts → typings/get-implementing-types.d.ts} +0 -0
  125. package/{getArgumentValues.d.ts → typings/getArgumentValues.d.ts} +0 -0
  126. package/{getObjectTypeFromTypeMap.d.ts → typings/getObjectTypeFromTypeMap.d.ts} +1 -1
  127. package/{getOperationASTFromRequest.d.ts → typings/getOperationASTFromRequest.d.ts} +1 -1
  128. package/{getResolversFromSchema.d.ts → typings/getResolversFromSchema.d.ts} +1 -1
  129. package/{getResponseKeyFromInfo.d.ts → typings/getResponseKeyFromInfo.d.ts} +0 -0
  130. package/{heal.d.ts → typings/heal.d.ts} +0 -0
  131. package/{helpers.d.ts → typings/helpers.d.ts} +0 -0
  132. package/{implementsAbstractType.d.ts → typings/implementsAbstractType.d.ts} +1 -1
  133. package/typings/index.d.ts +50 -0
  134. package/{inspect.d.ts → typings/inspect.d.ts} +0 -0
  135. package/{isAsyncIterable.d.ts → typings/isAsyncIterable.d.ts} +0 -0
  136. package/{isDocumentNode.d.ts → typings/isDocumentNode.d.ts} +0 -0
  137. package/{loaders.d.ts → typings/loaders.d.ts} +1 -1
  138. package/{mapAsyncIterator.d.ts → typings/mapAsyncIterator.d.ts} +0 -0
  139. package/{mapSchema.d.ts → typings/mapSchema.d.ts} +1 -1
  140. package/{memoize.d.ts → typings/memoize.d.ts} +0 -0
  141. package/{mergeDeep.d.ts → typings/mergeDeep.d.ts} +0 -0
  142. package/{observableToAsyncIterable.d.ts → typings/observableToAsyncIterable.d.ts} +0 -0
  143. package/{parse-graphql-json.d.ts → typings/parse-graphql-json.d.ts} +2 -2
  144. package/{parse-graphql-sdl.d.ts → typings/parse-graphql-sdl.d.ts} +1 -1
  145. package/{print-schema-with-directives.d.ts → typings/print-schema-with-directives.d.ts} +1 -1
  146. package/{prune.d.ts → typings/prune.d.ts} +1 -1
  147. package/{renameType.d.ts → typings/renameType.d.ts} +0 -0
  148. package/{rewire.d.ts → typings/rewire.d.ts} +0 -0
  149. package/{rootTypes.d.ts → typings/rootTypes.d.ts} +0 -0
  150. package/{selectionSets.d.ts → typings/selectionSets.d.ts} +1 -1
  151. package/{stub.d.ts → typings/stub.d.ts} +0 -0
  152. package/{transformInputValue.d.ts → typings/transformInputValue.d.ts} +1 -1
  153. package/{types.d.ts → typings/types.d.ts} +0 -0
  154. package/{updateArgument.d.ts → typings/updateArgument.d.ts} +0 -0
  155. package/{validate-documents.d.ts → typings/validate-documents.d.ts} +1 -1
  156. package/{valueMatchesCriteria.d.ts → typings/valueMatchesCriteria.d.ts} +0 -0
  157. package/{visitResult.d.ts → typings/visitResult.d.ts} +1 -1
  158. package/{withCancel.d.ts → typings/withCancel.d.ts} +0 -0
  159. package/index.d.ts +0 -50
  160. package/index.js +0 -4428
  161. package/index.mjs +0 -4315
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDirective = exports.getDirectives = exports.getDirectiveInExtensions = exports.getDirectivesInExtensions = void 0;
4
+ const getArgumentValues_js_1 = require("./getArgumentValues.js");
5
+ function getDirectivesInExtensions(node, pathToDirectivesInExtensions = ['directives']) {
6
+ return pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node === null || node === void 0 ? void 0 : node.extensions);
7
+ }
8
+ exports.getDirectivesInExtensions = getDirectivesInExtensions;
9
+ function _getDirectiveInExtensions(directivesInExtensions, directiveName) {
10
+ const directiveInExtensions = directivesInExtensions.filter(directiveAnnotation => directiveAnnotation.name === directiveName);
11
+ if (!directiveInExtensions.length) {
12
+ return undefined;
13
+ }
14
+ return directiveInExtensions.map(directive => { var _a; return (_a = directive.args) !== null && _a !== void 0 ? _a : {}; });
15
+ }
16
+ function getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions = ['directives']) {
17
+ const directivesInExtensions = pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node === null || node === void 0 ? void 0 : node.extensions);
18
+ if (directivesInExtensions === undefined) {
19
+ return undefined;
20
+ }
21
+ if (Array.isArray(directivesInExtensions)) {
22
+ return _getDirectiveInExtensions(directivesInExtensions, directiveName);
23
+ }
24
+ // Support condensed format by converting to longer format
25
+ // The condensed format does not preserve ordering of directives when repeatable directives are used.
26
+ // See https://github.com/ardatan/graphql-tools/issues/2534
27
+ const reformattedDirectivesInExtensions = [];
28
+ for (const [name, argsOrArrayOfArgs] of Object.entries(directivesInExtensions)) {
29
+ if (Array.isArray(argsOrArrayOfArgs)) {
30
+ for (const args of argsOrArrayOfArgs) {
31
+ reformattedDirectivesInExtensions.push({ name, args });
32
+ }
33
+ }
34
+ else {
35
+ reformattedDirectivesInExtensions.push({ name, args: argsOrArrayOfArgs });
36
+ }
37
+ }
38
+ return _getDirectiveInExtensions(reformattedDirectivesInExtensions, directiveName);
39
+ }
40
+ exports.getDirectiveInExtensions = getDirectiveInExtensions;
41
+ function getDirectives(schema, node, pathToDirectivesInExtensions = ['directives']) {
42
+ const directivesInExtensions = getDirectivesInExtensions(node, pathToDirectivesInExtensions);
43
+ if (directivesInExtensions != null && directivesInExtensions.length > 0) {
44
+ return directivesInExtensions;
45
+ }
46
+ const schemaDirectives = schema && schema.getDirectives ? schema.getDirectives() : [];
47
+ const schemaDirectiveMap = schemaDirectives.reduce((schemaDirectiveMap, schemaDirective) => {
48
+ schemaDirectiveMap[schemaDirective.name] = schemaDirective;
49
+ return schemaDirectiveMap;
50
+ }, {});
51
+ let astNodes = [];
52
+ if (node.astNode) {
53
+ astNodes.push(node.astNode);
54
+ }
55
+ if ('extensionASTNodes' in node && node.extensionASTNodes) {
56
+ astNodes = [...astNodes, ...node.extensionASTNodes];
57
+ }
58
+ const result = [];
59
+ for (const astNode of astNodes) {
60
+ if (astNode.directives) {
61
+ for (const directiveNode of astNode.directives) {
62
+ const schemaDirective = schemaDirectiveMap[directiveNode.name.value];
63
+ if (schemaDirective) {
64
+ result.push({ name: directiveNode.name.value, args: (0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode) });
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+ exports.getDirectives = getDirectives;
72
+ function getDirective(schema, node, directiveName, pathToDirectivesInExtensions = ['directives']) {
73
+ const directiveInExtensions = getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions);
74
+ if (directiveInExtensions != null) {
75
+ return directiveInExtensions;
76
+ }
77
+ const schemaDirective = schema && schema.getDirective ? schema.getDirective(directiveName) : undefined;
78
+ if (schemaDirective == null) {
79
+ return undefined;
80
+ }
81
+ let astNodes = [];
82
+ if (node.astNode) {
83
+ astNodes.push(node.astNode);
84
+ }
85
+ if ('extensionASTNodes' in node && node.extensionASTNodes) {
86
+ astNodes = [...astNodes, ...node.extensionASTNodes];
87
+ }
88
+ const result = [];
89
+ for (const astNode of astNodes) {
90
+ if (astNode.directives) {
91
+ for (const directiveNode of astNode.directives) {
92
+ if (directiveNode.name.value === directiveName) {
93
+ result.push((0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode));
94
+ }
95
+ }
96
+ }
97
+ }
98
+ if (!result.length) {
99
+ return undefined;
100
+ }
101
+ return result;
102
+ }
103
+ exports.getDirective = getDirective;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFieldsWithDirectives = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function parseDirectiveValue(value) {
6
+ switch (value.kind) {
7
+ case graphql_1.Kind.INT:
8
+ return parseInt(value.value);
9
+ case graphql_1.Kind.FLOAT:
10
+ return parseFloat(value.value);
11
+ case graphql_1.Kind.BOOLEAN:
12
+ return Boolean(value.value);
13
+ case graphql_1.Kind.STRING:
14
+ case graphql_1.Kind.ENUM:
15
+ return value.value;
16
+ case graphql_1.Kind.LIST:
17
+ return value.values.map(v => parseDirectiveValue(v));
18
+ case graphql_1.Kind.OBJECT:
19
+ return value.fields.reduce((prev, v) => ({ ...prev, [v.name.value]: parseDirectiveValue(v.value) }), {});
20
+ case graphql_1.Kind.NULL:
21
+ return null;
22
+ default:
23
+ return null;
24
+ }
25
+ }
26
+ function getFieldsWithDirectives(documentNode, options = {}) {
27
+ const result = {};
28
+ let selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
29
+ if (options.includeInputTypes) {
30
+ selected = [...selected, 'InputObjectTypeDefinition', 'InputObjectTypeExtension'];
31
+ }
32
+ const allTypes = documentNode.definitions.filter(obj => selected.includes(obj.kind));
33
+ for (const type of allTypes) {
34
+ const typeName = type.name.value;
35
+ if (type.fields == null) {
36
+ continue;
37
+ }
38
+ for (const field of type.fields) {
39
+ if (field.directives && field.directives.length > 0) {
40
+ const fieldName = field.name.value;
41
+ const key = `${typeName}.${fieldName}`;
42
+ const directives = field.directives.map(d => ({
43
+ name: d.name.value,
44
+ args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]: parseDirectiveValue(arg.value) }), {}),
45
+ }));
46
+ result[key] = directives;
47
+ }
48
+ }
49
+ }
50
+ return result;
51
+ }
52
+ exports.getFieldsWithDirectives = getFieldsWithDirectives;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImplementingTypes = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function getImplementingTypes(interfaceName, schema) {
6
+ const allTypesMap = schema.getTypeMap();
7
+ const result = [];
8
+ for (const graphqlTypeName in allTypesMap) {
9
+ const graphqlType = allTypesMap[graphqlTypeName];
10
+ if ((0, graphql_1.isObjectType)(graphqlType)) {
11
+ const allInterfaces = graphqlType.getInterfaces();
12
+ if (allInterfaces.find(int => int.name === interfaceName)) {
13
+ result.push(graphqlType.name);
14
+ }
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+ exports.getImplementingTypes = getImplementingTypes;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getArgumentValues = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const errors_js_1 = require("./errors.js");
6
+ const inspect_js_1 = require("./inspect.js");
7
+ /**
8
+ * Prepares an object map of argument values given a list of argument
9
+ * definitions and list of argument AST nodes.
10
+ *
11
+ * Note: The returned value is a plain Object with a prototype, since it is
12
+ * exposed to user code. Care should be taken to not pull values from the
13
+ * Object prototype.
14
+ */
15
+ function getArgumentValues(def, node, variableValues = {}) {
16
+ var _a;
17
+ const variableMap = Object.entries(variableValues).reduce((prev, [key, value]) => ({
18
+ ...prev,
19
+ [key]: value,
20
+ }), {});
21
+ const coercedValues = {};
22
+ const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
23
+ const argNodeMap = argumentNodes.reduce((prev, arg) => ({
24
+ ...prev,
25
+ [arg.name.value]: arg,
26
+ }), {});
27
+ for (const { name, type: argType, defaultValue } of def.args) {
28
+ const argumentNode = argNodeMap[name];
29
+ if (!argumentNode) {
30
+ if (defaultValue !== undefined) {
31
+ coercedValues[name] = defaultValue;
32
+ }
33
+ else if ((0, graphql_1.isNonNullType)(argType)) {
34
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` + 'was not provided.', {
35
+ nodes: [node],
36
+ });
37
+ }
38
+ continue;
39
+ }
40
+ const valueNode = argumentNode.value;
41
+ let isNull = valueNode.kind === graphql_1.Kind.NULL;
42
+ if (valueNode.kind === graphql_1.Kind.VARIABLE) {
43
+ const variableName = valueNode.name.value;
44
+ if (variableValues == null || variableMap[variableName] == null) {
45
+ if (defaultValue !== undefined) {
46
+ coercedValues[name] = defaultValue;
47
+ }
48
+ else if ((0, graphql_1.isNonNullType)(argType)) {
49
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` +
50
+ `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
51
+ nodes: [valueNode],
52
+ });
53
+ }
54
+ continue;
55
+ }
56
+ isNull = variableValues[variableName] == null;
57
+ }
58
+ if (isNull && (0, graphql_1.isNonNullType)(argType)) {
59
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, inspect_js_1.inspect)(argType)}" ` + 'must not be null.', {
60
+ nodes: [valueNode],
61
+ });
62
+ }
63
+ const coercedValue = (0, graphql_1.valueFromAST)(valueNode, argType, variableValues);
64
+ if (coercedValue === undefined) {
65
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
66
+ // execution. This is a runtime check to ensure execution does not
67
+ // continue with an invalid argument value.
68
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, {
69
+ nodes: [valueNode],
70
+ });
71
+ }
72
+ coercedValues[name] = coercedValue;
73
+ }
74
+ return coercedValues;
75
+ }
76
+ exports.getArgumentValues = getArgumentValues;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getObjectTypeFromTypeMap = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function getObjectTypeFromTypeMap(typeMap, type) {
6
+ if (type) {
7
+ const maybeObjectType = typeMap[type.name];
8
+ if ((0, graphql_1.isObjectType)(maybeObjectType)) {
9
+ return maybeObjectType;
10
+ }
11
+ }
12
+ }
13
+ exports.getObjectTypeFromTypeMap = getObjectTypeFromTypeMap;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOperationASTFromRequest = exports.getOperationASTFromDocument = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const memoize_js_1 = require("./memoize.js");
6
+ function getOperationASTFromDocument(documentNode, operationName) {
7
+ const doc = (0, graphql_1.getOperationAST)(documentNode, operationName);
8
+ if (!doc) {
9
+ throw new Error(`Cannot infer operation ${operationName || ''}`);
10
+ }
11
+ return doc;
12
+ }
13
+ exports.getOperationASTFromDocument = getOperationASTFromDocument;
14
+ exports.getOperationASTFromRequest = (0, memoize_js_1.memoize1)(function getOperationASTFromRequest(request) {
15
+ return getOperationASTFromDocument(request.document, request.operationName);
16
+ });
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResolversFromSchema = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function getResolversFromSchema(schema,
6
+ // Include default merged resolvers
7
+ includeDefaultMergedResolver) {
8
+ var _a, _b;
9
+ const resolvers = Object.create(null);
10
+ const typeMap = schema.getTypeMap();
11
+ for (const typeName in typeMap) {
12
+ if (!typeName.startsWith('__')) {
13
+ const type = typeMap[typeName];
14
+ if ((0, graphql_1.isScalarType)(type)) {
15
+ if (!(0, graphql_1.isSpecifiedScalarType)(type)) {
16
+ const config = type.toConfig();
17
+ delete config.astNode; // avoid AST duplication elsewhere
18
+ resolvers[typeName] = new graphql_1.GraphQLScalarType(config);
19
+ }
20
+ }
21
+ else if ((0, graphql_1.isEnumType)(type)) {
22
+ resolvers[typeName] = {};
23
+ const values = type.getValues();
24
+ for (const value of values) {
25
+ resolvers[typeName][value.name] = value.value;
26
+ }
27
+ }
28
+ else if ((0, graphql_1.isInterfaceType)(type)) {
29
+ if (type.resolveType != null) {
30
+ resolvers[typeName] = {
31
+ __resolveType: type.resolveType,
32
+ };
33
+ }
34
+ }
35
+ else if ((0, graphql_1.isUnionType)(type)) {
36
+ if (type.resolveType != null) {
37
+ resolvers[typeName] = {
38
+ __resolveType: type.resolveType,
39
+ };
40
+ }
41
+ }
42
+ else if ((0, graphql_1.isObjectType)(type)) {
43
+ resolvers[typeName] = {};
44
+ if (type.isTypeOf != null) {
45
+ resolvers[typeName].__isTypeOf = type.isTypeOf;
46
+ }
47
+ const fields = type.getFields();
48
+ for (const fieldName in fields) {
49
+ const field = fields[fieldName];
50
+ if (field.subscribe != null) {
51
+ resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
52
+ resolvers[typeName][fieldName].subscribe = field.subscribe;
53
+ }
54
+ if (field.resolve != null && ((_a = field.resolve) === null || _a === void 0 ? void 0 : _a.name) !== 'defaultFieldResolver') {
55
+ switch ((_b = field.resolve) === null || _b === void 0 ? void 0 : _b.name) {
56
+ case 'defaultMergedResolver':
57
+ if (!includeDefaultMergedResolver) {
58
+ continue;
59
+ }
60
+ break;
61
+ case 'defaultFieldResolver':
62
+ continue;
63
+ }
64
+ resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
65
+ resolvers[typeName][fieldName].resolve = field.resolve;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ return resolvers;
72
+ }
73
+ exports.getResolversFromSchema = getResolversFromSchema;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResponseKeyFromInfo = void 0;
4
+ /**
5
+ * Get the key under which the result of this resolver will be placed in the response JSON. Basically, just
6
+ * resolves aliases.
7
+ * @param info The info argument to the resolver.
8
+ */
9
+ function getResponseKeyFromInfo(info) {
10
+ return info.fieldNodes[0].alias != null ? info.fieldNodes[0].alias.value : info.fieldName;
11
+ }
12
+ exports.getResponseKeyFromInfo = getResponseKeyFromInfo;
package/cjs/heal.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.healTypes = exports.healSchema = void 0;
4
+ const graphql_1 = require("graphql");
5
+ // Update any references to named schema types that disagree with the named
6
+ // types found in schema.getTypeMap().
7
+ //
8
+ // healSchema and its callers (visitSchema/visitSchemaDirectives) all modify the schema in place.
9
+ // Therefore, private variables (such as the stored implementation map and the proper root types)
10
+ // are not updated.
11
+ //
12
+ // If this causes issues, the schema could be more aggressively healed as follows:
13
+ //
14
+ // healSchema(schema);
15
+ // const config = schema.toConfig()
16
+ // const healedSchema = new GraphQLSchema({
17
+ // ...config,
18
+ // query: schema.getType('<desired new root query type name>'),
19
+ // mutation: schema.getType('<desired new root mutation type name>'),
20
+ // subscription: schema.getType('<desired new root subscription type name>'),
21
+ // });
22
+ //
23
+ // One can then also -- if necessary -- assign the correct private variables to the initial schema
24
+ // as follows:
25
+ // Object.assign(schema, healedSchema);
26
+ //
27
+ // These steps are not taken automatically to preserve backwards compatibility with graphql-tools v4.
28
+ // See https://github.com/ardatan/graphql-tools/issues/1462
29
+ //
30
+ // They were briefly taken in v5, but can now be phased out as they were only required when other
31
+ // areas of the codebase were using healSchema and visitSchema more extensively.
32
+ //
33
+ function healSchema(schema) {
34
+ healTypes(schema.getTypeMap(), schema.getDirectives());
35
+ return schema;
36
+ }
37
+ exports.healSchema = healSchema;
38
+ function healTypes(originalTypeMap, directives) {
39
+ const actualNamedTypeMap = Object.create(null);
40
+ // If any of the .name properties of the GraphQLNamedType objects in
41
+ // schema.getTypeMap() have changed, the keys of the type map need to
42
+ // be updated accordingly.
43
+ for (const typeName in originalTypeMap) {
44
+ const namedType = originalTypeMap[typeName];
45
+ if (namedType == null || typeName.startsWith('__')) {
46
+ continue;
47
+ }
48
+ const actualName = namedType.name;
49
+ if (actualName.startsWith('__')) {
50
+ continue;
51
+ }
52
+ if (actualName in actualNamedTypeMap) {
53
+ throw new Error(`Duplicate schema type name ${actualName}`);
54
+ }
55
+ actualNamedTypeMap[actualName] = namedType;
56
+ // Note: we are deliberately leaving namedType in the schema by its
57
+ // original name (which might be different from actualName), so that
58
+ // references by that name can be healed.
59
+ }
60
+ // Now add back every named type by its actual name.
61
+ for (const typeName in actualNamedTypeMap) {
62
+ const namedType = actualNamedTypeMap[typeName];
63
+ originalTypeMap[typeName] = namedType;
64
+ }
65
+ // Directive declaration argument types can refer to named types.
66
+ for (const decl of directives) {
67
+ decl.args = decl.args.filter(arg => {
68
+ arg.type = healType(arg.type);
69
+ return arg.type !== null;
70
+ });
71
+ }
72
+ for (const typeName in originalTypeMap) {
73
+ const namedType = originalTypeMap[typeName];
74
+ // Heal all named types, except for dangling references, kept only to redirect.
75
+ if (!typeName.startsWith('__') && typeName in actualNamedTypeMap) {
76
+ if (namedType != null) {
77
+ healNamedType(namedType);
78
+ }
79
+ }
80
+ }
81
+ for (const typeName in originalTypeMap) {
82
+ if (!typeName.startsWith('__') && !(typeName in actualNamedTypeMap)) {
83
+ delete originalTypeMap[typeName];
84
+ }
85
+ }
86
+ function healNamedType(type) {
87
+ if ((0, graphql_1.isObjectType)(type)) {
88
+ healFields(type);
89
+ healInterfaces(type);
90
+ return;
91
+ }
92
+ else if ((0, graphql_1.isInterfaceType)(type)) {
93
+ healFields(type);
94
+ if ('getInterfaces' in type) {
95
+ healInterfaces(type);
96
+ }
97
+ return;
98
+ }
99
+ else if ((0, graphql_1.isUnionType)(type)) {
100
+ healUnderlyingTypes(type);
101
+ return;
102
+ }
103
+ else if ((0, graphql_1.isInputObjectType)(type)) {
104
+ healInputFields(type);
105
+ return;
106
+ }
107
+ else if ((0, graphql_1.isLeafType)(type)) {
108
+ return;
109
+ }
110
+ throw new Error(`Unexpected schema type: ${type}`);
111
+ }
112
+ function healFields(type) {
113
+ const fieldMap = type.getFields();
114
+ for (const [key, field] of Object.entries(fieldMap)) {
115
+ field.args
116
+ .map(arg => {
117
+ arg.type = healType(arg.type);
118
+ return arg.type === null ? null : arg;
119
+ })
120
+ .filter(Boolean);
121
+ field.type = healType(field.type);
122
+ if (field.type === null) {
123
+ delete fieldMap[key];
124
+ }
125
+ }
126
+ }
127
+ function healInterfaces(type) {
128
+ if ('getInterfaces' in type) {
129
+ const interfaces = type.getInterfaces();
130
+ interfaces.push(...interfaces
131
+ .splice(0)
132
+ .map(iface => healType(iface))
133
+ .filter(Boolean));
134
+ }
135
+ }
136
+ function healInputFields(type) {
137
+ const fieldMap = type.getFields();
138
+ for (const [key, field] of Object.entries(fieldMap)) {
139
+ field.type = healType(field.type);
140
+ if (field.type === null) {
141
+ delete fieldMap[key];
142
+ }
143
+ }
144
+ }
145
+ function healUnderlyingTypes(type) {
146
+ const types = type.getTypes();
147
+ types.push(...types
148
+ .splice(0)
149
+ .map(t => healType(t))
150
+ .filter(Boolean));
151
+ }
152
+ function healType(type) {
153
+ // Unwrap the two known wrapper types
154
+ if ((0, graphql_1.isListType)(type)) {
155
+ const healedType = healType(type.ofType);
156
+ return healedType != null ? new graphql_1.GraphQLList(healedType) : null;
157
+ }
158
+ else if ((0, graphql_1.isNonNullType)(type)) {
159
+ const healedType = healType(type.ofType);
160
+ return healedType != null ? new graphql_1.GraphQLNonNull(healedType) : null;
161
+ }
162
+ else if ((0, graphql_1.isNamedType)(type)) {
163
+ // If a type annotation on a field or an argument or a union member is
164
+ // any `GraphQLNamedType` with a `name`, then it must end up identical
165
+ // to `schema.getType(name)`, since `schema.getTypeMap()` is the source
166
+ // of truth for all named schema types.
167
+ // Note that new types can still be simply added by adding a field, as
168
+ // the official type will be undefined, not null.
169
+ const officialType = originalTypeMap[type.name];
170
+ if (officialType && type !== officialType) {
171
+ return officialType;
172
+ }
173
+ }
174
+ return type;
175
+ }
176
+ }
177
+ exports.healTypes = healTypes;
package/cjs/helpers.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertSome = exports.isSome = exports.compareNodes = exports.nodeToString = exports.compareStrings = exports.isValidPath = exports.isDocumentString = exports.asArray = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
6
+ exports.asArray = asArray;
7
+ const invalidDocRegex = /\.[a-z0-9]+$/i;
8
+ function isDocumentString(str) {
9
+ if (typeof str !== 'string') {
10
+ return false;
11
+ }
12
+ // XXX: is-valid-path or is-glob treat SDL as a valid path
13
+ // (`scalar Date` for example)
14
+ // this why checking the extension is fast enough
15
+ // and prevent from parsing the string in order to find out
16
+ // if the string is a SDL
17
+ if (invalidDocRegex.test(str)) {
18
+ return false;
19
+ }
20
+ try {
21
+ (0, graphql_1.parse)(str);
22
+ return true;
23
+ }
24
+ catch (e) { }
25
+ return false;
26
+ }
27
+ exports.isDocumentString = isDocumentString;
28
+ const invalidPathRegex = /[‘“!%&^<=>`]/;
29
+ function isValidPath(str) {
30
+ return typeof str === 'string' && !invalidPathRegex.test(str);
31
+ }
32
+ exports.isValidPath = isValidPath;
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
+ exports.compareStrings = compareStrings;
43
+ function nodeToString(a) {
44
+ var _a, _b;
45
+ let name;
46
+ if ('alias' in a) {
47
+ name = (_a = a.alias) === null || _a === void 0 ? void 0 : _a.value;
48
+ }
49
+ if (name == null && 'name' in a) {
50
+ name = (_b = a.name) === null || _b === void 0 ? void 0 : _b.value;
51
+ }
52
+ if (name == null) {
53
+ name = a.kind;
54
+ }
55
+ return name;
56
+ }
57
+ exports.nodeToString = nodeToString;
58
+ function compareNodes(a, b, customFn) {
59
+ const aStr = nodeToString(a);
60
+ const bStr = nodeToString(b);
61
+ if (typeof customFn === 'function') {
62
+ return customFn(aStr, bStr);
63
+ }
64
+ return compareStrings(aStr, bStr);
65
+ }
66
+ exports.compareNodes = compareNodes;
67
+ function isSome(input) {
68
+ return input != null;
69
+ }
70
+ exports.isSome = isSome;
71
+ function assertSome(input, message = 'Value should be something') {
72
+ if (input == null) {
73
+ throw new Error(message);
74
+ }
75
+ }
76
+ exports.assertSome = assertSome;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.implementsAbstractType = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function implementsAbstractType(schema, typeA, typeB) {
6
+ if (typeB == null || typeA == null) {
7
+ return false;
8
+ }
9
+ else if (typeA === typeB) {
10
+ return true;
11
+ }
12
+ else if ((0, graphql_1.isCompositeType)(typeA) && (0, graphql_1.isCompositeType)(typeB)) {
13
+ return (0, graphql_1.doTypesOverlap)(schema, typeA, typeB);
14
+ }
15
+ return false;
16
+ }
17
+ exports.implementsAbstractType = implementsAbstractType;