@graphitation/supermassive 2.2.2 → 2.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.
- package/.eslintcache +1 -1
- package/CHANGELOG.md +9 -1
- package/lib/ast/TypedAST.js +1 -0
- package/lib/ast/addTypesToRequestDocument.js +48 -42
- package/lib/ast/addTypesToRequestDocument.mjs +47 -42
- package/lib/benchmarks/index.js +15 -4
- package/lib/benchmarks/index.mjs +6 -3
- package/lib/benchmarks/nice-benchmark.js +1 -0
- package/lib/benchmarks/swapi-schema/index.js +14 -4
- package/lib/benchmarks/swapi-schema/index.mjs +5 -3
- package/lib/benchmarks/swapi-schema/models.js +9 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +22 -7
- package/lib/benchmarks/swapi-schema/resolvers.mjs +21 -7
- package/lib/collectFields.js +41 -11
- package/lib/collectFields.mjs +40 -11
- package/lib/compiledQuery.js +1 -0
- package/lib/definition.js +13 -8
- package/lib/definition.mjs +12 -8
- package/lib/directives.js +48 -33
- package/lib/directives.mjs +47 -33
- package/lib/executeWithSchema.d.ts +1 -1
- package/lib/executeWithSchema.d.ts.map +1 -1
- package/lib/executeWithSchema.js +5 -2
- package/lib/executeWithSchema.mjs +4 -2
- package/lib/executeWithoutSchema.d.ts +3 -1
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +365 -55
- package/lib/executeWithoutSchema.mjs +358 -52
- package/lib/extractImplicitTypesRuntime.js +4 -1
- package/lib/extractImplicitTypesRuntime.mjs +3 -1
- package/lib/hooks/types.d.ts +33 -0
- package/lib/hooks/types.d.ts.map +1 -0
- package/lib/hooks/types.js +16 -0
- package/lib/hooks/types.mjs +0 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -0
- package/lib/index.mjs +16 -0
- package/lib/jsutils/Maybe.js +1 -0
- package/lib/jsutils/ObjMap.js +1 -0
- package/lib/jsutils/Path.js +1 -0
- package/lib/jsutils/PromiseOrValue.js +1 -0
- package/lib/jsutils/devAssert.js +1 -0
- package/lib/jsutils/didYouMean.js +1 -0
- package/lib/jsutils/identityFunc.js +1 -0
- package/lib/jsutils/inspect.js +4 -1
- package/lib/jsutils/inspect.mjs +3 -1
- package/lib/jsutils/instanceOf.js +18 -6
- package/lib/jsutils/instanceOf.mjs +17 -6
- package/lib/jsutils/invariant.js +4 -1
- package/lib/jsutils/invariant.mjs +3 -1
- package/lib/jsutils/isAsyncIterable.js +1 -0
- package/lib/jsutils/isIterableObject.js +1 -0
- package/lib/jsutils/isObjectLike.js +1 -0
- package/lib/jsutils/isPromise.js +1 -0
- package/lib/jsutils/keyMap.js +1 -0
- package/lib/jsutils/keyValMap.js +1 -0
- package/lib/jsutils/mapValue.js +1 -0
- package/lib/jsutils/memoize3.js +1 -0
- package/lib/jsutils/naturalCompare.js +1 -0
- package/lib/jsutils/printPathArray.js +4 -1
- package/lib/jsutils/printPathArray.mjs +3 -1
- package/lib/jsutils/promiseForObject.js +1 -0
- package/lib/jsutils/promiseReduce.js +1 -0
- package/lib/jsutils/suggestionList.js +9 -1
- package/lib/jsutils/suggestionList.mjs +8 -1
- package/lib/jsutils/toObjMap.js +1 -0
- package/lib/subscribeWithSchema.js +1 -0
- package/lib/subscribeWithoutSchema.js +45 -6
- package/lib/subscribeWithoutSchema.mjs +44 -6
- package/lib/transforms/annotateDocumentGraphQLTransform.js +1 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -0
- package/lib/utilities/array.d.ts +2 -0
- package/lib/utilities/array.d.ts.map +1 -0
- package/lib/utilities/array.js +34 -0
- package/lib/utilities/array.mjs +15 -0
- package/lib/utilities/blankGraphQLTag.js +1 -0
- package/lib/utilities/mapAsyncIterator.js +1 -0
- package/lib/utilities/mergeResolvers.js +1 -0
- package/lib/utilities/typeNameFromAST.js +1 -0
- package/lib/values.js +82 -21
- package/lib/values.mjs +81 -21
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -41,6 +42,7 @@ var import_definition = require("./definition");
|
|
|
41
42
|
var import_mergeResolvers = require("./utilities/mergeResolvers");
|
|
42
43
|
var import_typeNameFromAST = require("./utilities/typeNameFromAST");
|
|
43
44
|
var import_values = require("./values");
|
|
45
|
+
var import_array = require("./utilities/array");
|
|
44
46
|
function executeWithoutSchema(args) {
|
|
45
47
|
const {
|
|
46
48
|
resolvers,
|
|
@@ -51,11 +53,22 @@ function executeWithoutSchema(args) {
|
|
|
51
53
|
variableValues,
|
|
52
54
|
operationName,
|
|
53
55
|
fieldResolver,
|
|
54
|
-
typeResolver
|
|
56
|
+
typeResolver,
|
|
57
|
+
fieldExecutionHooks
|
|
55
58
|
} = args;
|
|
56
59
|
const combinedResolvers = (0, import_mergeResolvers.mergeResolvers)(resolvers, schemaResolvers);
|
|
57
60
|
assertValidExecutionArguments(document, variableValues);
|
|
58
|
-
const exeContext = buildExecutionContext(
|
|
61
|
+
const exeContext = buildExecutionContext(
|
|
62
|
+
combinedResolvers,
|
|
63
|
+
document,
|
|
64
|
+
rootValue,
|
|
65
|
+
contextValue,
|
|
66
|
+
variableValues,
|
|
67
|
+
operationName,
|
|
68
|
+
fieldResolver,
|
|
69
|
+
typeResolver,
|
|
70
|
+
fieldExecutionHooks
|
|
71
|
+
);
|
|
59
72
|
if (!("resolvers" in exeContext)) {
|
|
60
73
|
return { errors: exeContext };
|
|
61
74
|
} else {
|
|
@@ -65,15 +78,20 @@ function executeWithoutSchema(args) {
|
|
|
65
78
|
}
|
|
66
79
|
function buildResponse(exeContext, data) {
|
|
67
80
|
if ((0, import_isPromise.isPromise)(data)) {
|
|
68
|
-
return data.then(
|
|
81
|
+
return data.then(
|
|
82
|
+
(resolved) => buildResponse(exeContext, resolved)
|
|
83
|
+
);
|
|
69
84
|
}
|
|
70
85
|
return exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
71
86
|
}
|
|
72
87
|
function assertValidExecutionArguments(document, rawVariableValues) {
|
|
73
88
|
(0, import_devAssert.devAssert)(document, "Must provide document.");
|
|
74
|
-
(0, import_devAssert.devAssert)(
|
|
89
|
+
(0, import_devAssert.devAssert)(
|
|
90
|
+
rawVariableValues == null || (0, import_isObjectLike.isObjectLike)(rawVariableValues),
|
|
91
|
+
"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."
|
|
92
|
+
);
|
|
75
93
|
}
|
|
76
|
-
function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
|
|
94
|
+
function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver, fieldExecutionHooks) {
|
|
77
95
|
var _a, _b;
|
|
78
96
|
let operation;
|
|
79
97
|
const fragments = /* @__PURE__ */ Object.create(null);
|
|
@@ -83,7 +101,9 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
83
101
|
if (operationName == null) {
|
|
84
102
|
if (operation !== void 0) {
|
|
85
103
|
return [
|
|
86
|
-
new import_graphql.GraphQLError(
|
|
104
|
+
new import_graphql.GraphQLError(
|
|
105
|
+
"Must provide operation name if query contains multiple operations."
|
|
106
|
+
)
|
|
87
107
|
];
|
|
88
108
|
}
|
|
89
109
|
operation = definition;
|
|
@@ -103,7 +123,12 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
103
123
|
return [new import_graphql.GraphQLError("Must provide an operation.")];
|
|
104
124
|
}
|
|
105
125
|
const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
|
|
106
|
-
const coercedVariableValues = (0, import_values.getVariableValues)(
|
|
126
|
+
const coercedVariableValues = (0, import_values.getVariableValues)(
|
|
127
|
+
resolvers,
|
|
128
|
+
variableDefinitions,
|
|
129
|
+
rawVariableValues != null ? rawVariableValues : {},
|
|
130
|
+
{ maxErrors: 50 }
|
|
131
|
+
);
|
|
107
132
|
if (coercedVariableValues.errors) {
|
|
108
133
|
return coercedVariableValues.errors;
|
|
109
134
|
}
|
|
@@ -116,12 +141,21 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
116
141
|
variableValues: coercedVariableValues.coerced,
|
|
117
142
|
fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
|
|
118
143
|
typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
|
|
119
|
-
errors: []
|
|
144
|
+
errors: [],
|
|
145
|
+
fieldExecutionHooks
|
|
120
146
|
};
|
|
121
147
|
}
|
|
122
148
|
function executeOperation(exeContext, operation, rootValue) {
|
|
123
149
|
const typeName = getOperationRootTypeName(operation);
|
|
124
|
-
const fields = (0, import_collectFields.collectFields)(
|
|
150
|
+
const fields = (0, import_collectFields.collectFields)(
|
|
151
|
+
exeContext.resolvers,
|
|
152
|
+
exeContext.fragments,
|
|
153
|
+
exeContext.variableValues,
|
|
154
|
+
typeName,
|
|
155
|
+
operation.selectionSet,
|
|
156
|
+
/* @__PURE__ */ new Map(),
|
|
157
|
+
/* @__PURE__ */ new Set()
|
|
158
|
+
);
|
|
125
159
|
const path = void 0;
|
|
126
160
|
try {
|
|
127
161
|
const result = operation.operation === "mutation" ? executeFieldsSerially(exeContext, typeName, rootValue, path, fields) : executeFields(exeContext, typeName, rootValue, path, fields);
|
|
@@ -138,28 +172,44 @@ function executeOperation(exeContext, operation, rootValue) {
|
|
|
138
172
|
}
|
|
139
173
|
}
|
|
140
174
|
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
141
|
-
return (0, import_promiseReduce.promiseReduce)(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
175
|
+
return (0, import_promiseReduce.promiseReduce)(
|
|
176
|
+
fields.entries(),
|
|
177
|
+
(results, [responseName, fieldNodes]) => {
|
|
178
|
+
const fieldPath = (0, import_Path.addPath)(path, responseName, parentTypeName);
|
|
179
|
+
const result = executeField(
|
|
180
|
+
exeContext,
|
|
181
|
+
parentTypeName,
|
|
182
|
+
sourceValue,
|
|
183
|
+
fieldNodes,
|
|
184
|
+
fieldPath
|
|
185
|
+
);
|
|
186
|
+
if (result === void 0) {
|
|
150
187
|
return results;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
188
|
+
}
|
|
189
|
+
if ((0, import_isPromise.isPromise)(result)) {
|
|
190
|
+
return result.then((resolvedResult) => {
|
|
191
|
+
results[responseName] = resolvedResult;
|
|
192
|
+
return results;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
results[responseName] = result;
|
|
196
|
+
return results;
|
|
197
|
+
},
|
|
198
|
+
/* @__PURE__ */ Object.create(null)
|
|
199
|
+
);
|
|
156
200
|
}
|
|
157
201
|
function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
158
202
|
const results = /* @__PURE__ */ Object.create(null);
|
|
159
203
|
let containsPromise = false;
|
|
160
204
|
for (const [responseName, fieldNodes] of fields.entries()) {
|
|
161
205
|
const fieldPath = (0, import_Path.addPath)(path, responseName, parentTypeName);
|
|
162
|
-
const result = executeField(
|
|
206
|
+
const result = executeField(
|
|
207
|
+
exeContext,
|
|
208
|
+
parentTypeName,
|
|
209
|
+
sourceValue,
|
|
210
|
+
fieldNodes,
|
|
211
|
+
fieldPath
|
|
212
|
+
);
|
|
163
213
|
if (result !== void 0) {
|
|
164
214
|
results[responseName] = result;
|
|
165
215
|
if ((0, import_isPromise.isPromise)(result)) {
|
|
@@ -174,6 +224,7 @@ function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
|
174
224
|
}
|
|
175
225
|
function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
176
226
|
const fieldName = fieldNodes[0].name.value;
|
|
227
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
177
228
|
let resolveFn;
|
|
178
229
|
let returnTypeName;
|
|
179
230
|
let returnTypeNode;
|
|
@@ -196,29 +247,104 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
196
247
|
resolveFn = resolveFn.resolve;
|
|
197
248
|
}
|
|
198
249
|
}
|
|
250
|
+
const isDefaultResolverUsed = !resolveFn;
|
|
199
251
|
if (!resolveFn) {
|
|
200
252
|
resolveFn = exeContext.fieldResolver;
|
|
201
253
|
}
|
|
202
|
-
const info = buildResolveInfo(
|
|
254
|
+
const info = buildResolveInfo(
|
|
255
|
+
exeContext,
|
|
256
|
+
fieldName,
|
|
257
|
+
fieldNodes,
|
|
258
|
+
parentTypeName,
|
|
259
|
+
returnTypeName,
|
|
260
|
+
returnTypeNode,
|
|
261
|
+
path
|
|
262
|
+
);
|
|
203
263
|
try {
|
|
204
|
-
const args = (0, import_values.getArgumentValues)(
|
|
264
|
+
const args = (0, import_values.getArgumentValues)(
|
|
265
|
+
exeContext.resolvers,
|
|
266
|
+
fieldNodes[0],
|
|
267
|
+
exeContext.variableValues
|
|
268
|
+
);
|
|
269
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
270
|
+
invokeBeforeFieldResolveHook(info, exeContext);
|
|
271
|
+
}
|
|
205
272
|
const contextValue = exeContext.contextValue;
|
|
206
273
|
const result = resolveFn(source, args, contextValue, info);
|
|
207
274
|
let completed;
|
|
208
275
|
if ((0, import_isPromise.isPromise)(result)) {
|
|
209
|
-
completed = result.then(
|
|
276
|
+
completed = result.then(
|
|
277
|
+
(resolved) => {
|
|
278
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
279
|
+
invokeAfterFieldResolveHook(info, exeContext, resolved);
|
|
280
|
+
}
|
|
281
|
+
return completeValue(
|
|
282
|
+
exeContext,
|
|
283
|
+
returnTypeNode,
|
|
284
|
+
fieldNodes,
|
|
285
|
+
info,
|
|
286
|
+
path,
|
|
287
|
+
resolved
|
|
288
|
+
);
|
|
289
|
+
},
|
|
290
|
+
(rawError) => {
|
|
291
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
292
|
+
invokeAfterFieldResolveHook(info, exeContext, void 0, rawError);
|
|
293
|
+
}
|
|
294
|
+
throw rawError;
|
|
295
|
+
}
|
|
296
|
+
);
|
|
210
297
|
} else {
|
|
211
|
-
|
|
298
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
299
|
+
invokeAfterFieldResolveHook(info, exeContext, result);
|
|
300
|
+
}
|
|
301
|
+
completed = completeValue(
|
|
302
|
+
exeContext,
|
|
303
|
+
returnTypeNode,
|
|
304
|
+
fieldNodes,
|
|
305
|
+
info,
|
|
306
|
+
path,
|
|
307
|
+
result
|
|
308
|
+
);
|
|
212
309
|
}
|
|
213
310
|
if ((0, import_isPromise.isPromise)(completed)) {
|
|
214
|
-
return completed.then(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
311
|
+
return completed.then(
|
|
312
|
+
(resolved) => {
|
|
313
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
314
|
+
invokeAfterFieldCompleteHook(info, exeContext, resolved);
|
|
315
|
+
}
|
|
316
|
+
return resolved;
|
|
317
|
+
},
|
|
318
|
+
(rawError) => {
|
|
319
|
+
const error = (0, import_graphql.locatedError)(
|
|
320
|
+
rawError,
|
|
321
|
+
fieldNodes,
|
|
322
|
+
(0, import_Path.pathToArray)(path)
|
|
323
|
+
);
|
|
324
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
325
|
+
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
326
|
+
}
|
|
327
|
+
return handleFieldError(error, returnTypeNode, exeContext);
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
332
|
+
invokeAfterFieldCompleteHook(info, exeContext, completed);
|
|
218
333
|
}
|
|
219
334
|
return completed;
|
|
220
335
|
} catch (rawError) {
|
|
221
|
-
const
|
|
336
|
+
const pathArray = (0, import_Path.pathToArray)(path);
|
|
337
|
+
const error = (0, import_graphql.locatedError)(
|
|
338
|
+
rawError,
|
|
339
|
+
fieldNodes,
|
|
340
|
+
pathArray
|
|
341
|
+
);
|
|
342
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve) && error.path && (0, import_array.arraysAreEqual)(pathArray, error.path)) {
|
|
343
|
+
invokeAfterFieldResolveHook(info, exeContext, void 0, error);
|
|
344
|
+
}
|
|
345
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
346
|
+
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
347
|
+
}
|
|
222
348
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
223
349
|
}
|
|
224
350
|
}
|
|
@@ -248,9 +374,18 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
248
374
|
throw result;
|
|
249
375
|
}
|
|
250
376
|
if (returnTypeNode.kind === import_graphql.Kind.NON_NULL_TYPE) {
|
|
251
|
-
const completed = completeValue(
|
|
377
|
+
const completed = completeValue(
|
|
378
|
+
exeContext,
|
|
379
|
+
returnTypeNode.type,
|
|
380
|
+
fieldNodes,
|
|
381
|
+
info,
|
|
382
|
+
path,
|
|
383
|
+
result
|
|
384
|
+
);
|
|
252
385
|
if (completed === null) {
|
|
253
|
-
throw new Error(
|
|
386
|
+
throw new Error(
|
|
387
|
+
`Cannot return null for non-nullable field ${info.parentTypeName}.${info.fieldName}.`
|
|
388
|
+
);
|
|
254
389
|
}
|
|
255
390
|
return completed;
|
|
256
391
|
}
|
|
@@ -258,7 +393,14 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
258
393
|
return null;
|
|
259
394
|
}
|
|
260
395
|
if (returnTypeNode.kind === import_graphql.Kind.LIST_TYPE) {
|
|
261
|
-
return completeListValue(
|
|
396
|
+
return completeListValue(
|
|
397
|
+
exeContext,
|
|
398
|
+
returnTypeNode.type,
|
|
399
|
+
fieldNodes,
|
|
400
|
+
info,
|
|
401
|
+
path,
|
|
402
|
+
result
|
|
403
|
+
);
|
|
262
404
|
}
|
|
263
405
|
const returnTypeName = returnTypeNode.name.value;
|
|
264
406
|
let returnType = exeContext.resolvers[returnTypeName];
|
|
@@ -271,16 +413,35 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
271
413
|
if (returnType instanceof import_graphql.GraphQLInputObjectType) {
|
|
272
414
|
}
|
|
273
415
|
if ((0, import_definition.isUnionResolverType)(returnType) || (0, import_definition.isInterfaceResolverType)(returnType)) {
|
|
274
|
-
return completeAbstractValue(
|
|
416
|
+
return completeAbstractValue(
|
|
417
|
+
exeContext,
|
|
418
|
+
returnType,
|
|
419
|
+
fieldNodes,
|
|
420
|
+
info,
|
|
421
|
+
path,
|
|
422
|
+
result
|
|
423
|
+
);
|
|
275
424
|
}
|
|
276
425
|
if (typeof returnType === "object") {
|
|
277
|
-
return completeObjectValue(
|
|
278
|
-
|
|
279
|
-
|
|
426
|
+
return completeObjectValue(
|
|
427
|
+
exeContext,
|
|
428
|
+
returnTypeName,
|
|
429
|
+
fieldNodes,
|
|
430
|
+
info,
|
|
431
|
+
path,
|
|
432
|
+
result
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
(0, import_invariant.invariant)(
|
|
436
|
+
false,
|
|
437
|
+
"Cannot complete value of unexpected output type: " + (0, import_inspect.inspect)(returnType)
|
|
438
|
+
);
|
|
280
439
|
}
|
|
281
440
|
function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
|
|
282
441
|
if (!(0, import_isIterableObject.isIterableObject)(result)) {
|
|
283
|
-
throw new import_graphql.GraphQLError(
|
|
442
|
+
throw new import_graphql.GraphQLError(
|
|
443
|
+
`Expected Iterable, but did not find one for field "${info.parentTypeName}.${info.fieldName}".`
|
|
444
|
+
);
|
|
284
445
|
}
|
|
285
446
|
let containsPromise = false;
|
|
286
447
|
const completedResults = Array.from(result, (item, index) => {
|
|
@@ -288,20 +449,44 @@ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, r
|
|
|
288
449
|
try {
|
|
289
450
|
let completedItem;
|
|
290
451
|
if ((0, import_isPromise.isPromise)(item)) {
|
|
291
|
-
completedItem = item.then(
|
|
452
|
+
completedItem = item.then(
|
|
453
|
+
(resolved) => completeValue(
|
|
454
|
+
exeContext,
|
|
455
|
+
returnTypeNode,
|
|
456
|
+
fieldNodes,
|
|
457
|
+
info,
|
|
458
|
+
itemPath,
|
|
459
|
+
resolved
|
|
460
|
+
)
|
|
461
|
+
);
|
|
292
462
|
} else {
|
|
293
|
-
completedItem = completeValue(
|
|
463
|
+
completedItem = completeValue(
|
|
464
|
+
exeContext,
|
|
465
|
+
returnTypeNode,
|
|
466
|
+
fieldNodes,
|
|
467
|
+
info,
|
|
468
|
+
itemPath,
|
|
469
|
+
item
|
|
470
|
+
);
|
|
294
471
|
}
|
|
295
472
|
if ((0, import_isPromise.isPromise)(completedItem)) {
|
|
296
473
|
containsPromise = true;
|
|
297
474
|
return completedItem.then(void 0, (rawError) => {
|
|
298
|
-
const error = (0, import_graphql.locatedError)(
|
|
475
|
+
const error = (0, import_graphql.locatedError)(
|
|
476
|
+
rawError,
|
|
477
|
+
fieldNodes,
|
|
478
|
+
(0, import_Path.pathToArray)(itemPath)
|
|
479
|
+
);
|
|
299
480
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
300
481
|
});
|
|
301
482
|
}
|
|
302
483
|
return completedItem;
|
|
303
484
|
} catch (rawError) {
|
|
304
|
-
const error = (0, import_graphql.locatedError)(
|
|
485
|
+
const error = (0, import_graphql.locatedError)(
|
|
486
|
+
rawError,
|
|
487
|
+
fieldNodes,
|
|
488
|
+
(0, import_Path.pathToArray)(itemPath)
|
|
489
|
+
);
|
|
305
490
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
306
491
|
}
|
|
307
492
|
});
|
|
@@ -310,7 +495,9 @@ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, r
|
|
|
310
495
|
function completeLeafValue(returnType, result) {
|
|
311
496
|
const serializedResult = returnType.serialize(result);
|
|
312
497
|
if (serializedResult === void 0) {
|
|
313
|
-
throw new Error(
|
|
498
|
+
throw new Error(
|
|
499
|
+
`Expected a value of type "${(0, import_inspect.inspect)(returnType)}" but received: ${(0, import_inspect.inspect)(result)}`
|
|
500
|
+
);
|
|
314
501
|
}
|
|
315
502
|
return serializedResult;
|
|
316
503
|
}
|
|
@@ -320,19 +507,43 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
320
507
|
const contextValue = exeContext.contextValue;
|
|
321
508
|
const runtimeTypeName = resolveTypeFn(result, contextValue, info);
|
|
322
509
|
if ((0, import_isPromise.isPromise)(runtimeTypeName)) {
|
|
323
|
-
return runtimeTypeName.then(
|
|
324
|
-
|
|
325
|
-
|
|
510
|
+
return runtimeTypeName.then(
|
|
511
|
+
(resolvedRuntimeTypeName) => completeObjectValue(
|
|
512
|
+
exeContext,
|
|
513
|
+
ensureValidRuntimeType(resolvedRuntimeTypeName, exeContext),
|
|
514
|
+
fieldNodes,
|
|
515
|
+
info,
|
|
516
|
+
path,
|
|
517
|
+
result
|
|
518
|
+
)
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
return completeObjectValue(
|
|
522
|
+
exeContext,
|
|
523
|
+
ensureValidRuntimeType(runtimeTypeName, exeContext),
|
|
524
|
+
fieldNodes,
|
|
525
|
+
info,
|
|
526
|
+
path,
|
|
527
|
+
result
|
|
528
|
+
);
|
|
326
529
|
}
|
|
327
530
|
function ensureValidRuntimeType(runtimeTypeName, exeContext) {
|
|
328
531
|
if (typeof runtimeTypeName !== "string") {
|
|
329
|
-
throw new import_graphql.GraphQLError(
|
|
532
|
+
throw new import_graphql.GraphQLError(
|
|
533
|
+
`Could not determine runtime type for abstract type ${runtimeTypeName}`
|
|
534
|
+
);
|
|
330
535
|
}
|
|
331
536
|
const runtimeType = exeContext.resolvers[runtimeTypeName];
|
|
332
537
|
if (!runtimeType) {
|
|
333
|
-
throw new import_graphql.GraphQLError(
|
|
538
|
+
throw new import_graphql.GraphQLError(
|
|
539
|
+
`Type "${runtimeTypeName}" does not exist inside the schema.`
|
|
540
|
+
);
|
|
334
541
|
} else if (runtimeType instanceof import_graphql.GraphQLScalarType || runtimeType instanceof import_graphql.GraphQLEnumType || runtimeType instanceof import_graphql.GraphQLInputObjectType || runtimeType.__resolveType) {
|
|
335
|
-
throw new import_graphql.GraphQLError(
|
|
542
|
+
throw new import_graphql.GraphQLError(
|
|
543
|
+
`Given runtime object "${getRuntimeTypeInstanceName(
|
|
544
|
+
runtimeType
|
|
545
|
+
)}" type is not a possible type for "${runtimeTypeName}".`
|
|
546
|
+
);
|
|
336
547
|
} else {
|
|
337
548
|
return runtimeTypeName;
|
|
338
549
|
}
|
|
@@ -353,22 +564,121 @@ function getRuntimeTypeInstanceName(runtimeType) {
|
|
|
353
564
|
}
|
|
354
565
|
}
|
|
355
566
|
function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
|
|
356
|
-
const subFieldNodes = collectSubfields(
|
|
567
|
+
const subFieldNodes = collectSubfields(
|
|
568
|
+
exeContext,
|
|
569
|
+
returnTypeName,
|
|
570
|
+
fieldNodes
|
|
571
|
+
);
|
|
357
572
|
return executeFields(exeContext, returnTypeName, result, path, subFieldNodes);
|
|
358
573
|
}
|
|
359
574
|
function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
360
|
-
return new import_graphql.GraphQLError(
|
|
575
|
+
return new import_graphql.GraphQLError(
|
|
576
|
+
`Expected value of type "${returnType.name}" but got: ${(0, import_inspect.inspect)(result)}.`,
|
|
577
|
+
fieldNodes
|
|
578
|
+
);
|
|
361
579
|
}
|
|
362
580
|
function collectSubfields(exeContext, returnTypeName, fieldNodes) {
|
|
363
581
|
let subFieldNodes = /* @__PURE__ */ new Map();
|
|
364
582
|
const visitedFragmentNames = /* @__PURE__ */ new Set();
|
|
365
583
|
for (const node of fieldNodes) {
|
|
366
584
|
if (node.selectionSet) {
|
|
367
|
-
subFieldNodes = (0, import_collectFields.collectFields)(
|
|
585
|
+
subFieldNodes = (0, import_collectFields.collectFields)(
|
|
586
|
+
exeContext.resolvers,
|
|
587
|
+
exeContext.fragments,
|
|
588
|
+
exeContext.variableValues,
|
|
589
|
+
returnTypeName,
|
|
590
|
+
node.selectionSet,
|
|
591
|
+
subFieldNodes,
|
|
592
|
+
visitedFragmentNames
|
|
593
|
+
);
|
|
368
594
|
}
|
|
369
595
|
}
|
|
370
596
|
return subFieldNodes;
|
|
371
597
|
}
|
|
598
|
+
function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
599
|
+
var _a;
|
|
600
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeFieldResolve;
|
|
601
|
+
if (!hook) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
executeSafe(
|
|
605
|
+
() => hook({
|
|
606
|
+
resolveInfo,
|
|
607
|
+
context: exeContext.contextValue
|
|
608
|
+
}),
|
|
609
|
+
(_, rawError) => {
|
|
610
|
+
const error = toGraphQLError(
|
|
611
|
+
rawError,
|
|
612
|
+
resolveInfo.path,
|
|
613
|
+
"Unexpected error in beforeFieldResolve hook"
|
|
614
|
+
);
|
|
615
|
+
exeContext.errors.push(error);
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
function invokeAfterFieldResolveHook(resolveInfo, exeContext, result, error) {
|
|
620
|
+
var _a;
|
|
621
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldResolve;
|
|
622
|
+
if (!hook) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
executeSafe(
|
|
626
|
+
() => hook({
|
|
627
|
+
resolveInfo,
|
|
628
|
+
context: exeContext.contextValue,
|
|
629
|
+
result,
|
|
630
|
+
error
|
|
631
|
+
}),
|
|
632
|
+
(_, rawError) => {
|
|
633
|
+
const error2 = toGraphQLError(
|
|
634
|
+
rawError,
|
|
635
|
+
resolveInfo.path,
|
|
636
|
+
"Unexpected error in afterFieldResolve hook"
|
|
637
|
+
);
|
|
638
|
+
exeContext.errors.push(error2);
|
|
639
|
+
}
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
function invokeAfterFieldCompleteHook(resolveInfo, exeContext, result, error) {
|
|
643
|
+
var _a;
|
|
644
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldComplete;
|
|
645
|
+
if (!hook) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
executeSafe(
|
|
649
|
+
() => hook({
|
|
650
|
+
resolveInfo,
|
|
651
|
+
context: exeContext.contextValue,
|
|
652
|
+
result,
|
|
653
|
+
error
|
|
654
|
+
}),
|
|
655
|
+
(_, rawError) => {
|
|
656
|
+
const error2 = toGraphQLError(
|
|
657
|
+
rawError,
|
|
658
|
+
resolveInfo.path,
|
|
659
|
+
"Unexpected error in afterFieldComplete hook"
|
|
660
|
+
);
|
|
661
|
+
exeContext.errors.push(error2);
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
function executeSafe(execute, onComplete) {
|
|
666
|
+
let error;
|
|
667
|
+
let result;
|
|
668
|
+
try {
|
|
669
|
+
result = execute();
|
|
670
|
+
} catch (e) {
|
|
671
|
+
error = e;
|
|
672
|
+
} finally {
|
|
673
|
+
onComplete(result, error);
|
|
674
|
+
return result;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function toGraphQLError(originalError, path, prependMessage) {
|
|
678
|
+
const originalMessage = originalError instanceof Error ? originalError.message : (0, import_inspect.inspect)(originalError);
|
|
679
|
+
const error = new Error(`${prependMessage}: ${originalMessage}`);
|
|
680
|
+
return (0, import_graphql.locatedError)(error, void 0, (0, import_Path.pathToArray)(path));
|
|
681
|
+
}
|
|
372
682
|
const defaultTypeResolver = function(value) {
|
|
373
683
|
if ((0, import_isObjectLike.isObjectLike)(value) && typeof value.__typename === "string") {
|
|
374
684
|
return value.__typename;
|