@graphitation/supermassive 0.1.3 → 0.2.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 (208) hide show
  1. package/.eslintcache +1 -1
  2. package/CHANGELOG.md +10 -2
  3. package/README.md +88 -0
  4. package/bin/supermassive.js +5 -0
  5. package/graphitation-supermassive-0.1.3-1.tgz +0 -0
  6. package/graphitation-supermassive-0.1.3-2.tgz +0 -0
  7. package/graphitation-supermassive-0.1.3.tgz +0 -0
  8. package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
  9. package/lib/ast/TypedAST.d.ts.map +1 -0
  10. package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
  11. package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
  12. package/lib/ast/addTypesToRequestDocument.js +8 -5
  13. package/lib/ast/addTypesToRequestDocument.mjs +9 -5
  14. package/lib/benchmarks/index.d.ts.map +1 -1
  15. package/lib/benchmarks/index.js +127 -0
  16. package/lib/benchmarks/index.mjs +109 -0
  17. package/lib/benchmarks/nice-benchmark.d.ts +1 -1
  18. package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
  19. package/lib/benchmarks/nice-benchmark.js +72 -0
  20. package/lib/benchmarks/nice-benchmark.mjs +49 -0
  21. package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
  22. package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
  23. package/lib/benchmarks/swapi-schema/index.js +39 -0
  24. package/lib/benchmarks/swapi-schema/index.mjs +16 -0
  25. package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
  26. package/lib/benchmarks/swapi-schema/models.js +29 -0
  27. package/lib/benchmarks/swapi-schema/models.mjs +6 -0
  28. package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
  29. package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
  30. package/lib/benchmarks/swapi-schema/resolvers.mjs +231 -0
  31. package/lib/bin/supermassive.d.ts +3 -0
  32. package/lib/bin/supermassive.d.ts.map +1 -0
  33. package/lib/bin/supermassive.js +83 -0
  34. package/lib/bin/supermassive.mjs +60 -0
  35. package/lib/bin/typeDefsToImplicitResolvers.d.ts +3 -0
  36. package/lib/bin/typeDefsToImplicitResolvers.d.ts.map +1 -0
  37. package/lib/bin/typeDefsToImplicitResolvers.js +82 -0
  38. package/lib/bin/typeDefsToImplicitResolvers.mjs +59 -0
  39. package/lib/collectFields.d.ts +17 -0
  40. package/lib/collectFields.d.ts.map +1 -0
  41. package/lib/collectFields.js +83 -0
  42. package/lib/collectFields.mjs +60 -0
  43. package/lib/compiledQuery.d.ts +1 -0
  44. package/lib/compiledQuery.d.ts.map +1 -0
  45. package/lib/compiledQuery.js +0 -0
  46. package/lib/compiledQuery.mjs +0 -0
  47. package/lib/execute.d.ts +128 -0
  48. package/lib/execute.d.ts.map +1 -0
  49. package/lib/execute.js +376 -0
  50. package/lib/execute.mjs +365 -0
  51. package/lib/executeWithSchema.d.ts +4 -0
  52. package/lib/executeWithSchema.d.ts.map +1 -0
  53. package/lib/{index.test.js → executeWithSchema.js} +44 -45
  54. package/lib/executeWithSchema.mjs +62 -0
  55. package/lib/executeWithoutSchema.d.ts +99 -0
  56. package/lib/executeWithoutSchema.d.ts.map +1 -0
  57. package/lib/executeWithoutSchema.js +376 -0
  58. package/lib/executeWithoutSchema.mjs +365 -0
  59. package/lib/extractImplicitTypes.d.ts +6 -0
  60. package/lib/extractImplicitTypes.d.ts.map +1 -0
  61. package/lib/extractImplicitTypes.js +246 -0
  62. package/lib/extractImplicitTypes.mjs +233 -0
  63. package/lib/extractImplicitTypesRuntime.d.ts +4 -0
  64. package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
  65. package/lib/extractImplicitTypesRuntime.js +103 -0
  66. package/lib/extractImplicitTypesRuntime.mjs +90 -0
  67. package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
  68. package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
  69. package/lib/extractImplicitTypesToTypescript.js +169 -0
  70. package/lib/extractImplicitTypesToTypescript.mjs +148 -0
  71. package/lib/index.d.ts +8 -0
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +14 -29
  74. package/lib/index.mjs +14 -29
  75. package/lib/jsutils/Maybe.d.ts +3 -0
  76. package/lib/jsutils/Maybe.d.ts.map +1 -0
  77. package/lib/jsutils/Maybe.js +3 -0
  78. package/lib/jsutils/Maybe.mjs +0 -0
  79. package/lib/jsutils/ObjMap.d.ts +13 -0
  80. package/lib/jsutils/ObjMap.d.ts.map +1 -0
  81. package/lib/jsutils/ObjMap.js +3 -0
  82. package/lib/jsutils/ObjMap.mjs +0 -0
  83. package/lib/jsutils/Path.d.ts +15 -0
  84. package/lib/jsutils/Path.d.ts.map +1 -0
  85. package/lib/jsutils/Path.js +23 -0
  86. package/lib/jsutils/Path.mjs +16 -0
  87. package/lib/jsutils/PromiseOrValue.d.ts +2 -0
  88. package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
  89. package/lib/jsutils/PromiseOrValue.js +3 -0
  90. package/lib/jsutils/PromiseOrValue.mjs +0 -0
  91. package/lib/jsutils/devAssert.d.ts +2 -0
  92. package/lib/jsutils/devAssert.d.ts.map +1 -0
  93. package/lib/jsutils/devAssert.js +16 -0
  94. package/lib/jsutils/devAssert.mjs +9 -0
  95. package/lib/jsutils/didYouMean.d.ts +6 -0
  96. package/lib/jsutils/didYouMean.d.ts.map +1 -0
  97. package/lib/jsutils/didYouMean.js +30 -0
  98. package/lib/jsutils/didYouMean.mjs +23 -0
  99. package/lib/jsutils/identityFunc.d.ts +5 -0
  100. package/lib/jsutils/identityFunc.d.ts.map +1 -0
  101. package/lib/jsutils/identityFunc.js +13 -0
  102. package/lib/jsutils/identityFunc.mjs +6 -0
  103. package/lib/jsutils/inspect.d.ts +5 -0
  104. package/lib/jsutils/inspect.d.ts.map +1 -0
  105. package/lib/jsutils/inspect.js +89 -0
  106. package/lib/jsutils/inspect.mjs +82 -0
  107. package/lib/jsutils/instanceOf.d.ts +14 -0
  108. package/lib/jsutils/instanceOf.d.ts.map +1 -0
  109. package/lib/jsutils/instanceOf.js +55 -0
  110. package/lib/jsutils/instanceOf.mjs +32 -0
  111. package/lib/jsutils/invariant.d.ts +2 -0
  112. package/lib/jsutils/invariant.d.ts.map +1 -0
  113. package/lib/jsutils/invariant.js +16 -0
  114. package/lib/jsutils/invariant.mjs +9 -0
  115. package/lib/jsutils/isAsyncIterable.d.ts +6 -0
  116. package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
  117. package/lib/jsutils/isAsyncIterable.js +13 -0
  118. package/lib/jsutils/isAsyncIterable.mjs +6 -0
  119. package/lib/jsutils/isIterableObject.d.ts +18 -0
  120. package/lib/jsutils/isIterableObject.d.ts.map +1 -0
  121. package/lib/jsutils/isIterableObject.js +13 -0
  122. package/lib/jsutils/isIterableObject.mjs +6 -0
  123. package/lib/jsutils/isObjectLike.d.ts +8 -0
  124. package/lib/jsutils/isObjectLike.d.ts.map +1 -0
  125. package/lib/jsutils/isObjectLike.js +13 -0
  126. package/lib/jsutils/isObjectLike.mjs +6 -0
  127. package/lib/jsutils/isPromise.d.ts +6 -0
  128. package/lib/jsutils/isPromise.d.ts.map +1 -0
  129. package/lib/jsutils/isPromise.js +13 -0
  130. package/lib/jsutils/isPromise.mjs +6 -0
  131. package/lib/jsutils/keyMap.d.ts +26 -0
  132. package/lib/jsutils/keyMap.d.ts.map +1 -0
  133. package/lib/jsutils/keyMap.js +17 -0
  134. package/lib/jsutils/keyMap.mjs +10 -0
  135. package/lib/jsutils/keyValMap.d.ts +20 -0
  136. package/lib/jsutils/keyValMap.d.ts.map +1 -0
  137. package/lib/jsutils/keyValMap.js +17 -0
  138. package/lib/jsutils/keyValMap.mjs +10 -0
  139. package/lib/jsutils/mapValue.d.ts +7 -0
  140. package/lib/jsutils/mapValue.d.ts.map +1 -0
  141. package/lib/jsutils/mapValue.js +17 -0
  142. package/lib/jsutils/mapValue.mjs +10 -0
  143. package/lib/jsutils/memoize3.d.ts +5 -0
  144. package/lib/jsutils/memoize3.d.ts.map +1 -0
  145. package/lib/jsutils/memoize3.js +34 -0
  146. package/lib/jsutils/memoize3.mjs +27 -0
  147. package/lib/jsutils/naturalCompare.d.ts +9 -0
  148. package/lib/jsutils/naturalCompare.d.ts.map +1 -0
  149. package/lib/jsutils/naturalCompare.js +53 -0
  150. package/lib/jsutils/naturalCompare.mjs +46 -0
  151. package/lib/jsutils/printPathArray.d.ts +5 -0
  152. package/lib/jsutils/printPathArray.d.ts.map +1 -0
  153. package/lib/jsutils/printPathArray.js +13 -0
  154. package/lib/jsutils/printPathArray.mjs +6 -0
  155. package/lib/jsutils/promiseForObject.d.ts +10 -0
  156. package/lib/jsutils/promiseForObject.d.ts.map +1 -0
  157. package/lib/jsutils/promiseForObject.js +19 -0
  158. package/lib/jsutils/promiseForObject.mjs +12 -0
  159. package/lib/jsutils/promiseReduce.d.ts +10 -0
  160. package/lib/jsutils/promiseReduce.d.ts.map +1 -0
  161. package/lib/jsutils/promiseReduce.js +34 -0
  162. package/lib/jsutils/promiseReduce.mjs +11 -0
  163. package/lib/jsutils/suggestionList.d.ts +6 -0
  164. package/lib/jsutils/suggestionList.d.ts.map +1 -0
  165. package/lib/jsutils/suggestionList.js +109 -0
  166. package/lib/jsutils/suggestionList.mjs +86 -0
  167. package/lib/jsutils/toObjMap.d.ts +4 -0
  168. package/lib/jsutils/toObjMap.d.ts.map +1 -0
  169. package/lib/jsutils/toObjMap.js +20 -0
  170. package/lib/jsutils/toObjMap.mjs +13 -0
  171. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
  172. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
  173. package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
  174. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +16 -0
  175. package/lib/transforms/transformerTestUtils.d.ts +79 -0
  176. package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
  177. package/lib/transforms/transformerTestUtils.js +175 -0
  178. package/lib/transforms/transformerTestUtils.mjs +154 -0
  179. package/lib/types.d.ts +74 -0
  180. package/lib/types.d.ts.map +1 -0
  181. package/lib/types.js +3 -0
  182. package/lib/types.mjs +0 -0
  183. package/lib/utilities/typeNameFromAST.d.ts +3 -0
  184. package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
  185. package/lib/utilities/typeNameFromAST.js +34 -0
  186. package/lib/utilities/typeNameFromAST.mjs +11 -0
  187. package/lib/values.d.ts +64 -0
  188. package/lib/values.d.ts.map +1 -0
  189. package/lib/values.js +145 -0
  190. package/lib/values.mjs +137 -0
  191. package/package.json +9 -4
  192. package/CHANGELOG.json +0 -65
  193. package/benchmarks/fixtures/query1.graphql +0 -20
  194. package/benchmarks/index.ts +0 -68
  195. package/benchmarks/nice-benchmark.ts +0 -32
  196. package/benchmarks/swapi-schema/index.ts +0 -13
  197. package/benchmarks/swapi-schema/models.ts +0 -4
  198. package/benchmarks/swapi-schema/resolvers.ts +0 -331
  199. package/benchmarks/swapi-schema/schema.graphql +0 -164
  200. package/benchmarks/swapi-schema/starwars.json +0 -5991
  201. package/lib/index.test.mjs +0 -63
  202. package/lib/src/ast/TypedAST.d.ts.map +0 -1
  203. package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
  204. package/lib/src/index.d.ts +0 -16
  205. package/lib/src/index.d.ts.map +0 -1
  206. package/lib/src/index.test.d.ts +0 -2
  207. package/lib/src/index.test.d.ts.map +0 -1
  208. package/starwars.json +0 -1
