@graphitation/supermassive 3.5.1 → 3.5.3
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 +18 -2
- package/lib/__testUtils__/execute.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +141 -5
- package/lib/executeWithoutSchema.js.map +2 -2
- package/lib/executeWithoutSchema.mjs +141 -5
- package/lib/executeWithoutSchema.mjs.map +2 -2
- package/lib/hooks/types.d.ts +23 -1
- package/lib/hooks/types.d.ts.map +1 -1
- package/lib/hooks/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -185,6 +185,10 @@ function executeOperation(exeContext) {
|
|
|
185
185
|
);
|
|
186
186
|
const path = void 0;
|
|
187
187
|
let result;
|
|
188
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
189
|
+
if (hooks == null ? void 0 : hooks.beforeOperationExecute) {
|
|
190
|
+
invokeBeforeOperationExecuteHook(exeContext);
|
|
191
|
+
}
|
|
188
192
|
switch (operation.operation) {
|
|
189
193
|
case "query":
|
|
190
194
|
result = executeFields(
|
|
@@ -242,6 +246,7 @@ function executeOperation(exeContext) {
|
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
248
|
function buildResponse(exeContext, data) {
|
|
249
|
+
var _a, _b;
|
|
245
250
|
if (isPromise(data)) {
|
|
246
251
|
return data.then(
|
|
247
252
|
(resolved) => buildResponse(exeContext, resolved),
|
|
@@ -251,6 +256,7 @@ function buildResponse(exeContext, data) {
|
|
|
251
256
|
}
|
|
252
257
|
);
|
|
253
258
|
}
|
|
259
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
254
260
|
try {
|
|
255
261
|
const initialResult = exeContext.errors.length === 0 ? { data } : { errors: exeContext.errors, data };
|
|
256
262
|
if (exeContext.subsequentPayloads.size > 0) {
|
|
@@ -261,6 +267,12 @@ function buildResponse(exeContext, data) {
|
|
|
261
267
|
subsequentResults: yieldSubsequentPayloads(exeContext)
|
|
262
268
|
};
|
|
263
269
|
} else {
|
|
270
|
+
if (hooks == null ? void 0 : hooks.afterBuildResponse) {
|
|
271
|
+
invokeAfterBuildResponseHook(exeContext, initialResult);
|
|
272
|
+
if (exeContext.errors.length > ((_b = (_a = initialResult.errors) == null ? void 0 : _a.length) != null ? _b : 0)) {
|
|
273
|
+
initialResult.errors = exeContext.errors;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
264
276
|
return initialResult;
|
|
265
277
|
}
|
|
266
278
|
} catch (error) {
|
|
@@ -404,6 +416,9 @@ function executeSubscriptionImpl(exeContext) {
|
|
|
404
416
|
const rootTypeName = getOperationRootTypeName(operation);
|
|
405
417
|
const { groupedFieldSet } = collectFields(exeContext, rootTypeName);
|
|
406
418
|
const firstRootField = groupedFieldSet.entries().next().value;
|
|
419
|
+
if (firstRootField === void 0) {
|
|
420
|
+
throw locatedError("Must have at least one root field.", []);
|
|
421
|
+
}
|
|
407
422
|
const [responseName, fieldGroup] = firstRootField;
|
|
408
423
|
const fieldName = fieldGroup[0].name.value;
|
|
409
424
|
const fieldDef = Definitions.getField(
|
|
@@ -432,17 +447,63 @@ function executeSubscriptionImpl(exeContext) {
|
|
|
432
447
|
typeNameFromReference(returnTypeRef),
|
|
433
448
|
path
|
|
434
449
|
);
|
|
450
|
+
const isDefaultResolverUsed = resolveFn === exeContext.subscribeFieldResolver;
|
|
451
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
452
|
+
let hookContext = void 0;
|
|
435
453
|
try {
|
|
436
454
|
const args = getArgumentValues(exeContext, fieldDef, fieldGroup[0]);
|
|
437
455
|
const contextValue = exeContext.contextValue;
|
|
456
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
457
|
+
hookContext = invokeBeforeFieldResolveHook(info, exeContext);
|
|
458
|
+
}
|
|
438
459
|
const result = resolveFn(rootValue, args, contextValue, info);
|
|
439
460
|
if (isPromise(result)) {
|
|
440
|
-
return result.then(assertEventStream).then(
|
|
441
|
-
|
|
442
|
-
|
|
461
|
+
return result.then(assertEventStream).then(
|
|
462
|
+
(resolved) => {
|
|
463
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
464
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
465
|
+
info,
|
|
466
|
+
exeContext,
|
|
467
|
+
hookContext,
|
|
468
|
+
resolved
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
return resolved;
|
|
472
|
+
},
|
|
473
|
+
(error) => {
|
|
474
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
475
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
476
|
+
info,
|
|
477
|
+
exeContext,
|
|
478
|
+
hookContext,
|
|
479
|
+
void 0,
|
|
480
|
+
error
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
const stream = assertEventStream(result);
|
|
488
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
489
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
490
|
+
info,
|
|
491
|
+
exeContext,
|
|
492
|
+
hookContext,
|
|
493
|
+
stream
|
|
494
|
+
);
|
|
443
495
|
}
|
|
444
|
-
return
|
|
496
|
+
return stream;
|
|
445
497
|
} catch (error) {
|
|
498
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
499
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
500
|
+
info,
|
|
501
|
+
exeContext,
|
|
502
|
+
hookContext,
|
|
503
|
+
void 0,
|
|
504
|
+
error
|
|
505
|
+
);
|
|
506
|
+
}
|
|
446
507
|
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
447
508
|
}
|
|
448
509
|
}
|
|
@@ -478,6 +539,10 @@ function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, pa
|
|
|
478
539
|
exeContext,
|
|
479
540
|
payload
|
|
480
541
|
);
|
|
542
|
+
const hooks = exeContext == null ? void 0 : exeContext.fieldExecutionHooks;
|
|
543
|
+
if (hooks == null ? void 0 : hooks.beforeSubscriptionEventEmit) {
|
|
544
|
+
invokeBeforeSubscriptionEventEmitHook(perEventContext, payload);
|
|
545
|
+
}
|
|
481
546
|
try {
|
|
482
547
|
const data = executeFields(
|
|
483
548
|
exeContext,
|
|
@@ -1207,6 +1272,77 @@ function invokeAfterFieldCompleteHook(resolveInfo, exeContext, hookContext, resu
|
|
|
1207
1272
|
}
|
|
1208
1273
|
);
|
|
1209
1274
|
}
|
|
1275
|
+
function invokeBeforeOperationExecuteHook(exeContext) {
|
|
1276
|
+
var _a;
|
|
1277
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeOperationExecute;
|
|
1278
|
+
if (!hook) {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
return executeSafe(
|
|
1282
|
+
() => hook({
|
|
1283
|
+
context: exeContext.contextValue,
|
|
1284
|
+
operation: exeContext.operation
|
|
1285
|
+
}),
|
|
1286
|
+
(_, rawError) => {
|
|
1287
|
+
if (rawError) {
|
|
1288
|
+
const error = toGraphQLError(
|
|
1289
|
+
rawError,
|
|
1290
|
+
void 0,
|
|
1291
|
+
"Unexpected error in beforeOperationExecute hook"
|
|
1292
|
+
);
|
|
1293
|
+
exeContext.errors.push(error);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
function invokeBeforeSubscriptionEventEmitHook(exeContext, eventPayload) {
|
|
1299
|
+
var _a;
|
|
1300
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeSubscriptionEventEmit;
|
|
1301
|
+
if (!hook) {
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
return executeSafe(
|
|
1305
|
+
() => hook({
|
|
1306
|
+
context: exeContext.contextValue,
|
|
1307
|
+
operation: exeContext.operation,
|
|
1308
|
+
eventPayload
|
|
1309
|
+
}),
|
|
1310
|
+
(_, rawError) => {
|
|
1311
|
+
if (rawError) {
|
|
1312
|
+
const error = toGraphQLError(
|
|
1313
|
+
rawError,
|
|
1314
|
+
void 0,
|
|
1315
|
+
"Unexpected error in beforeSubscriptionEventEmit hook"
|
|
1316
|
+
);
|
|
1317
|
+
exeContext.errors.push(error);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
function invokeAfterBuildResponseHook(exeContext, result) {
|
|
1323
|
+
var _a;
|
|
1324
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterBuildResponse;
|
|
1325
|
+
if (!hook) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
return executeSafe(
|
|
1329
|
+
() => hook({
|
|
1330
|
+
context: exeContext.contextValue,
|
|
1331
|
+
operation: exeContext.operation,
|
|
1332
|
+
result
|
|
1333
|
+
}),
|
|
1334
|
+
(_, rawError) => {
|
|
1335
|
+
if (rawError) {
|
|
1336
|
+
const error = toGraphQLError(
|
|
1337
|
+
rawError,
|
|
1338
|
+
void 0,
|
|
1339
|
+
"Unexpected error in afterBuildResponse hook"
|
|
1340
|
+
);
|
|
1341
|
+
exeContext.errors.push(error);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1210
1346
|
function executeSafe(execute, onComplete) {
|
|
1211
1347
|
let error;
|
|
1212
1348
|
let result;
|
|
@@ -1222,7 +1358,7 @@ function executeSafe(execute, onComplete) {
|
|
|
1222
1358
|
function toGraphQLError(originalError, path, prependMessage) {
|
|
1223
1359
|
const originalMessage = originalError instanceof Error ? originalError.message : inspect(originalError);
|
|
1224
1360
|
const error = new Error(`${prependMessage}: ${originalMessage}`);
|
|
1225
|
-
return locatedError(error, void 0, pathToArray(path));
|
|
1361
|
+
return locatedError(error, void 0, path ? pathToArray(path) : void 0);
|
|
1226
1362
|
}
|
|
1227
1363
|
var defaultTypeResolver = function(value) {
|
|
1228
1364
|
if (isObjectLike(value) && typeof value.__typename === "string") {
|