@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
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getVariableValues,
|
|
27
27
|
specifiedScalars
|
|
28
28
|
} from "./values.mjs";
|
|
29
|
+
import { arraysAreEqual } from "./utilities/array.mjs";
|
|
29
30
|
function executeWithoutSchema(args) {
|
|
30
31
|
const {
|
|
31
32
|
resolvers,
|
|
@@ -36,11 +37,22 @@ function executeWithoutSchema(args) {
|
|
|
36
37
|
variableValues,
|
|
37
38
|
operationName,
|
|
38
39
|
fieldResolver,
|
|
39
|
-
typeResolver
|
|
40
|
+
typeResolver,
|
|
41
|
+
fieldExecutionHooks
|
|
40
42
|
} = args;
|
|
41
43
|
const combinedResolvers = mergeResolvers(resolvers, schemaResolvers);
|
|
42
44
|
assertValidExecutionArguments(document, variableValues);
|
|
43
|
-
const exeContext = buildExecutionContext(
|
|
45
|
+
const exeContext = buildExecutionContext(
|
|
46
|
+
combinedResolvers,
|
|
47
|
+
document,
|
|
48
|
+
rootValue,
|
|
49
|
+
contextValue,
|
|
50
|
+
variableValues,
|
|
51
|
+
operationName,
|
|
52
|
+
fieldResolver,
|
|
53
|
+
typeResolver,
|
|
54
|
+
fieldExecutionHooks
|
|
55
|
+
);
|
|
44
56
|
if (!("resolvers" in exeContext)) {
|
|
45
57
|
return { errors: exeContext };
|
|
46
58
|
} else {
|
|
@@ -50,15 +62,20 @@ function executeWithoutSchema(args) {
|
|
|
50
62
|
}
|
|
51
63
|
function buildResponse(exeContext, data) {
|
|
52
64
|
if (isPromise(data)) {
|
|
53
|
-
return data.then(
|
|
65
|
+
return data.then(
|
|
66
|
+
(resolved) => buildResponse(exeContext, resolved)
|
|
67
|
+
);
|
|
54
68
|
}
|
|
55
69
|
return exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
56
70
|
}
|
|
57
71
|
function assertValidExecutionArguments(document, rawVariableValues) {
|
|
58
72
|
devAssert(document, "Must provide document.");
|
|
59
|
-
devAssert(
|
|
73
|
+
devAssert(
|
|
74
|
+
rawVariableValues == null || isObjectLike(rawVariableValues),
|
|
75
|
+
"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."
|
|
76
|
+
);
|
|
60
77
|
}
|
|
61
|
-
function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver) {
|
|
78
|
+
function buildExecutionContext(resolvers, document, rootValue, contextValue, rawVariableValues, operationName, fieldResolver, typeResolver, fieldExecutionHooks) {
|
|
62
79
|
var _a, _b;
|
|
63
80
|
let operation;
|
|
64
81
|
const fragments = /* @__PURE__ */ Object.create(null);
|
|
@@ -68,7 +85,9 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
68
85
|
if (operationName == null) {
|
|
69
86
|
if (operation !== void 0) {
|
|
70
87
|
return [
|
|
71
|
-
new GraphQLError(
|
|
88
|
+
new GraphQLError(
|
|
89
|
+
"Must provide operation name if query contains multiple operations."
|
|
90
|
+
)
|
|
72
91
|
];
|
|
73
92
|
}
|
|
74
93
|
operation = definition;
|
|
@@ -88,7 +107,12 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
88
107
|
return [new GraphQLError("Must provide an operation.")];
|
|
89
108
|
}
|
|
90
109
|
const variableDefinitions = (_b = operation.variableDefinitions) != null ? _b : [];
|
|
91
|
-
const coercedVariableValues = getVariableValues(
|
|
110
|
+
const coercedVariableValues = getVariableValues(
|
|
111
|
+
resolvers,
|
|
112
|
+
variableDefinitions,
|
|
113
|
+
rawVariableValues != null ? rawVariableValues : {},
|
|
114
|
+
{ maxErrors: 50 }
|
|
115
|
+
);
|
|
92
116
|
if (coercedVariableValues.errors) {
|
|
93
117
|
return coercedVariableValues.errors;
|
|
94
118
|
}
|
|
@@ -101,12 +125,21 @@ function buildExecutionContext(resolvers, document, rootValue, contextValue, raw
|
|
|
101
125
|
variableValues: coercedVariableValues.coerced,
|
|
102
126
|
fieldResolver: fieldResolver != null ? fieldResolver : defaultFieldResolver,
|
|
103
127
|
typeResolver: typeResolver != null ? typeResolver : defaultTypeResolver,
|
|
104
|
-
errors: []
|
|
128
|
+
errors: [],
|
|
129
|
+
fieldExecutionHooks
|
|
105
130
|
};
|
|
106
131
|
}
|
|
107
132
|
function executeOperation(exeContext, operation, rootValue) {
|
|
108
133
|
const typeName = getOperationRootTypeName(operation);
|
|
109
|
-
const fields = collectFields(
|
|
134
|
+
const fields = collectFields(
|
|
135
|
+
exeContext.resolvers,
|
|
136
|
+
exeContext.fragments,
|
|
137
|
+
exeContext.variableValues,
|
|
138
|
+
typeName,
|
|
139
|
+
operation.selectionSet,
|
|
140
|
+
/* @__PURE__ */ new Map(),
|
|
141
|
+
/* @__PURE__ */ new Set()
|
|
142
|
+
);
|
|
110
143
|
const path = void 0;
|
|
111
144
|
try {
|
|
112
145
|
const result = operation.operation === "mutation" ? executeFieldsSerially(exeContext, typeName, rootValue, path, fields) : executeFields(exeContext, typeName, rootValue, path, fields);
|
|
@@ -123,28 +156,44 @@ function executeOperation(exeContext, operation, rootValue) {
|
|
|
123
156
|
}
|
|
124
157
|
}
|
|
125
158
|
function executeFieldsSerially(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
126
|
-
return promiseReduce(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
159
|
+
return promiseReduce(
|
|
160
|
+
fields.entries(),
|
|
161
|
+
(results, [responseName, fieldNodes]) => {
|
|
162
|
+
const fieldPath = addPath(path, responseName, parentTypeName);
|
|
163
|
+
const result = executeField(
|
|
164
|
+
exeContext,
|
|
165
|
+
parentTypeName,
|
|
166
|
+
sourceValue,
|
|
167
|
+
fieldNodes,
|
|
168
|
+
fieldPath
|
|
169
|
+
);
|
|
170
|
+
if (result === void 0) {
|
|
135
171
|
return results;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
172
|
+
}
|
|
173
|
+
if (isPromise(result)) {
|
|
174
|
+
return result.then((resolvedResult) => {
|
|
175
|
+
results[responseName] = resolvedResult;
|
|
176
|
+
return results;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
results[responseName] = result;
|
|
180
|
+
return results;
|
|
181
|
+
},
|
|
182
|
+
/* @__PURE__ */ Object.create(null)
|
|
183
|
+
);
|
|
141
184
|
}
|
|
142
185
|
function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
143
186
|
const results = /* @__PURE__ */ Object.create(null);
|
|
144
187
|
let containsPromise = false;
|
|
145
188
|
for (const [responseName, fieldNodes] of fields.entries()) {
|
|
146
189
|
const fieldPath = addPath(path, responseName, parentTypeName);
|
|
147
|
-
const result = executeField(
|
|
190
|
+
const result = executeField(
|
|
191
|
+
exeContext,
|
|
192
|
+
parentTypeName,
|
|
193
|
+
sourceValue,
|
|
194
|
+
fieldNodes,
|
|
195
|
+
fieldPath
|
|
196
|
+
);
|
|
148
197
|
if (result !== void 0) {
|
|
149
198
|
results[responseName] = result;
|
|
150
199
|
if (isPromise(result)) {
|
|
@@ -159,6 +208,7 @@ function executeFields(exeContext, parentTypeName, sourceValue, path, fields) {
|
|
|
159
208
|
}
|
|
160
209
|
function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
161
210
|
const fieldName = fieldNodes[0].name.value;
|
|
211
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
162
212
|
let resolveFn;
|
|
163
213
|
let returnTypeName;
|
|
164
214
|
let returnTypeNode;
|
|
@@ -181,29 +231,104 @@ function executeField(exeContext, parentTypeName, source, fieldNodes, path) {
|
|
|
181
231
|
resolveFn = resolveFn.resolve;
|
|
182
232
|
}
|
|
183
233
|
}
|
|
234
|
+
const isDefaultResolverUsed = !resolveFn;
|
|
184
235
|
if (!resolveFn) {
|
|
185
236
|
resolveFn = exeContext.fieldResolver;
|
|
186
237
|
}
|
|
187
|
-
const info = buildResolveInfo(
|
|
238
|
+
const info = buildResolveInfo(
|
|
239
|
+
exeContext,
|
|
240
|
+
fieldName,
|
|
241
|
+
fieldNodes,
|
|
242
|
+
parentTypeName,
|
|
243
|
+
returnTypeName,
|
|
244
|
+
returnTypeNode,
|
|
245
|
+
path
|
|
246
|
+
);
|
|
188
247
|
try {
|
|
189
|
-
const args = getArgumentValues(
|
|
248
|
+
const args = getArgumentValues(
|
|
249
|
+
exeContext.resolvers,
|
|
250
|
+
fieldNodes[0],
|
|
251
|
+
exeContext.variableValues
|
|
252
|
+
);
|
|
253
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
254
|
+
invokeBeforeFieldResolveHook(info, exeContext);
|
|
255
|
+
}
|
|
190
256
|
const contextValue = exeContext.contextValue;
|
|
191
257
|
const result = resolveFn(source, args, contextValue, info);
|
|
192
258
|
let completed;
|
|
193
259
|
if (isPromise(result)) {
|
|
194
|
-
completed = result.then(
|
|
260
|
+
completed = result.then(
|
|
261
|
+
(resolved) => {
|
|
262
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
263
|
+
invokeAfterFieldResolveHook(info, exeContext, resolved);
|
|
264
|
+
}
|
|
265
|
+
return completeValue(
|
|
266
|
+
exeContext,
|
|
267
|
+
returnTypeNode,
|
|
268
|
+
fieldNodes,
|
|
269
|
+
info,
|
|
270
|
+
path,
|
|
271
|
+
resolved
|
|
272
|
+
);
|
|
273
|
+
},
|
|
274
|
+
(rawError) => {
|
|
275
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
276
|
+
invokeAfterFieldResolveHook(info, exeContext, void 0, rawError);
|
|
277
|
+
}
|
|
278
|
+
throw rawError;
|
|
279
|
+
}
|
|
280
|
+
);
|
|
195
281
|
} else {
|
|
196
|
-
|
|
282
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
283
|
+
invokeAfterFieldResolveHook(info, exeContext, result);
|
|
284
|
+
}
|
|
285
|
+
completed = completeValue(
|
|
286
|
+
exeContext,
|
|
287
|
+
returnTypeNode,
|
|
288
|
+
fieldNodes,
|
|
289
|
+
info,
|
|
290
|
+
path,
|
|
291
|
+
result
|
|
292
|
+
);
|
|
197
293
|
}
|
|
198
294
|
if (isPromise(completed)) {
|
|
199
|
-
return completed.then(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
295
|
+
return completed.then(
|
|
296
|
+
(resolved) => {
|
|
297
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
298
|
+
invokeAfterFieldCompleteHook(info, exeContext, resolved);
|
|
299
|
+
}
|
|
300
|
+
return resolved;
|
|
301
|
+
},
|
|
302
|
+
(rawError) => {
|
|
303
|
+
const error = locatedError(
|
|
304
|
+
rawError,
|
|
305
|
+
fieldNodes,
|
|
306
|
+
pathToArray(path)
|
|
307
|
+
);
|
|
308
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
309
|
+
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
310
|
+
}
|
|
311
|
+
return handleFieldError(error, returnTypeNode, exeContext);
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
316
|
+
invokeAfterFieldCompleteHook(info, exeContext, completed);
|
|
203
317
|
}
|
|
204
318
|
return completed;
|
|
205
319
|
} catch (rawError) {
|
|
206
|
-
const
|
|
320
|
+
const pathArray = pathToArray(path);
|
|
321
|
+
const error = locatedError(
|
|
322
|
+
rawError,
|
|
323
|
+
fieldNodes,
|
|
324
|
+
pathArray
|
|
325
|
+
);
|
|
326
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve) && error.path && arraysAreEqual(pathArray, error.path)) {
|
|
327
|
+
invokeAfterFieldResolveHook(info, exeContext, void 0, error);
|
|
328
|
+
}
|
|
329
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
330
|
+
invokeAfterFieldCompleteHook(info, exeContext, void 0, error);
|
|
331
|
+
}
|
|
207
332
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
208
333
|
}
|
|
209
334
|
}
|
|
@@ -233,9 +358,18 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
233
358
|
throw result;
|
|
234
359
|
}
|
|
235
360
|
if (returnTypeNode.kind === Kind.NON_NULL_TYPE) {
|
|
236
|
-
const completed = completeValue(
|
|
361
|
+
const completed = completeValue(
|
|
362
|
+
exeContext,
|
|
363
|
+
returnTypeNode.type,
|
|
364
|
+
fieldNodes,
|
|
365
|
+
info,
|
|
366
|
+
path,
|
|
367
|
+
result
|
|
368
|
+
);
|
|
237
369
|
if (completed === null) {
|
|
238
|
-
throw new Error(
|
|
370
|
+
throw new Error(
|
|
371
|
+
`Cannot return null for non-nullable field ${info.parentTypeName}.${info.fieldName}.`
|
|
372
|
+
);
|
|
239
373
|
}
|
|
240
374
|
return completed;
|
|
241
375
|
}
|
|
@@ -243,7 +377,14 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
243
377
|
return null;
|
|
244
378
|
}
|
|
245
379
|
if (returnTypeNode.kind === Kind.LIST_TYPE) {
|
|
246
|
-
return completeListValue(
|
|
380
|
+
return completeListValue(
|
|
381
|
+
exeContext,
|
|
382
|
+
returnTypeNode.type,
|
|
383
|
+
fieldNodes,
|
|
384
|
+
info,
|
|
385
|
+
path,
|
|
386
|
+
result
|
|
387
|
+
);
|
|
247
388
|
}
|
|
248
389
|
const returnTypeName = returnTypeNode.name.value;
|
|
249
390
|
let returnType = exeContext.resolvers[returnTypeName];
|
|
@@ -256,16 +397,35 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
256
397
|
if (returnType instanceof GraphQLInputObjectType) {
|
|
257
398
|
}
|
|
258
399
|
if (isUnionResolverType(returnType) || isInterfaceResolverType(returnType)) {
|
|
259
|
-
return completeAbstractValue(
|
|
400
|
+
return completeAbstractValue(
|
|
401
|
+
exeContext,
|
|
402
|
+
returnType,
|
|
403
|
+
fieldNodes,
|
|
404
|
+
info,
|
|
405
|
+
path,
|
|
406
|
+
result
|
|
407
|
+
);
|
|
260
408
|
}
|
|
261
409
|
if (typeof returnType === "object") {
|
|
262
|
-
return completeObjectValue(
|
|
410
|
+
return completeObjectValue(
|
|
411
|
+
exeContext,
|
|
412
|
+
returnTypeName,
|
|
413
|
+
fieldNodes,
|
|
414
|
+
info,
|
|
415
|
+
path,
|
|
416
|
+
result
|
|
417
|
+
);
|
|
263
418
|
}
|
|
264
|
-
invariant(
|
|
419
|
+
invariant(
|
|
420
|
+
false,
|
|
421
|
+
"Cannot complete value of unexpected output type: " + inspect(returnType)
|
|
422
|
+
);
|
|
265
423
|
}
|
|
266
424
|
function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, result) {
|
|
267
425
|
if (!isIterableObject(result)) {
|
|
268
|
-
throw new GraphQLError(
|
|
426
|
+
throw new GraphQLError(
|
|
427
|
+
`Expected Iterable, but did not find one for field "${info.parentTypeName}.${info.fieldName}".`
|
|
428
|
+
);
|
|
269
429
|
}
|
|
270
430
|
let containsPromise = false;
|
|
271
431
|
const completedResults = Array.from(result, (item, index) => {
|
|
@@ -273,20 +433,44 @@ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, r
|
|
|
273
433
|
try {
|
|
274
434
|
let completedItem;
|
|
275
435
|
if (isPromise(item)) {
|
|
276
|
-
completedItem = item.then(
|
|
436
|
+
completedItem = item.then(
|
|
437
|
+
(resolved) => completeValue(
|
|
438
|
+
exeContext,
|
|
439
|
+
returnTypeNode,
|
|
440
|
+
fieldNodes,
|
|
441
|
+
info,
|
|
442
|
+
itemPath,
|
|
443
|
+
resolved
|
|
444
|
+
)
|
|
445
|
+
);
|
|
277
446
|
} else {
|
|
278
|
-
completedItem = completeValue(
|
|
447
|
+
completedItem = completeValue(
|
|
448
|
+
exeContext,
|
|
449
|
+
returnTypeNode,
|
|
450
|
+
fieldNodes,
|
|
451
|
+
info,
|
|
452
|
+
itemPath,
|
|
453
|
+
item
|
|
454
|
+
);
|
|
279
455
|
}
|
|
280
456
|
if (isPromise(completedItem)) {
|
|
281
457
|
containsPromise = true;
|
|
282
458
|
return completedItem.then(void 0, (rawError) => {
|
|
283
|
-
const error = locatedError(
|
|
459
|
+
const error = locatedError(
|
|
460
|
+
rawError,
|
|
461
|
+
fieldNodes,
|
|
462
|
+
pathToArray(itemPath)
|
|
463
|
+
);
|
|
284
464
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
285
465
|
});
|
|
286
466
|
}
|
|
287
467
|
return completedItem;
|
|
288
468
|
} catch (rawError) {
|
|
289
|
-
const error = locatedError(
|
|
469
|
+
const error = locatedError(
|
|
470
|
+
rawError,
|
|
471
|
+
fieldNodes,
|
|
472
|
+
pathToArray(itemPath)
|
|
473
|
+
);
|
|
290
474
|
return handleFieldError(error, returnTypeNode, exeContext);
|
|
291
475
|
}
|
|
292
476
|
});
|
|
@@ -295,7 +479,9 @@ function completeListValue(exeContext, returnTypeNode, fieldNodes, info, path, r
|
|
|
295
479
|
function completeLeafValue(returnType, result) {
|
|
296
480
|
const serializedResult = returnType.serialize(result);
|
|
297
481
|
if (serializedResult === void 0) {
|
|
298
|
-
throw new Error(
|
|
482
|
+
throw new Error(
|
|
483
|
+
`Expected a value of type "${inspect(returnType)}" but received: ${inspect(result)}`
|
|
484
|
+
);
|
|
299
485
|
}
|
|
300
486
|
return serializedResult;
|
|
301
487
|
}
|
|
@@ -305,19 +491,43 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
305
491
|
const contextValue = exeContext.contextValue;
|
|
306
492
|
const runtimeTypeName = resolveTypeFn(result, contextValue, info);
|
|
307
493
|
if (isPromise(runtimeTypeName)) {
|
|
308
|
-
return runtimeTypeName.then(
|
|
494
|
+
return runtimeTypeName.then(
|
|
495
|
+
(resolvedRuntimeTypeName) => completeObjectValue(
|
|
496
|
+
exeContext,
|
|
497
|
+
ensureValidRuntimeType(resolvedRuntimeTypeName, exeContext),
|
|
498
|
+
fieldNodes,
|
|
499
|
+
info,
|
|
500
|
+
path,
|
|
501
|
+
result
|
|
502
|
+
)
|
|
503
|
+
);
|
|
309
504
|
}
|
|
310
|
-
return completeObjectValue(
|
|
505
|
+
return completeObjectValue(
|
|
506
|
+
exeContext,
|
|
507
|
+
ensureValidRuntimeType(runtimeTypeName, exeContext),
|
|
508
|
+
fieldNodes,
|
|
509
|
+
info,
|
|
510
|
+
path,
|
|
511
|
+
result
|
|
512
|
+
);
|
|
311
513
|
}
|
|
312
514
|
function ensureValidRuntimeType(runtimeTypeName, exeContext) {
|
|
313
515
|
if (typeof runtimeTypeName !== "string") {
|
|
314
|
-
throw new GraphQLError(
|
|
516
|
+
throw new GraphQLError(
|
|
517
|
+
`Could not determine runtime type for abstract type ${runtimeTypeName}`
|
|
518
|
+
);
|
|
315
519
|
}
|
|
316
520
|
const runtimeType = exeContext.resolvers[runtimeTypeName];
|
|
317
521
|
if (!runtimeType) {
|
|
318
|
-
throw new GraphQLError(
|
|
522
|
+
throw new GraphQLError(
|
|
523
|
+
`Type "${runtimeTypeName}" does not exist inside the schema.`
|
|
524
|
+
);
|
|
319
525
|
} else if (runtimeType instanceof GraphQLScalarType || runtimeType instanceof GraphQLEnumType || runtimeType instanceof GraphQLInputObjectType || runtimeType.__resolveType) {
|
|
320
|
-
throw new GraphQLError(
|
|
526
|
+
throw new GraphQLError(
|
|
527
|
+
`Given runtime object "${getRuntimeTypeInstanceName(
|
|
528
|
+
runtimeType
|
|
529
|
+
)}" type is not a possible type for "${runtimeTypeName}".`
|
|
530
|
+
);
|
|
321
531
|
} else {
|
|
322
532
|
return runtimeTypeName;
|
|
323
533
|
}
|
|
@@ -338,7 +548,11 @@ function getRuntimeTypeInstanceName(runtimeType) {
|
|
|
338
548
|
}
|
|
339
549
|
}
|
|
340
550
|
function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
|
|
341
|
-
const subFieldNodes = collectSubfields(
|
|
551
|
+
const subFieldNodes = collectSubfields(
|
|
552
|
+
exeContext,
|
|
553
|
+
returnTypeName,
|
|
554
|
+
fieldNodes
|
|
555
|
+
);
|
|
342
556
|
return executeFields(exeContext, returnTypeName, result, path, subFieldNodes);
|
|
343
557
|
}
|
|
344
558
|
function collectSubfields(exeContext, returnTypeName, fieldNodes) {
|
|
@@ -346,11 +560,103 @@ function collectSubfields(exeContext, returnTypeName, fieldNodes) {
|
|
|
346
560
|
const visitedFragmentNames = /* @__PURE__ */ new Set();
|
|
347
561
|
for (const node of fieldNodes) {
|
|
348
562
|
if (node.selectionSet) {
|
|
349
|
-
subFieldNodes = collectFields(
|
|
563
|
+
subFieldNodes = collectFields(
|
|
564
|
+
exeContext.resolvers,
|
|
565
|
+
exeContext.fragments,
|
|
566
|
+
exeContext.variableValues,
|
|
567
|
+
returnTypeName,
|
|
568
|
+
node.selectionSet,
|
|
569
|
+
subFieldNodes,
|
|
570
|
+
visitedFragmentNames
|
|
571
|
+
);
|
|
350
572
|
}
|
|
351
573
|
}
|
|
352
574
|
return subFieldNodes;
|
|
353
575
|
}
|
|
576
|
+
function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
577
|
+
var _a;
|
|
578
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeFieldResolve;
|
|
579
|
+
if (!hook) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
executeSafe(
|
|
583
|
+
() => hook({
|
|
584
|
+
resolveInfo,
|
|
585
|
+
context: exeContext.contextValue
|
|
586
|
+
}),
|
|
587
|
+
(_, rawError) => {
|
|
588
|
+
const error = toGraphQLError(
|
|
589
|
+
rawError,
|
|
590
|
+
resolveInfo.path,
|
|
591
|
+
"Unexpected error in beforeFieldResolve hook"
|
|
592
|
+
);
|
|
593
|
+
exeContext.errors.push(error);
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
function invokeAfterFieldResolveHook(resolveInfo, exeContext, result, error) {
|
|
598
|
+
var _a;
|
|
599
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldResolve;
|
|
600
|
+
if (!hook) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
executeSafe(
|
|
604
|
+
() => hook({
|
|
605
|
+
resolveInfo,
|
|
606
|
+
context: exeContext.contextValue,
|
|
607
|
+
result,
|
|
608
|
+
error
|
|
609
|
+
}),
|
|
610
|
+
(_, rawError) => {
|
|
611
|
+
const error2 = toGraphQLError(
|
|
612
|
+
rawError,
|
|
613
|
+
resolveInfo.path,
|
|
614
|
+
"Unexpected error in afterFieldResolve hook"
|
|
615
|
+
);
|
|
616
|
+
exeContext.errors.push(error2);
|
|
617
|
+
}
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
function invokeAfterFieldCompleteHook(resolveInfo, exeContext, result, error) {
|
|
621
|
+
var _a;
|
|
622
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldComplete;
|
|
623
|
+
if (!hook) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
executeSafe(
|
|
627
|
+
() => hook({
|
|
628
|
+
resolveInfo,
|
|
629
|
+
context: exeContext.contextValue,
|
|
630
|
+
result,
|
|
631
|
+
error
|
|
632
|
+
}),
|
|
633
|
+
(_, rawError) => {
|
|
634
|
+
const error2 = toGraphQLError(
|
|
635
|
+
rawError,
|
|
636
|
+
resolveInfo.path,
|
|
637
|
+
"Unexpected error in afterFieldComplete hook"
|
|
638
|
+
);
|
|
639
|
+
exeContext.errors.push(error2);
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
function executeSafe(execute, onComplete) {
|
|
644
|
+
let error;
|
|
645
|
+
let result;
|
|
646
|
+
try {
|
|
647
|
+
result = execute();
|
|
648
|
+
} catch (e) {
|
|
649
|
+
error = e;
|
|
650
|
+
} finally {
|
|
651
|
+
onComplete(result, error);
|
|
652
|
+
return result;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function toGraphQLError(originalError, path, prependMessage) {
|
|
656
|
+
const originalMessage = originalError instanceof Error ? originalError.message : inspect(originalError);
|
|
657
|
+
const error = new Error(`${prependMessage}: ${originalMessage}`);
|
|
658
|
+
return locatedError(error, void 0, pathToArray(path));
|
|
659
|
+
}
|
|
354
660
|
var defaultTypeResolver = function(value) {
|
|
355
661
|
if (isObjectLike(value) && typeof value.__typename === "string") {
|
|
356
662
|
return value.__typename;
|
|
@@ -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;
|
|
@@ -57,7 +58,9 @@ function extractImplicitTypes(document, getTypeByName) {
|
|
|
57
58
|
if (!implementedBy[node.name.value]) {
|
|
58
59
|
implementedBy[node.name.value] = [];
|
|
59
60
|
}
|
|
60
|
-
implementedBy[node.name.value].push(
|
|
61
|
+
implementedBy[node.name.value].push(
|
|
62
|
+
astNode.name.value
|
|
63
|
+
);
|
|
61
64
|
});
|
|
62
65
|
result[astNode.name.value] = {};
|
|
63
66
|
}
|
|
@@ -46,7 +46,9 @@ function extractImplicitTypes(document, getTypeByName) {
|
|
|
46
46
|
if (!implementedBy[node.name.value]) {
|
|
47
47
|
implementedBy[node.name.value] = [];
|
|
48
48
|
}
|
|
49
|
-
implementedBy[node.name.value].push(
|
|
49
|
+
implementedBy[node.name.value].push(
|
|
50
|
+
astNode.name.value
|
|
51
|
+
);
|
|
50
52
|
});
|
|
51
53
|
result[astNode.name.value] = {};
|
|
52
54
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ResolveInfo } from "../types";
|
|
2
|
+
interface BaseExecuteHookArgs {
|
|
3
|
+
context: unknown;
|
|
4
|
+
}
|
|
5
|
+
interface BaseExecuteFieldHookArgs extends BaseExecuteHookArgs {
|
|
6
|
+
resolveInfo: ResolveInfo;
|
|
7
|
+
}
|
|
8
|
+
export interface BeforeFieldResolveHookArgs extends BaseExecuteFieldHookArgs {
|
|
9
|
+
}
|
|
10
|
+
export interface AfterFieldResolveHookArgs extends BaseExecuteFieldHookArgs {
|
|
11
|
+
result?: unknown;
|
|
12
|
+
error?: any;
|
|
13
|
+
}
|
|
14
|
+
export interface AfterFieldCompleteHookArgs extends BaseExecuteFieldHookArgs {
|
|
15
|
+
result?: unknown;
|
|
16
|
+
error?: any;
|
|
17
|
+
}
|
|
18
|
+
export interface BeforeFieldResolveHook {
|
|
19
|
+
(args: BeforeFieldResolveHookArgs): void;
|
|
20
|
+
}
|
|
21
|
+
export interface AfterFieldResolveHook {
|
|
22
|
+
(args: AfterFieldResolveHookArgs): void;
|
|
23
|
+
}
|
|
24
|
+
export interface AfterFieldCompleteHook {
|
|
25
|
+
(args: AfterFieldCompleteHookArgs): void;
|
|
26
|
+
}
|
|
27
|
+
export interface ExecutionHooks {
|
|
28
|
+
beforeFieldResolve?: BeforeFieldResolveHook;
|
|
29
|
+
afterFieldResolve?: AfterFieldResolveHook;
|
|
30
|
+
afterFieldComplete?: AfterFieldCompleteHook;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,UAAU,mBAAmB;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,wBAAyB,SAAQ,mBAAmB;IAC5D,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;CAAG;AAE/E,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;IAC1E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,sBAAsB;IACrC,CAAC,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,sBAAsB;IACrC,CAAC,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,cAAc;IAC7B,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;IAC1C,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;CAC7C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
File without changes
|
package/lib/index.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export { specifiedScalars } from "./values";
|
|
|
9
9
|
export { annotateDocumentGraphQLTransform } from "./transforms/annotateDocumentGraphQLTransform";
|
|
10
10
|
export type { PromiseOrValue } from "./jsutils/PromiseOrValue";
|
|
11
11
|
export type { NameNode, DocumentNode, OperationDefinitionNode, VariableDefinitionNode, VariableNode, SelectionSetNode, FieldNode, ArgumentNode, FragmentSpreadNode, InlineFragmentNode, FragmentDefinitionNode, IntValueNode, FloatValueNode, StringValueNode, BooleanValueNode, NullValueNode, EnumValueNode, ListValueNode, ObjectValueNode, ObjectFieldNode, DirectiveNode, NamedTypeNode, ListTypeNode, NonNullTypeNode, SchemaDefinitionNode, OperationTypeDefinitionNode, ScalarTypeDefinitionNode, ObjectTypeDefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, UnionTypeDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, InputObjectTypeDefinitionNode, DirectiveDefinitionNode, SchemaExtensionNode, ScalarTypeExtensionNode, ObjectTypeExtensionNode, InterfaceTypeExtensionNode, UnionTypeExtensionNode, EnumTypeExtensionNode, InputObjectTypeExtensionNode, } from "./ast/TypedAST";
|
|
12
|
+
export { BeforeFieldResolveHookArgs, AfterFieldResolveHookArgs, AfterFieldCompleteHookArgs, BeforeFieldResolveHook, AfterFieldResolveHook, AfterFieldCompleteHook, ExecutionHooks, } from "./hooks/types";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|