@@ -0,0 +1,365 @@
1
+ import {
2
+ GraphQLEnumType,
3
+ GraphQLError,
4
+ GraphQLInputObjectType,
5
+ GraphQLScalarType,
6
+ isLeafType,
7
+ Kind,
8
+ locatedError
9
+ } from "graphql";
10
+ import {collectFields} from "./collectFields";
11
+ import {devAssert} from "./jsutils/devAssert";
12
+ import {inspect} from "./jsutils/inspect";
13
+ import {invariant} from "./jsutils/invariant";
14
+ import {isIterableObject} from "./jsutils/isIterableObject";
15
+ import {isObjectLike} from "./jsutils/isObjectLike";
16
+ import {isPromise} from "./jsutils/isPromise";
17
+ import {addPath, pathToArray} from "./jsutils/Path";
18
+ import {promiseForObject} from "./jsutils/promiseForObject";
19
+ import {promiseReduce} from "./jsutils/promiseReduce";
20
+ import {typeNameFromAST} from "./utilities/typeNameFromAST";
21
+ import {
22
+ getArgumentValues,
23
+ getVariableValues,
24
+ specifiedScalars
25
+ } from "./values";
26
+ function execute(args) {
27
+ const {
28
+ resolvers,
29
+ document,
30
+ rootValue,
31
+ contextValue,
32
+ variableValues,
33
+ operationName,
34
+ fieldResolver,
35
+ typeResolver
36
+ } = args;
37
+ assertValidExecutionArguments(document, variableValues);
38
+ const exeContext = buildExecutionContext(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver);
39
+ if (!("resolvers" in exeContext)) {
40
+ return {errors: exeContext};
41
+ } else {
42
+ const data = executeOperation(exeContext, exeContext.operation, rootValue);
43
+ return buildResponse(exeContext, data);
44
+ }
45
+ }
46
+ function buildResponse(exeContext, data) {
47
+ if (isPromise(data)) {
48
+ return data.then((resolved) => buildResponse(exeContext, resolved));
49
+ }
50
+ return exeContext.errors.length === 0 ? {data} : {errors: exeContext.errors, data};
51
+ }
52
+ function assertValidExecutionArguments(document, rawVariableValues) {
53
+ devAssert(document, "Must provide document.");
54
+ 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.");
55
+ }
56
+ function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
57
+ var _a, _b;
58
+ let operation;
59
+ const fragments = Object.create(null);
60
+ for (const definition of document.definitions) {
61
+ switch (definition.kind) {
62
+ case Kind.OPERATION_DEFINITION:
63
+ if (operationName == null) {
64
+ if (operation !== void 0) {
65
+ return [
66
+ new GraphQLError("Must provide operation name if query contains multiple operations.")
67
+ ];
68
+ }
69
+ operation = definition;
70
+ } else if (((_a = definition.name) == null ? void 0 : _a.value) === operationName) {
71
+ operation = definition;
72
+ }
73
+ break;
74
+ case Kind.FRAGMENT_DEFINITION:
75
+ fragments[definition.name.value] = definition;
76
+ break;
77
+ }
78
+ }
79
+ if (!operation) {
80
+ if (operationName != null) {
81
+ return [new GraphQLError(`Unknown operation named "${operationName}".`)];
82
+ }
83
+ return [new GraphQLError("Must provide an operation.")];
84
+ }
85
+ const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
86
+ const coercedVariableValues = getVariableValues(resolvers, variableDefinitions, rawVariableValues != null ? rawVariableValues : {}, {maxErrors: 50});
87
+ if (coercedVariableValues.errors) {
88
+ return coercedVariableValues.errors;
89
+ }
90
+ return {
91
+ resolvers,
92
+ fragments,
93
+ rootValue,
94
+ contextValue,
95
+ operation,
96
+ variableValues: coercedVariableValues.coerced,
97
+ fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
98
+ typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
99
+ errors: []
100
+ };
101
+ }
102
+ function executeOperation(exeContext, operation, rootValue) {
103
+ const typeName = getOperationRootTypeName(operation);
104
+ const fields = collectFields(exeContext.resolvers, exeContext.fragments, exeContext.variableValues, typeName, operation.selectionSet, new Map(), new Set());
105
+ const path = void 0;
106
+ try {
107
+ const result = operation.operation === "mutation" ? executeFieldsSerially(exeContext, typeName, rootValue, path, fields) : executeFields(exeContext, typeName, rootValue, path, fields);
108
+ if (isPromise(result)) {
109
+ return result.then(void 0, (error) => {
110
+ exeContext.errors.push(error);
111
+ return Promise.resolve(null);
112
+ });
113
+ }
114
+ return result;
115
+ } catch (error) {
116
+ exeContext.errors.push(error);
117
+ return null;
118
+ }
119
+ }
120
+ function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, fields) {
121
+ return promiseReduce(fields.entries(), (results, [responseName, fieldNodes]) => {
122
+ const fieldPath = addPath(path, responseName, parentTypeName);
123
+ const result = executeField(exeContext, parentTypeName, sourceValue, fieldNodes, fieldPath);
124
+ if (result === void 0) {
125
+ return results;
126
+ }
127
+ if (isPromise(result)) {
128
+ return result.then((resolvedResult) => {
129
+ results[responseName] = resolvedResult;
130
+ return results;
131
+ });
132
+ }
133
+ results[responseName] = result;
134
+ return results;
135
+ }, Object.create(null));
136
+ }
137
+ function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
138
+ const results = Object.create(null);
139
+ let containsPromise = false;
140
+ for (const [responseName, fieldNodes] of fields.entries()) {
141
+ const fieldPath = addPath(path, responseName, parentTypeName);
142
+ const result = executeField(exeContext, parentTypeName, sourceValue, fieldNodes, fieldPath);
143
+ if (result !== void 0) {
144
+ results[responseName] = result;
145
+ if (isPromise(result)) {
146
+ containsPromise = true;
147
+ }
148
+ }
149
+ }
150
+ if (!containsPromise) {
151
+ return results;
152
+ }
153
+ return promiseForObject(results);
154
+ }
155
+ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
156
+ const fieldName = fieldNodes[0].name.value;
157
+ let resolveFn;
158
+ let returnTypeName;
159
+ let returnTypeNode;
160
+ if (fieldName === "__typename" && !resolveFn) {
161
+ resolveFn = () => parentTypeName;
162
+ returnTypeName = "String";
163
+ returnTypeNode = {
164
+ kind: Kind.NAMED_TYPE,
165
+ name: {
166
+ kind: Kind.NAME,
167
+ value: "String"
168
+ }
169
+ };
170
+ } else {
171
+ returnTypeNode = fieldNodes[0].__type;
172
+ returnTypeName = typeNameFromAST(returnTypeNode);
173
+ const typeResolvers = exeContext.resolvers[parentTypeName];
174
+ resolveFn = typeResolvers == null ? void 0 : typeResolvers[fieldName];
175
+ }
176
+ if (!resolveFn) {
177
+ resolveFn = exeContext.fieldResolver;
178
+ }
179
+ const info = buildResolveInfo(exeContext, fieldName, fieldNodes, parentTypeName, returnTypeName, returnTypeNode, path);
180
+ try {
181
+ const args = getArgumentValues(exeContext.resolvers, fieldNodes[0], exeContext.variableValues);
182
+ const contextValue = exeContext.contextValue;
183
+ const result = resolveFn(source, args, contextValue, info);
184
+ let completed;
185
+ if (isPromise(result)) {
186
+ completed = result.then((resolved) => completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resolved));
187
+ } else {
188
+ completed = completeValue(exeContext, returnTypeNode, fieldNodes, info, path, result);
189
+ }
190
+ if (isPromise(completed)) {
191
+ return completed.then(void 0, (rawError) => {
192
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
193
+ return handleFieldError(error, returnTypeNode, exeContext);
194
+ });
195
+ }
196
+ return completed;
197
+ } catch (rawError) {
198
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
199
+ return handleFieldError(error, returnTypeNode, exeContext);
200
+ }
201
+ }
202
+ function buildResolveInfo(exeContext, fieldName, fieldNodes, parentTypeName, returnTypeName, returnTypeNode, path) {
203
+ return {
204
+ fieldName,
205
+ fieldNodes,
206
+ returnTypeName,
207
+ parentTypeName,
208
+ returnTypeNode,
209
+ path,
210
+ fragments: exeContext.fragments,
211
+ rootValue: exeContext.rootValue,
212
+ operation: exeContext.operation,
213
+ variableValues: exeContext.variableValues
214
+ };
215
+ }
216
+ function handleFieldError(error, returnTypeNode, exeContext) {
217
+ if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
218
+ throw error;
219
+ }
220
+ exeContext.errors.push(error);
221
+ return null;
222
+ }
223
+ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
224
+ if (result instanceof Error) {
225
+ throw result;
226
+ }
227
+ if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
228
+ const completed = completeValue(exeContext, returnTypeNode.type, fieldNodes, info, path, result);
229
+ if (completed === null) {
230
+ throw new Error(`Cannot return null for non-nullable field ${info.parentTypeName}.${info.fieldName}.`);
231
+ }
232
+ return completed;
233
+ }
234
+ if (result == null) {
235
+ return null;
236
+ }
237
+ if (returnTypeNode.kind === Kind.LIST_TYPE) {
238
+ return completeListValue(exeContext, returnTypeNode.type, fieldNodes, info, path, result);
239
+ }
240
+ const returnTypeName = returnTypeNode.name.value;
241
+ let returnType = exeContext.resolvers[returnTypeName];
242
+ if (!returnType) {
243
+ returnType = specifiedScalars[returnTypeName];
244
+ }
245
+ if (isLeafType(returnType)) {
246
+ return completeLeafValue(returnType, result);
247
+ }
248
+ if (returnType instanceof GraphQLInputObjectType) {
249
+ }
250
+ if ("__resolveType" in returnType) {
251
+ return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
252
+ }
253
+ if (typeof returnType === "object") {
254
+ return completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result);
255
+ }
256
+ invariant(false, "Cannot complete value of unexpected output type: " + inspect(returnType));
257
+ }
258
+ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
259
+ if (!isIterableObject(result)) {
260
+ throw new GraphQLError(`Expected Iterable, but did not find one for field "${info.parentTypeName}.${info.fieldName}".`);
261
+ }
262
+ let containsPromise = false;
263
+ const completedResults = Array.from(result, (item, index) => {
264
+ const itemPath = addPath(path, index, void 0);
265
+ try {
266
+ let completedItem;
267
+ if (isPromise(item)) {
268
+ completedItem = item.then((resolved) => completeValue(exeContext, returnTypeNode, fieldNodes, info, itemPath, resolved));
269
+ } else {
270
+ completedItem = completeValue(exeContext, returnTypeNode, fieldNodes, info, itemPath, item);
271
+ }
272
+ if (isPromise(completedItem)) {
273
+ containsPromise = true;
274
+ return completedItem.then(void 0, (rawError) => {
275
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
276
+ return handleFieldError(error, returnTypeNode, exeContext);
277
+ });
278
+ }
279
+ return completedItem;
280
+ } catch (rawError) {
281
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
282
+ return handleFieldError(error, returnTypeNode, exeContext);
283
+ }
284
+ });
285
+ return containsPromise ? Promise.all(completedResults) : completedResults;
286
+ }
287
+ function completeLeafValue(returnType, result) {
288
+ const serializedResult = returnType.serialize(result);
289
+ if (serializedResult === void 0) {
290
+ throw new Error(`Expected a value of type "${inspect(returnType)}" but received: ${inspect(result)}`);
291
+ }
292
+ return serializedResult;
293
+ }
294
+ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
295
+ var _a;
296
+ const resolveTypeFn = (_a = returnType.__resolveType) != null ? _a : exeContext.typeResolver;
297
+ const contextValue = exeContext.contextValue;
298
+ const runtimeTypeName = resolveTypeFn(result, contextValue, info);
299
+ if (isPromise(runtimeTypeName)) {
300
+ return runtimeTypeName.then((resolvedRuntimeTypeName) => completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeTypeName, exeContext), fieldNodes, info, path, result));
301
+ }
302
+ return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeTypeName, exeContext), fieldNodes, info, path, result);
303
+ }
304
+ function ensureValidRuntimeType(runtimeTypeName, exeContext) {
305
+ if (typeof runtimeTypeName === "string") {
306
+ const runtimeType = exeContext.resolvers[runtimeTypeName];
307
+ if (!runtimeType) {
308
+ throw new Error("TODO - no such type");
309
+ } else if (runtimeType instanceof GraphQLScalarType || runtimeType instanceof GraphQLEnumType || runtimeType instanceof GraphQLInputObjectType || runtimeType.__resolveType) {
310
+ throw new Error("TODO - invalid runtime type");
311
+ } else {
312
+ return runtimeTypeName;
313
+ }
314
+ }
315
+ throw new Error("TODO - Could not determine runtime type for abstract type");
316
+ }
317
+ function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
318
+ const subFieldNodes = collectSubfields(exeContext, returnTypeName, fieldNodes);
319
+ return executeFields(exeContext, returnTypeName, result, path, subFieldNodes);
320
+ }
321
+ function invalidReturnTypeError(returnType, result, fieldNodes) {
322
+ return new GraphQLError(`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`, fieldNodes);
323
+ }
324
+ function collectSubfields(exeContext, returnTypeName, fieldNodes) {
325
+ let subFieldNodes = new Map();
326
+ const visitedFragmentNames = new Set();
327
+ for (const node of fieldNodes) {
328
+ if (node.selectionSet) {
329
+ subFieldNodes = collectFields(exeContext.resolvers, exeContext.fragments, exeContext.variableValues, returnTypeName, node.selectionSet, subFieldNodes, visitedFragmentNames);
330
+ }
331
+ }
332
+ return subFieldNodes;
333
+ }
334
+ const defaultTypeResolver = function(value) {
335
+ if (isObjectLike(value) && typeof value.__typename === "string") {
336
+ return value.__typename;
337
+ }
338
+ };
339
+ const defaultFieldResolver = function(source, args, contextValue, info) {
340
+ if (isObjectLike(source) || typeof source === "function") {
341
+ const property = source[info.fieldName];
342
+ if (typeof property === "function") {
343
+ return source[info.fieldName](args, contextValue, info);
344
+ }
345
+ return property;
346
+ }
347
+ };
348
+ function getOperationRootTypeName(operation) {
349
+ switch (operation.operation) {
350
+ case "query":
351
+ return "Query";
352
+ case "mutation":
353
+ return "Mutation";
354
+ case "subscription":
355
+ return "Subscription";
356
+ }
357
+ }
358
+ export {
359
+ assertValidExecutionArguments,
360
+ buildExecutionContext,
361
+ buildResolveInfo,
362
+ defaultFieldResolver,
363
+ defaultTypeResolver,
364
+ execute
365
+ };
@@ -0,0 +1,4 @@
1
+ import { PromiseOrValue } from "./jsutils/PromiseOrValue";
2
+ import { ExecutionResult, ExecutionWithSchemaArgs } from "./types";
3
+ export declare function executeWithSchema({ typeDefs, resolvers, document: rawDocument, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver, }: ExecutionWithSchemaArgs): PromiseOrValue<ExecutionResult>;
4
+ //# sourceMappingURL=executeWithSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeWithSchema.d.ts","sourceRoot":"","sources":["../src/executeWithSchema.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAIL,eAAe,EACf,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,cAAc,CAAC,eAAe,CAAC,CA2B3D"}
@@ -19,6 +19,10 @@ var __objSpread = (a, b) => {
19
19
  return a;
20
20
  };
