@graphitation/supermassive 0.1.1 → 0.3.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 (192) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +264 -2
  3. package/bin/supermassive.js +7 -0
  4. package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
  5. package/lib/ast/TypedAST.d.ts.map +1 -0
  6. package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
  7. package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
  8. package/lib/ast/addTypesToRequestDocument.js +8 -5
  9. package/lib/ast/addTypesToRequestDocument.mjs +12 -6
  10. package/lib/benchmarks/index.d.ts.map +1 -1
  11. package/lib/benchmarks/index.js +127 -0
  12. package/lib/benchmarks/index.mjs +111 -0
  13. package/lib/benchmarks/nice-benchmark.d.ts +1 -1
  14. package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
  15. package/lib/benchmarks/nice-benchmark.js +72 -0
  16. package/lib/benchmarks/nice-benchmark.mjs +52 -0
  17. package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
  18. package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
  19. package/lib/benchmarks/swapi-schema/index.js +39 -0
  20. package/lib/benchmarks/swapi-schema/index.mjs +17 -0
  21. package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
  22. package/lib/benchmarks/swapi-schema/models.js +29 -0
  23. package/lib/benchmarks/swapi-schema/models.mjs +7 -0
  24. package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
  25. package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
  26. package/lib/benchmarks/swapi-schema/resolvers.mjs +230 -0
  27. package/lib/bin/supermassive.d.ts +3 -0
  28. package/lib/bin/supermassive.d.ts.map +1 -0
  29. package/lib/bin/supermassive.js +83 -0
  30. package/lib/bin/supermassive.mjs +62 -0
  31. package/lib/collectFields.d.ts +17 -0
  32. package/lib/collectFields.d.ts.map +1 -0
  33. package/lib/collectFields.js +83 -0
  34. package/lib/collectFields.mjs +61 -0
  35. package/lib/compiledQuery.d.ts +1 -0
  36. package/lib/compiledQuery.d.ts.map +1 -0
  37. package/lib/compiledQuery.js +0 -0
  38. package/lib/compiledQuery.mjs +0 -0
  39. package/lib/executeWithSchema.d.ts +4 -0
  40. package/lib/executeWithSchema.d.ts.map +1 -0
  41. package/lib/{index.test.js → executeWithSchema.js} +45 -46
  42. package/lib/executeWithSchema.mjs +64 -0
  43. package/lib/executeWithoutSchema.d.ts +99 -0
  44. package/lib/executeWithoutSchema.d.ts.map +1 -0
  45. package/lib/executeWithoutSchema.js +376 -0
  46. package/lib/executeWithoutSchema.mjs +363 -0
  47. package/lib/extractImplicitTypesRuntime.d.ts +4 -0
  48. package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
  49. package/lib/extractImplicitTypesRuntime.js +103 -0
  50. package/lib/extractImplicitTypesRuntime.mjs +91 -0
  51. package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
  52. package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
  53. package/lib/extractImplicitTypesToTypescript.js +169 -0
  54. package/lib/extractImplicitTypesToTypescript.mjs +149 -0
  55. package/lib/index.d.ts +8 -0
  56. package/lib/index.d.ts.map +1 -0
  57. package/lib/index.js +12 -29
  58. package/lib/index.mjs +13 -29
  59. package/lib/jsutils/Maybe.d.ts +3 -0
  60. package/lib/jsutils/Maybe.d.ts.map +1 -0
  61. package/lib/jsutils/Maybe.js +3 -0
  62. package/lib/jsutils/Maybe.mjs +0 -0
  63. package/lib/jsutils/ObjMap.d.ts +13 -0
  64. package/lib/jsutils/ObjMap.d.ts.map +1 -0
  65. package/lib/jsutils/ObjMap.js +3 -0
  66. package/lib/jsutils/ObjMap.mjs +0 -0
  67. package/lib/jsutils/Path.d.ts +15 -0
  68. package/lib/jsutils/Path.d.ts.map +1 -0
  69. package/lib/jsutils/Path.js +23 -0
  70. package/lib/jsutils/Path.mjs +17 -0
  71. package/lib/jsutils/PromiseOrValue.d.ts +2 -0
  72. package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
  73. package/lib/jsutils/PromiseOrValue.js +3 -0
  74. package/lib/jsutils/PromiseOrValue.mjs +0 -0
  75. package/lib/jsutils/devAssert.d.ts +2 -0
  76. package/lib/jsutils/devAssert.d.ts.map +1 -0
  77. package/lib/jsutils/devAssert.js +16 -0
  78. package/lib/jsutils/devAssert.mjs +10 -0
  79. package/lib/jsutils/didYouMean.d.ts +6 -0
  80. package/lib/jsutils/didYouMean.d.ts.map +1 -0
  81. package/lib/jsutils/didYouMean.js +30 -0
  82. package/lib/jsutils/didYouMean.mjs +24 -0
  83. package/lib/jsutils/identityFunc.d.ts +5 -0
  84. package/lib/jsutils/identityFunc.d.ts.map +1 -0
  85. package/lib/jsutils/identityFunc.js +13 -0
  86. package/lib/jsutils/identityFunc.mjs +7 -0
  87. package/lib/jsutils/inspect.d.ts +5 -0
  88. package/lib/jsutils/inspect.d.ts.map +1 -0
  89. package/lib/jsutils/inspect.js +89 -0
  90. package/lib/jsutils/inspect.mjs +83 -0
  91. package/lib/jsutils/instanceOf.d.ts +14 -0
  92. package/lib/jsutils/instanceOf.d.ts.map +1 -0
  93. package/lib/jsutils/instanceOf.js +55 -0
  94. package/lib/jsutils/instanceOf.mjs +33 -0
  95. package/lib/jsutils/invariant.d.ts +2 -0
  96. package/lib/jsutils/invariant.d.ts.map +1 -0
  97. package/lib/jsutils/invariant.js +16 -0
  98. package/lib/jsutils/invariant.mjs +10 -0
  99. package/lib/jsutils/isAsyncIterable.d.ts +6 -0
  100. package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
  101. package/lib/jsutils/isAsyncIterable.js +13 -0
  102. package/lib/jsutils/isAsyncIterable.mjs +7 -0
  103. package/lib/jsutils/isIterableObject.d.ts +18 -0
  104. package/lib/jsutils/isIterableObject.d.ts.map +1 -0
  105. package/lib/jsutils/isIterableObject.js +13 -0
  106. package/lib/jsutils/isIterableObject.mjs +7 -0
  107. package/lib/jsutils/isObjectLike.d.ts +8 -0
  108. package/lib/jsutils/isObjectLike.d.ts.map +1 -0
  109. package/lib/jsutils/isObjectLike.js +13 -0
  110. package/lib/jsutils/isObjectLike.mjs +7 -0
  111. package/lib/jsutils/isPromise.d.ts +6 -0
  112. package/lib/jsutils/isPromise.d.ts.map +1 -0
  113. package/lib/jsutils/isPromise.js +13 -0
  114. package/lib/jsutils/isPromise.mjs +7 -0
  115. package/lib/jsutils/keyMap.d.ts +26 -0
  116. package/lib/jsutils/keyMap.d.ts.map +1 -0
  117. package/lib/jsutils/keyMap.js +17 -0
  118. package/lib/jsutils/keyMap.mjs +11 -0
  119. package/lib/jsutils/keyValMap.d.ts +20 -0
  120. package/lib/jsutils/keyValMap.d.ts.map +1 -0
  121. package/lib/jsutils/keyValMap.js +17 -0
  122. package/lib/jsutils/keyValMap.mjs +11 -0
  123. package/lib/jsutils/mapValue.d.ts +7 -0
  124. package/lib/jsutils/mapValue.d.ts.map +1 -0
  125. package/lib/jsutils/mapValue.js +17 -0
  126. package/lib/jsutils/mapValue.mjs +11 -0
  127. package/lib/jsutils/memoize3.d.ts +5 -0
  128. package/lib/jsutils/memoize3.d.ts.map +1 -0
  129. package/lib/jsutils/memoize3.js +34 -0
  130. package/lib/jsutils/memoize3.mjs +28 -0
  131. package/lib/jsutils/naturalCompare.d.ts +9 -0
  132. package/lib/jsutils/naturalCompare.d.ts.map +1 -0
  133. package/lib/jsutils/naturalCompare.js +53 -0
  134. package/lib/jsutils/naturalCompare.mjs +47 -0
  135. package/lib/jsutils/printPathArray.d.ts +5 -0
  136. package/lib/jsutils/printPathArray.d.ts.map +1 -0
  137. package/lib/jsutils/printPathArray.js +13 -0
  138. package/lib/jsutils/printPathArray.mjs +7 -0
  139. package/lib/jsutils/promiseForObject.d.ts +10 -0
  140. package/lib/jsutils/promiseForObject.d.ts.map +1 -0
  141. package/lib/jsutils/promiseForObject.js +19 -0
  142. package/lib/jsutils/promiseForObject.mjs +13 -0
  143. package/lib/jsutils/promiseReduce.d.ts +10 -0
  144. package/lib/jsutils/promiseReduce.d.ts.map +1 -0
  145. package/lib/jsutils/promiseReduce.js +34 -0
  146. package/lib/jsutils/promiseReduce.mjs +12 -0
  147. package/lib/jsutils/suggestionList.d.ts +6 -0
  148. package/lib/jsutils/suggestionList.d.ts.map +1 -0
  149. package/lib/jsutils/suggestionList.js +109 -0
  150. package/lib/jsutils/suggestionList.mjs +87 -0
  151. package/lib/jsutils/toObjMap.d.ts +4 -0
  152. package/lib/jsutils/toObjMap.d.ts.map +1 -0
  153. package/lib/jsutils/toObjMap.js +20 -0
  154. package/lib/jsutils/toObjMap.mjs +14 -0
  155. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
  156. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
  157. package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
  158. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +17 -0
  159. package/lib/transforms/transformerTestUtils.d.ts +79 -0
  160. package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
  161. package/lib/transforms/transformerTestUtils.js +175 -0
  162. package/lib/transforms/transformerTestUtils.mjs +160 -0
  163. package/lib/types.d.ts +74 -0
  164. package/lib/types.d.ts.map +1 -0
  165. package/lib/types.js +3 -0
  166. package/lib/types.mjs +0 -0
  167. package/lib/utilities/typeNameFromAST.d.ts +3 -0
  168. package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
  169. package/lib/utilities/typeNameFromAST.js +34 -0
  170. package/lib/utilities/typeNameFromAST.mjs +12 -0
  171. package/lib/values.d.ts +64 -0
  172. package/lib/values.d.ts.map +1 -0
  173. package/lib/values.js +145 -0
  174. package/lib/values.mjs +138 -0
  175. package/package.json +21 -6
  176. package/.eslintcache +0 -1
  177. package/CHANGELOG.json +0 -35
  178. package/benchmarks/fixtures/query1.graphql +0 -20
  179. package/benchmarks/index.ts +0 -68
  180. package/benchmarks/nice-benchmark.ts +0 -32
  181. package/benchmarks/swapi-schema/index.ts +0 -13
  182. package/benchmarks/swapi-schema/models.ts +0 -4
  183. package/benchmarks/swapi-schema/resolvers.ts +0 -331
  184. package/benchmarks/swapi-schema/schema.graphql +0 -164
  185. package/benchmarks/swapi-schema/starwars.json +0 -5991
  186. package/lib/index.test.mjs +0 -63
  187. package/lib/src/ast/TypedAST.d.ts.map +0 -1
  188. package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
  189. package/lib/src/index.d.ts +0 -16
  190. package/lib/src/index.d.ts.map +0 -1
  191. package/lib/src/index.test.d.ts +0 -2
  192. package/lib/src/index.test.d.ts.map +0 -1
