@graphitation/supermassive 3.5.1 → 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 +10 -2
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +138 -5
- package/lib/executeWithoutSchema.js.map +2 -2
- package/lib/executeWithoutSchema.mjs +138 -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 +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
|
+
);
|
|
483
|
+
}
|
|
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
|
+
);
|
|
443
492
|
}
|
|
444
|
-
return
|
|
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,
|
|
@@ -1207,6 +1269,77 @@ function invokeAfterFieldCompleteHook(resolveInfo, exeContext, hookContext, resu
|
|
|
1207
1269
|
}
|
|
1208
1270
|
);
|
|
1209
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
|
+
}
|
|
1210
1343
|
function executeSafe(execute, onComplete) {
|
|
1211
1344
|
let error;
|
|
1212
1345
|
let result;
|
|
@@ -1222,7 +1355,7 @@ function executeSafe(execute, onComplete) {
|
|
|
1222
1355
|
function toGraphQLError(originalError, path, prependMessage) {
|
|
1223
1356
|
const originalMessage = originalError instanceof Error ? originalError.message : inspect(originalError);
|
|
1224
1357
|
const error = new Error(`${prependMessage}: ${originalMessage}`);
|
|
1225
|
-
return locatedError(error, void 0, pathToArray(path));
|
|
1358
|
+
return locatedError(error, void 0, path ? pathToArray(path) : void 0);
|
|
1226
1359
|
}
|
|
1227
1360
|
var defaultTypeResolver = function(value) {
|
|
1228
1361
|
if (isObjectLike(value) && typeof value.__typename === "string") {
|