@graphitation/supermassive 3.5.0 → 3.5.2
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/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +186 -29
- package/lib/executeWithoutSchema.js.map +2 -2
- package/lib/executeWithoutSchema.mjs +186 -29
- package/lib/executeWithoutSchema.mjs.map +2 -2
- package/lib/hooks/types.d.ts +25 -8
- package/lib/hooks/types.d.ts.map +1 -1
- package/lib/hooks/types.js.map +1 -1
- package/lib/jsutils/printPathArray.d.ts.map +1 -1
- package/lib/jsutils/printPathArray.js +12 -3
- package/lib/jsutils/printPathArray.js.map +2 -2
- package/lib/jsutils/printPathArray.mjs +12 -3
- package/lib/jsutils/printPathArray.mjs.map +2 -2
- package/package.json +1 -1
|
@@ -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) {
|
|
@@ -432,17 +444,63 @@ function executeSubscriptionImpl(exeContext) {
|
|
|
432
444
|
typeNameFromReference(returnTypeRef),
|
|
433
445
|
path
|
|
434
446
|
);
|
|
447
|
+
const isDefaultResolverUsed = resolveFn === exeContext.subscribeFieldResolver;
|
|
448
|
+
const hooks = exeContext.fieldExecutionHooks;
|
|
449
|
+
let hookContext = void 0;
|
|
435
450
|
try {
|
|
436
451
|
const args = getArgumentValues(exeContext, fieldDef, fieldGroup[0]);
|
|
437
452
|
const contextValue = exeContext.contextValue;
|
|
453
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldResolve)) {
|
|
454
|
+
hookContext = invokeBeforeFieldResolveHook(info, exeContext);
|
|
455
|
+
}
|
|
438
456
|
const result = resolveFn(rootValue, args, contextValue, info);
|
|
439
457
|
if (isPromise(result)) {
|
|
440
|
-
return result.then(assertEventStream).then(
|
|
441
|
-
|
|
442
|
-
|
|
458
|
+
return result.then(assertEventStream).then(
|
|
459
|
+
(resolved) => {
|
|
460
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
461
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
462
|
+
info,
|
|
463
|
+
exeContext,
|
|
464
|
+
hookContext,
|
|
465
|
+
resolved
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
return resolved;
|
|
469
|
+
},
|
|
470
|
+
(error) => {
|
|
471
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
472
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
473
|
+
info,
|
|
474
|
+
exeContext,
|
|
475
|
+
hookContext,
|
|
476
|
+
void 0,
|
|
477
|
+
error
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
481
|
+
}
|
|
482
|
+
);
|
|
443
483
|
}
|
|
444
|
-
|
|
484
|
+
const stream = assertEventStream(result);
|
|
485
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
486
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
487
|
+
info,
|
|
488
|
+
exeContext,
|
|
489
|
+
hookContext,
|
|
490
|
+
stream
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
return stream;
|
|
445
494
|
} catch (error) {
|
|
495
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
496
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
497
|
+
info,
|
|
498
|
+
exeContext,
|
|
499
|
+
hookContext,
|
|
500
|
+
void 0,
|
|
501
|
+
error
|
|
502
|
+
);
|
|
503
|
+
}
|
|
446
504
|
throw locatedError(error, fieldGroup, pathToArray(path));
|
|
447
505
|
}
|
|
448
506
|
}
|
|
@@ -478,6 +536,10 @@ function mapResultOrEventStreamOrPromise(resultOrStreamOrPromise, exeContext, pa
|
|
|
478
536
|
exeContext,
|
|
479
537
|
payload
|
|
480
538
|
);
|
|
539
|
+
const hooks = exeContext == null ? void 0 : exeContext.fieldExecutionHooks;
|
|
540
|
+
if (hooks == null ? void 0 : hooks.beforeSubscriptionEventEmit) {
|
|
541
|
+
invokeBeforeSubscriptionEventEmitHook(perEventContext, payload);
|
|
542
|
+
}
|
|
481
543
|
try {
|
|
482
544
|
const data = executeFields(
|
|
483
545
|
exeContext,
|
|
@@ -536,7 +598,7 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
536
598
|
typeNameFromReference(returnTypeRef),
|
|
537
599
|
path
|
|
538
600
|
);
|
|
539
|
-
const isDefaultResolverUsed = resolveFn === exeContext.fieldResolver;
|
|
601
|
+
const isDefaultResolverUsed = resolveFn === exeContext.fieldResolver || fieldName === "__typename";
|
|
540
602
|
const hooks = exeContext.fieldExecutionHooks;
|
|
541
603
|
let hookContext = void 0;
|
|
542
604
|
try {
|
|
@@ -546,28 +608,50 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
546
608
|
hookContext = invokeBeforeFieldResolveHook(info, exeContext);
|
|
547
609
|
}
|
|
548
610
|
const result = resolveFn(source, args, contextValue, info);
|
|
549
|
-
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
550
|
-
hookContext = invokeAfterFieldResolveHook(
|
|
551
|
-
info,
|
|
552
|
-
exeContext,
|
|
553
|
-
hookContext,
|
|
554
|
-
result
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
611
|
let completed;
|
|
558
612
|
if (isPromise(result)) {
|
|
559
|
-
completed = result.then(
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
613
|
+
completed = result.then(
|
|
614
|
+
(resolved) => {
|
|
615
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
616
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
617
|
+
info,
|
|
618
|
+
exeContext,
|
|
619
|
+
hookContext,
|
|
620
|
+
resolved
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
return completeValue(
|
|
624
|
+
exeContext,
|
|
625
|
+
returnTypeRef,
|
|
626
|
+
fieldGroup,
|
|
627
|
+
info,
|
|
628
|
+
path,
|
|
629
|
+
resolved,
|
|
630
|
+
incrementalDataRecord
|
|
631
|
+
);
|
|
632
|
+
},
|
|
633
|
+
(rawError) => {
|
|
634
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
635
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
636
|
+
info,
|
|
637
|
+
exeContext,
|
|
638
|
+
hookContext,
|
|
639
|
+
void 0,
|
|
640
|
+
rawError
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
throw rawError;
|
|
644
|
+
}
|
|
645
|
+
);
|
|
646
|
+
} else {
|
|
647
|
+
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldResolve)) {
|
|
648
|
+
hookContext = invokeAfterFieldResolveHook(
|
|
564
649
|
info,
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
650
|
+
exeContext,
|
|
651
|
+
hookContext,
|
|
652
|
+
result
|
|
568
653
|
);
|
|
569
|
-
}
|
|
570
|
-
} else {
|
|
654
|
+
}
|
|
571
655
|
completed = completeValue(
|
|
572
656
|
exeContext,
|
|
573
657
|
returnTypeRef,
|
|
@@ -626,7 +710,8 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
|
|
|
626
710
|
info,
|
|
627
711
|
exeContext,
|
|
628
712
|
hookContext,
|
|
629
|
-
void 0
|
|
713
|
+
void 0,
|
|
714
|
+
error
|
|
630
715
|
);
|
|
631
716
|
}
|
|
632
717
|
if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldComplete)) {
|
|
@@ -1132,7 +1217,7 @@ function invokeBeforeFieldResolveHook(resolveInfo, exeContext) {
|
|
|
1132
1217
|
}
|
|
1133
1218
|
);
|
|
1134
1219
|
}
|
|
1135
|
-
function invokeAfterFieldResolveHook(resolveInfo, exeContext, hookContext, result) {
|
|
1220
|
+
function invokeAfterFieldResolveHook(resolveInfo, exeContext, hookContext, result, error) {
|
|
1136
1221
|
var _a;
|
|
1137
1222
|
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterFieldResolve;
|
|
1138
1223
|
if (!hook) {
|
|
@@ -1143,16 +1228,17 @@ function invokeAfterFieldResolveHook(resolveInfo, exeContext, hookContext, resul
|
|
|
1143
1228
|
resolveInfo,
|
|
1144
1229
|
context: exeContext.contextValue,
|
|
1145
1230
|
hookContext,
|
|
1146
|
-
result
|
|
1231
|
+
result,
|
|
1232
|
+
error
|
|
1147
1233
|
}),
|
|
1148
1234
|
(_, rawError) => {
|
|
1149
1235
|
if (rawError) {
|
|
1150
|
-
const
|
|
1236
|
+
const error2 = toGraphQLError(
|
|
1151
1237
|
rawError,
|
|
1152
1238
|
resolveInfo.path,
|
|
1153
1239
|
"Unexpected error in afterFieldResolve hook"
|
|
1154
1240
|
);
|
|
1155
|
-
exeContext.errors.push(
|
|
1241
|
+
exeContext.errors.push(error2);
|
|
1156
1242
|
}
|
|
1157
1243
|
}
|
|
1158
1244
|
);
|
|
@@ -1183,6 +1269,77 @@ function invokeAfterFieldCompleteHook(resolveInfo, exeContext, hookContext, resu
|
|
|
1183
1269
|
}
|
|
1184
1270
|
);
|
|
1185
1271
|
}
|
|
1272
|
+
function invokeBeforeOperationExecuteHook(exeContext) {
|
|
1273
|
+
var _a;
|
|
1274
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeOperationExecute;
|
|
1275
|
+
if (!hook) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
return executeSafe(
|
|
1279
|
+
() => hook({
|
|
1280
|
+
context: exeContext.contextValue,
|
|
1281
|
+
operation: exeContext.operation
|
|
1282
|
+
}),
|
|
1283
|
+
(_, rawError) => {
|
|
1284
|
+
if (rawError) {
|
|
1285
|
+
const error = toGraphQLError(
|
|
1286
|
+
rawError,
|
|
1287
|
+
void 0,
|
|
1288
|
+
"Unexpected error in beforeOperationExecute hook"
|
|
1289
|
+
);
|
|
1290
|
+
exeContext.errors.push(error);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
function invokeBeforeSubscriptionEventEmitHook(exeContext, eventPayload) {
|
|
1296
|
+
var _a;
|
|
1297
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.beforeSubscriptionEventEmit;
|
|
1298
|
+
if (!hook) {
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
return executeSafe(
|
|
1302
|
+
() => hook({
|
|
1303
|
+
context: exeContext.contextValue,
|
|
1304
|
+
operation: exeContext.operation,
|
|
1305
|
+
eventPayload
|
|
1306
|
+
}),
|
|
1307
|
+
(_, rawError) => {
|
|
1308
|
+
if (rawError) {
|
|
1309
|
+
const error = toGraphQLError(
|
|
1310
|
+
rawError,
|
|
1311
|
+
void 0,
|
|
1312
|
+
"Unexpected error in beforeSubscriptionEventEmit hook"
|
|
1313
|
+
);
|
|
1314
|
+
exeContext.errors.push(error);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
function invokeAfterBuildResponseHook(exeContext, result) {
|
|
1320
|
+
var _a;
|
|
1321
|
+
const hook = (_a = exeContext.fieldExecutionHooks) == null ? void 0 : _a.afterBuildResponse;
|
|
1322
|
+
if (!hook) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
return executeSafe(
|
|
1326
|
+
() => hook({
|
|
1327
|
+
context: exeContext.contextValue,
|
|
1328
|
+
operation: exeContext.operation,
|
|
1329
|
+
result
|
|
1330
|
+
}),
|
|
1331
|
+
(_, rawError) => {
|
|
1332
|
+
if (rawError) {
|
|
1333
|
+
const error = toGraphQLError(
|
|
1334
|
+
rawError,
|
|
1335
|
+
void 0,
|
|
1336
|
+
"Unexpected error in afterBuildResponse hook"
|
|
1337
|
+
);
|
|
1338
|
+
exeContext.errors.push(error);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1186
1343
|
function executeSafe(execute, onComplete) {
|
|
1187
1344
|
let error;
|
|
1188
1345
|
let result;
|
|
@@ -1198,7 +1355,7 @@ function executeSafe(execute, onComplete) {
|
|
|
1198
1355
|
function toGraphQLError(originalError, path, prependMessage) {
|
|
1199
1356
|
const originalMessage = originalError instanceof Error ? originalError.message : inspect(originalError);
|
|
1200
1357
|
const error = new Error(`${prependMessage}: ${originalMessage}`);
|
|
1201
|
-
return locatedError(error, void 0, pathToArray(path));
|
|
1358
|
+
return locatedError(error, void 0, path ? pathToArray(path) : void 0);
|
|
1202
1359
|
}
|
|
1203
1360
|
var defaultTypeResolver = function(value) {
|
|
1204
1361
|
if (isObjectLike(value) && typeof value.__typename === "string") {
|