21
21
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, {get: all[name], enumerable: true});
25
+ };
22
26
  var __reExport = (target, module2, desc) => {
23
27
  if (module2 && typeof module2 === "object" || typeof module2 === "function") {
24
28
  for (let key of __getOwnPropNames(module2))
@@ -30,50 +34,45 @@ var __reExport = (target, module2, desc) => {
30
34
  var __toModule = (module2) => {
31
35
  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);
32
36
  };
33
- var __async = (__this, __arguments, generator) => {
34
- return new Promise((resolve, reject) => {
35
- var fulfilled = (value) => {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- };
42
- var rejected = (value) => {
43
- try {
44
- step(generator.throw(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
- step((generator = generator.apply(__this, __arguments)).next());
51
- });
52
- };
37
+ __markAsModule(exports);
38
+ __export(exports, {
39
+ executeWithSchema: () => executeWithSchema
40
+ });
41
+ var import_schema = __toModule(require("@graphql-tools/schema"));
53
42
  var import_graphql = __toModule(require("graphql"));
54
43
  var import__ = __toModule(require("."));
55
- var import_swapi_schema = __toModule(require("../benchmarks/swapi-schema"));
56
- var import_models = __toModule(require("../benchmarks/swapi-schema/models"));
57
- var import_resolvers = __toModule(require("../benchmarks/swapi-schema/resolvers"));
58
- describe("execute", () => {
59
- it.skip("executes a basic query", () => __async(void 0, null, function* () {
60
- const query = `
61
- {
62
- person(id: 1) {
63
- name
64
- gender
65
- }
66
- }`;
67
- const document = (0, import_graphql.parse)(query);
68
- expect.assertions(1);
69
- const args = {
70
- document,
71
- contextValue: {
72
- models: import_models.default
73
- }
74
- };
75
- const result = yield (0, import__.execute)(__objSpread(__objSpread({}, args), {resolvers: import_resolvers.default}));
76
- const validResult = yield (0, import_graphql.execute)(__objSpread(__objSpread({}, args), {schema: import_swapi_schema.default}));
77
- expect(result).toEqual(validResult);
78
- }));
79
- });
44
+ function executeWithSchema({
45
+ typeDefs,
46
+ resolvers: resolvers2,
47
+ document: rawDocument,
48
+ rootValue,
49
+ contextValue,
50
+ variableValues,
51
+ operationName,
52
+ fieldResolver,
53
+ typeResolver
54
+ }) {
55
+ const schema = (0, import_schema.makeExecutableSchema)({typeDefs, resolvers: resolvers2});
56
+ let extractedResolvers = {};
57
+ const getTypeByName = (name) => {
58
+ const type = import__.specifiedScalars[name] || extractedResolvers[name];
59
+ if ((0, import_graphql.isInputType)(type)) {
60
+ return type;
61
+ } else {
62
+ throw new Error("Invalid type");
63
+ }
64
+ };
65
+ extractedResolvers = (0, import__.extractImplicitTypes)(typeDefs, getTypeByName);
66
+ const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers2);
67
+ const document = (0, import__.addTypesToRequestDocument)(schema, rawDocument);
68
+ return (0, import__.executeWithoutSchema)({
69
+ document,
70
+ resolvers: fullResolvers,
71
+ rootValue,
72
+ contextValue,
73
+ variableValues,
74
+ operationName,
75
+ fieldResolver,
76
+ typeResolver
77
+ });
78
+ }
@@ -0,0 +1,62 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
6
+ var __objSpread = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import {makeExecutableSchema} from "@graphql-tools/schema";
18
+ import {isInputType} from "graphql";
19
+ import {
20
+ addTypesToRequestDocument,
21
+ executeWithoutSchema,
22
+ extractImplicitTypes,
23
+ specifiedScalars
24
+ } from ".";
25
+ function executeWithSchema({
26
+ typeDefs,
27
+ resolvers: resolvers2,
28
+ document: rawDocument,
29
+ rootValue,
30
+ contextValue,
31
+ variableValues,
32
+ operationName,
33
+ fieldResolver,
34
+ typeResolver
35
+ }) {
36
+ const schema = makeExecutableSchema({typeDefs, resolvers: resolvers2});
37
+ let extractedResolvers = {};
38
+ const getTypeByName = (name) => {
39
+ const type = specifiedScalars[name] || extractedResolvers[name];
40
+ if (isInputType(type)) {
41
+ return type;
42
+ } else {
43
+ throw new Error("Invalid type");
44
+ }
45
+ };
46
+ extractedResolvers = extractImplicitTypes(typeDefs, getTypeByName);
47
+ const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers2);
48
+ const document = addTypesToRequestDocument(schema, rawDocument);
49
+ return executeWithoutSchema({
50
+ document,
51
+ resolvers: fullResolvers,
52
+ rootValue,
53
+ contextValue,
54
+ variableValues,
55
+ operationName,
56
+ fieldResolver,
57
+ typeResolver
58
+ });
59
+ }
60
+ export {
61
+ executeWithSchema
62
+ };
@@ -0,0 +1,99 @@
1
+ import { GraphQLError } from "graphql";
2
+ import { DocumentNode, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, TypeNode } from "./ast/TypedAST";
3
+ import type { Maybe } from "./jsutils/Maybe";
4
+ import type { ObjMap } from "./jsutils/ObjMap";
5
+ import type { Path } from "./jsutils/Path";
6
+ import type { PromiseOrValue } from "./jsutils/PromiseOrValue";
7
+ import { ExecutionWithoutSchemaArgs, FieldResolver, ResolveInfo, Resolvers, TypeResolver, ExecutionResult } from "./types";
8
+ /**
9
+ * Terminology
10
+ *
11
+ * "Definitions" are the generic name for top-level statements in the document.
12
+ * Examples of this include:
13
+ * 1) Operations (such as a query)
14
+ * 2) Fragments
15
+ *
16
+ * "Operations" are a generic name for requests in the document.
17
+ * Examples of this include:
18
+ * 1) query,
19
+ * 2) mutation
20
+ *
21
+ * "Selections" are the definitions that can appear legally and at
22
+ * single level of the query. These include:
23
+ * 1) field references e.g "a"
24
+ * 2) fragment "spreads" e.g. "...c"
25
+ * 3) inline fragment "spreads" e.g. "...on Type { a }"
26
+ */
27
+ /**
28
+ * Data that must be available at all points during query execution.
29
+ *
30
+ * Namely, schema of the type system that is currently executing,
31
+ * and the fragments defined in the query document
32
+ */
33
+ export interface ExecutionContext {
34
+ resolvers: Resolvers;
35
+ fragments: ObjMap<FragmentDefinitionNode>;
36
+ rootValue: unknown;
37
+ contextValue: unknown;
38
+ operation: OperationDefinitionNode;
39
+ variableValues: {
40
+ [variable: string]: unknown;
41
+ };
42
+ fieldResolver: FieldResolver<any, any>;
43
+ typeResolver: TypeResolver<any, any>;
44
+ errors: Array<GraphQLError>;
45
+ }
46
+ /**
47
+ * Implements the "Executing requests" section of the GraphQL specification.
48
+ *
49
+ * Returns either a synchronous ExecutionResult (if all encountered resolvers
50
+ * are synchronous), or a Promise of an ExecutionResult that will eventually be
51
+ * resolved and never rejected.
52
+ *
53
+ * If the arguments to this function do not result in a legal execution context,
54
+ * a GraphQLError will be thrown immediately explaining the invalid input.
55
+ */
56
+ export declare function executeWithoutSchema(args: ExecutionWithoutSchemaArgs): PromiseOrValue<ExecutionResult>;
57
+ /**
58
+ * Essential assertions before executing to provide developer feedback for
59
+ * improper use of the GraphQL library.
60
+ *
61
+ * @internal
62
+ */
63
+ export declare function assertValidExecutionArguments(document: DocumentNode, rawVariableValues: Maybe<{
64
+ [variable: string]: unknown;
65
+ }>): void;
66
+ /**
67
+ * Constructs a ExecutionContext object from the arguments passed to
68
+ * execute, which we will pass throughout the other execution methods.
69
+ *
70
+ * Throws a GraphQLError if a valid execution context cannot be created.
71
+ *
72
+ * @internal
73
+ */
74
+ export declare function buildExecutionContext(resolvers: Resolvers, document: DocumentNode, rootValue: unknown, contextValue: unknown, rawVariableValues: Maybe<{
75
+ [variable: string]: unknown;
76
+ }>, operationName: Maybe<string>, fieldResolver: Maybe<FieldResolver<unknown, unknown>>, typeResolver?: Maybe<TypeResolver<unknown, unknown>>): Array<GraphQLError> | ExecutionContext;
77
+ /**
78
+ * @internal
79
+ */
80
+ export declare function buildResolveInfo(exeContext: ExecutionContext, fieldName: string, fieldNodes: Array<FieldNode>, parentTypeName: string, returnTypeName: string, returnTypeNode: TypeNode, path: Path): ResolveInfo;
81
+ /**
82
+ * If a resolveType function is not given, then a default resolve behavior is
83
+ * used which attempts two strategies:
84
+ *
85
+ * First, See if the provided value has a `__typename` field defined, if so, use
86
+ * that value as name of the resolved type.
87
+ *
88
+ * Otherwise, test each possible type for the abstract type by calling
89
+ * isTypeOf for the object being coerced, returning the first type that matches.
90
+ */
91
+ export declare const defaultTypeResolver: TypeResolver<unknown, unknown>;
92
+ /**
93
+ * If a resolve function is not given, then a default resolve behavior is used
94
+ * which takes the property of the source object of the same name as the field
95
+ * and returns it as the result, or if it's a function, returns the result
96
+ * of calling that function while passing along args and context value.
97
+ */
98
+ export declare const defaultFieldResolver: FieldResolver<unknown, unknown>;
99
+ //# sourceMappingURL=executeWithoutSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeWithoutSchema.d.ts","sourceRoot":"","sources":["../src/executeWithoutSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EASb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EAEvB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EACL,0BAA0B,EAC1B,aAAa,EAGb,WAAW,EAEX,SAAS,EACT,YAAY,EAEZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAQjB;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,uBAAuB,CAAC;IACnC,cAAc,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAChD,aAAa,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvC,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,0BAA0B,GAC/B,cAAc,CAAC,eAAe,CAAC,CA0CjC;AAoBD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,YAAY,EACtB,iBAAiB,EAAE,KAAK,CAAC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,GACxD,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,OAAO,EACrB,iBAAiB,EAAE,KAAK,CAAC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,EACzD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,EAC5B,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EACrD,YAAY,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GACnD,KAAK,CAAC,YAAY,CAAC,GAAG,gBAAgB,CAyDxC;AAgPD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,gBAAgB,EAC5B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,EAC5B,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,QAAQ,EACxB,IAAI,EAAE,IAAI,GACT,WAAW,CAeb;AAoWD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAM9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,OAAO,EAAE,OAAO,CAchE,CAAC"}