@@ -0,0 +1,363 @@
1
+ // src/executeWithoutSchema.ts
2
+ import {
3
+ GraphQLEnumType,
4
+ GraphQLError,
5
+ GraphQLInputObjectType,
6
+ GraphQLScalarType,
7
+ isLeafType,
8
+ Kind,
9
+ locatedError
10
+ } from "graphql";
11
+ import {collectFields} from "./collectFields.mjs";
12
+ import {devAssert} from "./jsutils/devAssert.mjs";
13
+ import {inspect} from "./jsutils/inspect.mjs";
14
+ import {invariant} from "./jsutils/invariant.mjs";
15
+ import {isIterableObject} from "./jsutils/isIterableObject.mjs";
16
+ import {isObjectLike} from "./jsutils/isObjectLike.mjs";
17
+ import {isPromise} from "./jsutils/isPromise.mjs";
18
+ import {addPath, pathToArray} from "./jsutils/Path.mjs";
19
+ import {promiseForObject} from "./jsutils/promiseForObject.mjs";
20
+ import {promiseReduce} from "./jsutils/promiseReduce.mjs";
21
+ import {typeNameFromAST} from "./utilities/typeNameFromAST.mjs";
22
+ import {
23
+ getArgumentValues,
24
+ getVariableValues,
25
+ specifiedScalars
26
+ } from "./values.mjs";
27
+ function executeWithoutSchema(args) {
28
+ const {
29
+ resolvers,
30
+ document,
31
+ rootValue,
32
+ contextValue,
33
+ variableValues,
34
+ operationName,
35
+ fieldResolver,
36
+ typeResolver
37
+ } = args;
38
+ assertValidExecutionArguments(document, variableValues);
39
+ const exeContext = buildExecutionContext(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver);
40
+ if (!("resolvers" in exeContext)) {
41
+ return {errors: exeContext};
42
+ } else {
43
+ const data = executeOperation(exeContext, exeContext.operation, rootValue);
44
+ return buildResponse(exeContext, data);
45
+ }
46
+ }
47
+ function buildResponse(exeContext, data) {
48
+ if (isPromise(data)) {
49
+ return data.then((resolved) => buildResponse(exeContext, resolved));
50
+ }
51
+ return exeContext.errors.length === 0 ? {data} : {errors: exeContext.errors, data};
52
+ }
53
+ function assertValidExecutionArguments(document, rawVariableValues) {
54
+ devAssert(document, "Must provide document.");
55
+ devAssert(rawVariableValues == null || isObjectLike(rawVariableValues), "Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided.");
56
+ }
57
+ function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
58
+ var _a, _b;
59
+ let operation;
60
+ const fragments = Object.create(null);
61
+ for (const definition of document.definitions) {
62
+ switch (definition.kind) {
63
+ case Kind.OPERATION_DEFINITION:
64
+ if (operationName == null) {
65
+ if (operation !== void 0) {
66
+ return [
67
+ new GraphQLError("Must provide operation name if query contains multiple operations.")
68
+ ];
69
+ }
70
+ operation = definition;
71
+ } else if (((_a = definition.name) == null ? void 0 : _a.value) === operationName) {
72
+ operation = definition;
73
+ }
74
+ break;
75
+ case Kind.FRAGMENT_DEFINITION:
76
+ fragments[definition.name.value] = definition;
77
+ break;
78
+ }
79
+ }
80
+ if (!operation) {
81
+ if (operationName != null) {
82
+ return [new GraphQLError(`Unknown operation named "${operationName}".`)];
83
+ }
84
+ return [new GraphQLError("Must provide an operation.")];
85
+ }
86
+ const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
87
+ const coercedVariableValues = getVariableValues(resolvers, variableDefinitions, rawVariableValues != null ? rawVariableValues : {}, {maxErrors: 50});
88
+ if (coercedVariableValues.errors) {
89
+ return coercedVariableValues.errors;
90
+ }
91
+ return {
92
+ resolvers,
93
+ fragments,
94
+ rootValue,
95
+ contextValue,
96
+ operation,
97
+ variableValues: coercedVariableValues.coerced,
98
+ fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
99
+ typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
100
+ errors: []
101
+ };
102
+ }
103
+ function executeOperation(exeContext, operation, rootValue) {
104
+ const typeName = getOperationRootTypeName(operation);
105
+ const fields = collectFields(exeContext.resolvers, exeContext.fragments, exeContext.variableValues, typeName, operation.selectionSet, new Map(), new Set());
106
+ const path = void 0;
107
+ try {
108
+ const result = operation.operation === "mutation" ? executeFieldsSerially(exeContext, typeName, rootValue, path, fields) : executeFields(exeContext, typeName, rootValue, path, fields);
109
+ if (isPromise(result)) {
110
+ return result.then(void 0, (error) => {
111
+ exeContext.errors.push(error);
112
+ return Promise.resolve(null);
113
+ });
114
+ }
115
+ return result;
116
+ } catch (error) {
117
+ exeContext.errors.push(error);
118
+ return null;
119
+ }
120
+ }
121
+ function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, fields) {
122
+ return promiseReduce(fields.entries(), (results, [responseName, fieldNodes]) => {
123
+ const fieldPath = addPath(path, responseName, parentTypeName);
124
+ const result = executeField(exeContext, parentTypeName, sourceValue, fieldNodes, fieldPath);
125
+ if (result === void 0) {
126
+ return results;
127
+ }
128
+ if (isPromise(result)) {
129
+ return result.then((resolvedResult) => {
130
+ results[responseName] = resolvedResult;
131
+ return results;
132
+ });
133
+ }
134
+ results[responseName] = result;
135
+ return results;
136
+ }, Object.create(null));
137
+ }
138
+ function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
139
+ const results = Object.create(null);
140
+ let containsPromise = false;
141
+ for (const [responseName, fieldNodes] of fields.entries()) {
142
+ const fieldPath = addPath(path, responseName, parentTypeName);
143
+ const result = executeField(exeContext, parentTypeName, sourceValue, fieldNodes, fieldPath);
144
+ if (result !== void 0) {
145
+ results[responseName] = result;
146
+ if (isPromise(result)) {
147
+ containsPromise = true;
148
+ }
149
+ }
150
+ }
151
+ if (!containsPromise) {
152
+ return results;
153
+ }
154
+ return promiseForObject(results);
155
+ }
156
+ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
157
+ const fieldName = fieldNodes[0].name.value;
158
+ let resolveFn;
159
+ let returnTypeName;
160
+ let returnTypeNode;
161
+ if (fieldName === "__typename" && !resolveFn) {
162
+ resolveFn = () => parentTypeName;
163
+ returnTypeName = "String";
164
+ returnTypeNode = {
165
+ kind: Kind.NAMED_TYPE,
166
+ name: {
167
+ kind: Kind.NAME,
168
+ value: "String"
169
+ }
170
+ };
171
+ } else {
172
+ returnTypeNode = fieldNodes[0].__type;
173
+ returnTypeName = typeNameFromAST(returnTypeNode);
174
+ const typeResolvers = exeContext.resolvers[parentTypeName];
175
+ resolveFn = typeResolvers == null ? void 0 : typeResolvers[fieldName];
176
+ }
177
+ if (!resolveFn) {
178
+ resolveFn = exeContext.fieldResolver;
179
+ }
180
+ const info = buildResolveInfo(exeContext, fieldName, fieldNodes, parentTypeName, returnTypeName, returnTypeNode, path);
181
+ try {
182
+ const args = getArgumentValues(exeContext.resolvers, fieldNodes[0], exeContext.variableValues);
183
+ const contextValue = exeContext.contextValue;
184
+ const result = resolveFn(source, args, contextValue, info);
185
+ let completed;
186
+ if (isPromise(result)) {
187
+ completed = result.then((resolved) => completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resolved));
188
+ } else {
189
+ completed = completeValue(exeContext, returnTypeNode, fieldNodes, info, path, result);
190
+ }
191
+ if (isPromise(completed)) {
192
+ return completed.then(void 0, (rawError) => {
193
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
194
+ return handleFieldError(error, returnTypeNode, exeContext);
195
+ });
196
+ }
197
+ return completed;
198
+ } catch (rawError) {
199
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
200
+ return handleFieldError(error, returnTypeNode, exeContext);
201
+ }
202
+ }
203
+ function buildResolveInfo(exeContext, fieldName, fieldNodes, parentTypeName, returnTypeName, returnTypeNode, path) {
204
+ return {
205
+ fieldName,
206
+ fieldNodes,
207
+ returnTypeName,
208
+ parentTypeName,
209
+ returnTypeNode,
210
+ path,
211
+ fragments: exeContext.fragments,
212
+ rootValue: exeContext.rootValue,
213
+ operation: exeContext.operation,
214
+ variableValues: exeContext.variableValues
215
+ };
216
+ }
217
+ function handleFieldError(error, returnTypeNode, exeContext) {
218
+ if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
219
+ throw error;
220
+ }
221
+ exeContext.errors.push(error);
222
+ return null;
223
+ }
224
+ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
225
+ if (result instanceof Error) {
226
+ throw result;
227
+ }
228
+ if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
229
+ const completed = completeValue(exeContext, returnTypeNode.type, fieldNodes, info, path, result);
230
+ if (completed === null) {
231
+ throw new Error(`Cannot return null for non-nullable field ${info.parentTypeName}.${info.fieldName}.`);
232
+ }
233
+ return completed;
234
+ }
235
+ if (result == null) {
236
+ return null;
237
+ }
238
+ if (returnTypeNode.kind === Kind.LIST_TYPE) {
239
+ return completeListValue(exeContext, returnTypeNode.type, fieldNodes, info, path, result);
240
+ }
241
+ const returnTypeName = returnTypeNode.name.value;
242
+ let returnType = exeContext.resolvers[returnTypeName];
243
+ if (!returnType) {
244
+ returnType = specifiedScalars[returnTypeName];
245
+ }
246
+ if (isLeafType(returnType)) {
247
+ return completeLeafValue(returnType, result);
248
+ }
249
+ if (returnType instanceof GraphQLInputObjectType) {
250
+ }
251
+ if ("__resolveType" in returnType) {
252
+ return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
253
+ }
254
+ if (typeof returnType === "object") {
255
+ return completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result);
256
+ }
257
+ invariant(false, "Cannot complete value of unexpected output type: " + inspect(returnType));
258
+ }
259
+ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
260
+ if (!isIterableObject(result)) {
261
+ throw new GraphQLError(`Expected Iterable, but did not find one for field "${info.parentTypeName}.${info.fieldName}".`);
262
+ }
263
+ let containsPromise = false;
264
+ const completedResults = Array.from(result, (item, index) => {
265
+ const itemPath = addPath(path, index, void 0);
266
+ try {
267
+ let completedItem;
268
+ if (isPromise(item)) {
269
+ completedItem = item.then((resolved) => completeValue(exeContext, returnTypeNode, fieldNodes, info, itemPath, resolved));
270
+ } else {
271
+ completedItem = completeValue(exeContext, returnTypeNode, fieldNodes, info, itemPath, item);
272
+ }
273
+ if (isPromise(completedItem)) {
274
+ containsPromise = true;
275
+ return completedItem.then(void 0, (rawError) => {
276
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
277
+ return handleFieldError(error, returnTypeNode, exeContext);
278
+ });
279
+ }
280
+ return completedItem;
281
+ } catch (rawError) {
282
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
283
+ return handleFieldError(error, returnTypeNode, exeContext);
284
+ }
285
+ });
286
+ return containsPromise ? Promise.all(completedResults) : completedResults;
287
+ }
288
+ function completeLeafValue(returnType, result) {
289
+ const serializedResult = returnType.serialize(result);
290
+ if (serializedResult === void 0) {
291
+ throw new Error(`Expected a value of type "${inspect(returnType)}" but received: ${inspect(result)}`);
292
+ }
293
+ return serializedResult;
294
+ }
295
+ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
296
+ var _a;
297
+ const resolveTypeFn = (_a = returnType.__resolveType) != null ? _a : exeContext.typeResolver;
298
+ const contextValue = exeContext.contextValue;
299
+ const runtimeTypeName = resolveTypeFn(result, contextValue, info);
300
+ if (isPromise(runtimeTypeName)) {
301
+ return runtimeTypeName.then((resolvedRuntimeTypeName) => completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeTypeName, exeContext), fieldNodes, info, path, result));
302
+ }
303
+ return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeTypeName, exeContext), fieldNodes, info, path, result);
304
+ }
305
+ function ensureValidRuntimeType(runtimeTypeName, exeContext) {
306
+ if (typeof runtimeTypeName === "string") {
307
+ const runtimeType = exeContext.resolvers[runtimeTypeName];
308
+ if (!runtimeType) {
309
+ throw new Error("TODO - no such type");
310
+ } else if (runtimeType instanceof GraphQLScalarType || runtimeType instanceof GraphQLEnumType || runtimeType instanceof GraphQLInputObjectType || runtimeType.__resolveType) {
311
+ throw new Error("TODO - invalid runtime type");
312
+ } else {
313
+ return runtimeTypeName;
314
+ }
315
+ }
316
+ throw new Error("TODO - Could not determine runtime type for abstract type");
317
+ }
318
+ function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
319
+ const subFieldNodes = collectSubfields(exeContext, returnTypeName, fieldNodes);
320
+ return executeFields(exeContext, returnTypeName, result, path, subFieldNodes);
321
+ }
322
+ function collectSubfields(exeContext, returnTypeName, fieldNodes) {
323
+ let subFieldNodes = new Map();
324
+ const visitedFragmentNames = new Set();
325
+ for (const node of fieldNodes) {
326
+ if (node.selectionSet) {
327
+ subFieldNodes = collectFields(exeContext.resolvers, exeContext.fragments, exeContext.variableValues, returnTypeName, node.selectionSet, subFieldNodes, visitedFragmentNames);
328
+ }
329
+ }
330
+ return subFieldNodes;
331
+ }
332
+ var defaultTypeResolver = function(value) {
333
+ if (isObjectLike(value) && typeof value.__typename === "string") {
334
+ return value.__typename;
335
+ }
336
+ };
337
+ var defaultFieldResolver = function(source, args, contextValue, info) {
338
+ if (isObjectLike(source) || typeof source === "function") {
339
+ const property = source[info.fieldName];
340
+ if (typeof property === "function") {
341
+ return source[info.fieldName](args, contextValue, info);
342
+ }
343
+ return property;
344
+ }
345
+ };
346
+ function getOperationRootTypeName(operation) {
347
+ switch (operation.operation) {
348
+ case "query":
349
+ return "Query";
350
+ case "mutation":
351
+ return "Mutation";
352
+ case "subscription":
353
+ return "Subscription";
354
+ }
355
+ }
356
+ export {
357
+ assertValidExecutionArguments,
358
+ buildExecutionContext,
359
+ buildResolveInfo,
360
+ defaultFieldResolver,
361
+ defaultTypeResolver,
362
+ executeWithoutSchema
363
+ };
@@ -0,0 +1,4 @@
1
+ import { DocumentNode, GraphQLInputType } from "graphql";
2
+ import { Resolvers } from "./types";
3
+ export declare function extractImplicitTypes<TSource = any, TContext = any>(document: DocumentNode, getTypeByName: (name: string) => GraphQLInputType): Resolvers<TSource, TContext>;
4
+ //# sourceMappingURL=extractImplicitTypesRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractImplicitTypesRuntime.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAcZ,gBAAgB,EAKjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,GAAG,EAAE,QAAQ,GAAG,GAAG,EAChE,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAChD,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAuB9B"}
@@ -0,0 +1,103 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __reExport = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+ __markAsModule(exports);
24
+ __export(exports, {
25
+ extractImplicitTypes: () => extractImplicitTypes
26
+ });
27
+ var import_graphql = __toModule(require("graphql"));
28
+ function extractImplicitTypes(document, getTypeByName) {
29
+ var _a;
30
+ const result = Object.create(null);
31
+ for (let astNode of document.definitions) {
32
+ if (astNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION) {
33
+ const name = astNode.name.value;
34
+ result[name] = new import_graphql.GraphQLScalarType({
35
+ name,
36
+ description: (_a = astNode.description) == null ? void 0 : _a.value
37
+ });
38
+ } else if (astNode.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
39
+ result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
40
+ } else if (astNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION) {
41
+ result[astNode.name.value] = makeEnum(astNode);
42
+ } else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION || astNode.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION) {
43
+ result[astNode.name.value] = {__resolveType: void 0};
44
+ } else if (astNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) {
45
+ result[astNode.name.value] = {};
46
+ }
47
+ }
48
+ return result;
49
+ }
50
+ function makeEnum(astNode) {
51
+ var _a, _b;
52
+ const enumValueMap = Object.create(null);
53
+ for (const value of astNode.values || []) {
54
+ enumValueMap[value.name.value] = {
55
+ description: (_a = value.description) == null ? void 0 : _a.value,
56
+ deprecationReason: getDeprecationReason(value),
57
+ astNode: value
58
+ };
59
+ }
60
+ return new import_graphql.GraphQLEnumType({
61
+ name: astNode.name.value,
62
+ description: (_b = astNode.description) == null ? void 0 : _b.value,
63
+ values: enumValueMap
64
+ });
65
+ }
66
+ function makeInputObject(astNode, getTypeByName) {
67
+ var _a;
68
+ const name = astNode.name.value;
69
+ return new import_graphql.GraphQLInputObjectType({
70
+ name,
71
+ description: (_a = astNode.description) == null ? void 0 : _a.value,
72
+ fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
73
+ astNode
74
+ });
75
+ }
76
+ function buildInputFieldMap(fieldNodes, getTypeByName) {
77
+ var _a;
78
+ const inputFieldMap = Object.create(null);
79
+ for (const field of fieldNodes) {
80
+ const type = getWrappedType(field.type, getTypeByName);
81
+ inputFieldMap[field.name.value] = {
82
+ type,
83
+ description: (_a = field.description) == null ? void 0 : _a.value,
84
+ defaultValue: (0, import_graphql.valueFromAST)(field.defaultValue, type),
85
+ deprecationReason: getDeprecationReason(field),
86
+ astNode: field
87
+ };
88
+ }
89
+ return inputFieldMap;
90
+ }
91
+ function getWrappedType(type, getTypeByName) {
92
+ if (type.kind === import_graphql.Kind.LIST_TYPE) {
93
+ return new import_graphql.GraphQLList(getWrappedType(type.type, getTypeByName));
94
+ } else if (type.kind === import_graphql.Kind.NON_NULL_TYPE) {
95
+ return new import_graphql.GraphQLNonNull(getWrappedType(type.type, getTypeByName));
96
+ } else {
97
+ return getTypeByName(type.name.value);
98
+ }
99
+ }
100
+ function getDeprecationReason(node) {
101
+ const deprecated = (0, import_graphql.getDirectiveValues)(import_graphql.GraphQLDeprecatedDirective, node);
102
+ return deprecated == null ? void 0 : deprecated.reason;
103
+ }
@@ -0,0 +1,91 @@
1
+ // src/extractImplicitTypesRuntime.ts
2
+ import {
3
+ getDirectiveValues,
4
+ GraphQLDeprecatedDirective,
5
+ GraphQLEnumType,
6
+ GraphQLScalarType,
7
+ Kind,
8
+ GraphQLInputObjectType,
9
+ valueFromAST,
10
+ GraphQLNonNull,
11
+ GraphQLList
12
+ } from "graphql";
13
+ function extractImplicitTypes(document, getTypeByName) {
14
+ var _a;
15
+ const result = Object.create(null);
16
+ for (let astNode of document.definitions) {
17
+ if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
18
+ const name = astNode.name.value;
19
+ result[name] = new GraphQLScalarType({
20
+ name,
21
+ description: (_a = astNode.description) == null ? void 0 : _a.value
22
+ });
23
+ } else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
24
+ result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
25
+ } else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
26
+ result[astNode.name.value] = makeEnum(astNode);
27
+ } else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
28
+ result[astNode.name.value] = {__resolveType: void 0};
29
+ } else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
30
+ result[astNode.name.value] = {};
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ function makeEnum(astNode) {
36
+ var _a, _b;
37
+ const enumValueMap = Object.create(null);
38
+ for (const value of astNode.values || []) {
39
+ enumValueMap[value.name.value] = {
40
+ description: (_a = value.description) == null ? void 0 : _a.value,
41
+ deprecationReason: getDeprecationReason(value),
42
+ astNode: value
43
+ };
44
+ }
45
+ return new GraphQLEnumType({
46
+ name: astNode.name.value,
47
+ description: (_b = astNode.description) == null ? void 0 : _b.value,
48
+ values: enumValueMap
49
+ });
50
+ }
51
+ function makeInputObject(astNode, getTypeByName) {
52
+ var _a;
53
+ const name = astNode.name.value;
54
+ return new GraphQLInputObjectType({
55
+ name,
56
+ description: (_a = astNode.description) == null ? void 0 : _a.value,
57
+ fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
58
+ astNode
59
+ });
60
+ }
61
+ function buildInputFieldMap(fieldNodes, getTypeByName) {
62
+ var _a;
63
+ const inputFieldMap = Object.create(null);
64
+ for (const field of fieldNodes) {
65
+ const type = getWrappedType(field.type, getTypeByName);
66
+ inputFieldMap[field.name.value] = {
67
+ type,
68
+ description: (_a = field.description) == null ? void 0 : _a.value,
69
+ defaultValue: valueFromAST(field.defaultValue, type),
70
+ deprecationReason: getDeprecationReason(field),
71
+ astNode: field
72
+ };
73
+ }
74
+ return inputFieldMap;
75
+ }
76
+ function getWrappedType(type, getTypeByName) {
77
+ if (type.kind === Kind.LIST_TYPE) {
78
+ return new GraphQLList(getWrappedType(type.type, getTypeByName));
79
+ } else if (type.kind === Kind.NON_NULL_TYPE) {
80
+ return new GraphQLNonNull(getWrappedType(type.type, getTypeByName));
81
+ } else {
82
+ return getTypeByName(type.name.value);
83
+ }
84
+ }
85
+ function getDeprecationReason(node) {
86
+ const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
87
+ return deprecated == null ? void 0 : deprecated.reason;
88
+ }
89
+ export {
90
+ extractImplicitTypes
91
+ };
@@ -0,0 +1,4 @@
1
+ import ts from "typescript";
2
+ import { DocumentNode } from "graphql";
3
+ export declare function extractImplicitTypesToTypescript(document: DocumentNode): ts.SourceFile;
4
+ //# sourceMappingURL=extractImplicitTypesToTypescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractImplicitTypesToTypescript.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesToTypescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,YAAY,EAYb,MAAM,SAAS,CAAC;AAUjB,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,YAAY,GACrB,EAAE,CAAC,UAAU,CAmFf"}