@graphql-tools/utils 8.7.0 → 8.8.0-alpha-6c480b2d.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 +229 -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 +223 -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
package/cjs/index.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./loaders.js"), exports);
5
+ tslib_1.__exportStar(require("./helpers.js"), exports);
6
+ tslib_1.__exportStar(require("./get-directives.js"), exports);
7
+ tslib_1.__exportStar(require("./get-fields-with-directives.js"), exports);
8
+ tslib_1.__exportStar(require("./get-implementing-types.js"), exports);
9
+ tslib_1.__exportStar(require("./print-schema-with-directives.js"), exports);
10
+ tslib_1.__exportStar(require("./get-fields-with-directives.js"), exports);
11
+ tslib_1.__exportStar(require("./validate-documents.js"), exports);
12
+ tslib_1.__exportStar(require("./parse-graphql-json.js"), exports);
13
+ tslib_1.__exportStar(require("./parse-graphql-sdl.js"), exports);
14
+ tslib_1.__exportStar(require("./build-operation-for-field.js"), exports);
15
+ tslib_1.__exportStar(require("./types.js"), exports);
16
+ tslib_1.__exportStar(require("./filterSchema.js"), exports);
17
+ tslib_1.__exportStar(require("./heal.js"), exports);
18
+ tslib_1.__exportStar(require("./getResolversFromSchema.js"), exports);
19
+ tslib_1.__exportStar(require("./forEachField.js"), exports);
20
+ tslib_1.__exportStar(require("./forEachDefaultValue.js"), exports);
21
+ tslib_1.__exportStar(require("./mapSchema.js"), exports);
22
+ tslib_1.__exportStar(require("./addTypes.js"), exports);
23
+ tslib_1.__exportStar(require("./rewire.js"), exports);
24
+ tslib_1.__exportStar(require("./prune.js"), exports);
25
+ tslib_1.__exportStar(require("./mergeDeep.js"), exports);
26
+ tslib_1.__exportStar(require("./Interfaces.js"), exports);
27
+ tslib_1.__exportStar(require("./stub.js"), exports);
28
+ tslib_1.__exportStar(require("./selectionSets.js"), exports);
29
+ tslib_1.__exportStar(require("./getResponseKeyFromInfo.js"), exports);
30
+ tslib_1.__exportStar(require("./fields.js"), exports);
31
+ tslib_1.__exportStar(require("./renameType.js"), exports);
32
+ tslib_1.__exportStar(require("./transformInputValue.js"), exports);
33
+ tslib_1.__exportStar(require("./mapAsyncIterator.js"), exports);
34
+ tslib_1.__exportStar(require("./updateArgument.js"), exports);
35
+ tslib_1.__exportStar(require("./implementsAbstractType.js"), exports);
36
+ tslib_1.__exportStar(require("./errors.js"), exports);
37
+ tslib_1.__exportStar(require("./observableToAsyncIterable.js"), exports);
38
+ tslib_1.__exportStar(require("./visitResult.js"), exports);
39
+ tslib_1.__exportStar(require("./getArgumentValues.js"), exports);
40
+ tslib_1.__exportStar(require("./valueMatchesCriteria.js"), exports);
41
+ tslib_1.__exportStar(require("./isAsyncIterable.js"), exports);
42
+ tslib_1.__exportStar(require("./isDocumentNode.js"), exports);
43
+ tslib_1.__exportStar(require("./astFromValueUntyped.js"), exports);
44
+ tslib_1.__exportStar(require("./executor.js"), exports);
45
+ tslib_1.__exportStar(require("./withCancel.js"), exports);
46
+ tslib_1.__exportStar(require("./AggregateError.js"), exports);
47
+ tslib_1.__exportStar(require("./rootTypes.js"), exports);
48
+ tslib_1.__exportStar(require("./comments.js"), exports);
49
+ tslib_1.__exportStar(require("./collectFields.js"), exports);
50
+ tslib_1.__exportStar(require("./inspect.js"), exports);
51
+ tslib_1.__exportStar(require("./memoize.js"), exports);
52
+ tslib_1.__exportStar(require("./fixSchemaAst.js"), exports);
53
+ tslib_1.__exportStar(require("./getOperationASTFromRequest.js"), exports);
package/cjs/inspect.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ // Taken from graphql-js
3
+ // https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.inspect = void 0;
6
+ const graphql_1 = require("graphql");
7
+ const AggregateError_js_1 = require("./AggregateError.js");
8
+ const MAX_RECURSIVE_DEPTH = 3;
9
+ /**
10
+ * Used to print values in error messages.
11
+ */
12
+ function inspect(value) {
13
+ return formatValue(value, []);
14
+ }
15
+ exports.inspect = inspect;
16
+ function formatValue(value, seenValues) {
17
+ switch (typeof value) {
18
+ case 'string':
19
+ return JSON.stringify(value);
20
+ case 'function':
21
+ return value.name ? `[function ${value.name}]` : '[function]';
22
+ case 'object':
23
+ return formatObjectValue(value, seenValues);
24
+ default:
25
+ return String(value);
26
+ }
27
+ }
28
+ function formatError(value) {
29
+ if (value instanceof graphql_1.GraphQLError) {
30
+ return value.toString();
31
+ }
32
+ return `${value.name}: ${value.message};\n ${value.stack}`;
33
+ }
34
+ function formatObjectValue(value, previouslySeenValues) {
35
+ if (value === null) {
36
+ return 'null';
37
+ }
38
+ if (value instanceof Error) {
39
+ if ((0, AggregateError_js_1.isAggregateError)(value)) {
40
+ return formatError(value) + '\n' + formatArray(value.errors, previouslySeenValues);
41
+ }
42
+ return formatError(value);
43
+ }
44
+ if (previouslySeenValues.includes(value)) {
45
+ return '[Circular]';
46
+ }
47
+ const seenValues = [...previouslySeenValues, value];
48
+ if (isJSONable(value)) {
49
+ const jsonValue = value.toJSON();
50
+ // check for infinite recursion
51
+ if (jsonValue !== value) {
52
+ return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
53
+ }
54
+ }
55
+ else if (Array.isArray(value)) {
56
+ return formatArray(value, seenValues);
57
+ }
58
+ return formatObject(value, seenValues);
59
+ }
60
+ function isJSONable(value) {
61
+ return typeof value.toJSON === 'function';
62
+ }
63
+ function formatObject(object, seenValues) {
64
+ const entries = Object.entries(object);
65
+ if (entries.length === 0) {
66
+ return '{}';
67
+ }
68
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
69
+ return '[' + getObjectTag(object) + ']';
70
+ }
71
+ const properties = entries.map(([key, value]) => key + ': ' + formatValue(value, seenValues));
72
+ return '{ ' + properties.join(', ') + ' }';
73
+ }
74
+ function formatArray(array, seenValues) {
75
+ if (array.length === 0) {
76
+ return '[]';
77
+ }
78
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
79
+ return '[Array]';
80
+ }
81
+ const len = array.length;
82
+ const remaining = array.length;
83
+ const items = [];
84
+ for (let i = 0; i < len; ++i) {
85
+ items.push(formatValue(array[i], seenValues));
86
+ }
87
+ if (remaining === 1) {
88
+ items.push('... 1 more item');
89
+ }
90
+ else if (remaining > 1) {
91
+ items.push(`... ${remaining} more items`);
92
+ }
93
+ return '[' + items.join(', ') + ']';
94
+ }
95
+ function getObjectTag(object) {
96
+ const tag = Object.prototype.toString
97
+ .call(object)
98
+ .replace(/^\[object /, '')
99
+ .replace(/]$/, '');
100
+ if (tag === 'Object' && typeof object.constructor === 'function') {
101
+ const name = object.constructor.name;
102
+ if (typeof name === 'string' && name !== '') {
103
+ return name;
104
+ }
105
+ }
106
+ return tag;
107
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAsyncIterable = void 0;
4
+ function isAsyncIterable(value) {
5
+ return (typeof value === 'object' &&
6
+ value != null &&
7
+ Symbol.asyncIterator in value &&
8
+ typeof value[Symbol.asyncIterator] === 'function');
9
+ }
10
+ exports.isAsyncIterable = isAsyncIterable;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDocumentNode = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function isDocumentNode(object) {
6
+ return object && typeof object === 'object' && 'kind' in object && object.kind === graphql_1.Kind.DOCUMENT;
7
+ }
8
+ exports.isDocumentNode = isDocumentNode;
package/cjs/loaders.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAsyncIterator = void 0;
4
+ /**
5
+ * Given an AsyncIterable and a callback function, return an AsyncIterator
6
+ * which produces values mapped via calling the callback function.
7
+ */
8
+ function mapAsyncIterator(iterator, callback, rejectCallback) {
9
+ let $return;
10
+ let abruptClose;
11
+ if (typeof iterator.return === 'function') {
12
+ $return = iterator.return;
13
+ abruptClose = (error) => {
14
+ const rethrow = () => Promise.reject(error);
15
+ return $return.call(iterator).then(rethrow, rethrow);
16
+ };
17
+ }
18
+ function mapResult(result) {
19
+ return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
20
+ }
21
+ let mapReject;
22
+ if (rejectCallback) {
23
+ // Capture rejectCallback to ensure it cannot be null.
24
+ const reject = rejectCallback;
25
+ mapReject = (error) => asyncMapValue(error, reject).then(iteratorResult, abruptClose);
26
+ }
27
+ return {
28
+ next() {
29
+ return iterator.next().then(mapResult, mapReject);
30
+ },
31
+ return() {
32
+ return $return
33
+ ? $return.call(iterator).then(mapResult, mapReject)
34
+ : Promise.resolve({ value: undefined, done: true });
35
+ },
36
+ throw(error) {
37
+ if (typeof iterator.throw === 'function') {
38
+ return iterator.throw(error).then(mapResult, mapReject);
39
+ }
40
+ return Promise.reject(error).catch(abruptClose);
41
+ },
42
+ [Symbol.asyncIterator]() {
43
+ return this;
44
+ },
45
+ };
46
+ }
47
+ exports.mapAsyncIterator = mapAsyncIterator;
48
+ function asyncMapValue(value, callback) {
49
+ return new Promise(resolve => resolve(callback(value)));
50
+ }
51
+ function iteratorResult(value) {
52
+ return { value, done: false };
53
+ }