@graphitation/supermassive 3.8.0-alpha.2 → 3.8.0-alpha.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.
@@ -276,10 +276,16 @@ function buildResponse(exeContext, data) {
276
276
  };
277
277
  } else {
278
278
  if (hooks == null ? void 0 : hooks.afterBuildResponse) {
279
- invokeAfterBuildResponseHook(exeContext, initialResult);
279
+ const hookResult = invokeAfterBuildResponseHook(
280
+ exeContext,
281
+ initialResult
282
+ );
280
283
  if (exeContext.errors.length > ((_b = (_a = initialResult.errors) == null ? void 0 : _a.length) != null ? _b : 0)) {
281
284
  initialResult.errors = exeContext.errors;
282
285
  }
286
+ if (hookResult instanceof GraphQLError) {
287
+ return { errors: initialResult.errors };
288
+ }
283
289
  }
284
290
  return initialResult;
285
291
  }
@@ -468,23 +474,18 @@ function executeSubscriptionImpl(exeContext) {
468
474
  const hooks = exeContext.fieldExecutionHooks;
469
475
  let hookContext = void 0;
470
476
  try {
471
- const args = getArgumentValues(exeContext, fieldDef, fieldGroup[0]);
472
- const contextValue = exeContext.contextValue;
477
+ let result;
473
478
  if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.beforeFieldSubscribe)) {
474
479
  hookContext = invokeBeforeFieldSubscribeHook(info, exeContext);
475
480
  }
476
- let result;
481
+ const args = getArgumentValues(exeContext, fieldDef, fieldGroup[0]);
482
+ const contextValue = exeContext.contextValue;
477
483
  if (hookContext) {
478
484
  if (isPromise(hookContext)) {
479
485
  result = hookContext.then((context) => {
480
486
  hookContext = context;
481
- if (hookContext instanceof GraphQLError) {
482
- return null;
483
- }
484
487
  return resolveFn(rootValue, args, contextValue, info);
485
488
  });
486
- } else if (hookContext instanceof GraphQLError) {
487
- result = null;
488
489
  }
489
490
  }
490
491
  if (result === void 0) {
@@ -499,42 +500,23 @@ function executeSubscriptionImpl(exeContext) {
499
500
  resolved,
500
501
  error
501
502
  );
502
- if (hookContext instanceof GraphQLError) {
503
- throw hookContext;
504
- }
505
503
  }
506
504
  };
507
505
  if (isPromise(result)) {
508
- return result.then(assertEventStream).then(
509
- (resolved) => {
510
- if (resolved instanceof GraphQLError) {
511
- throw resolved;
512
- }
513
- if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldSubscribe)) {
514
- hookContext = invokeAfterFieldSubscribeHook(
515
- info,
516
- exeContext,
517
- hookContext,
518
- resolved
519
- );
520
- if (hookContext instanceof GraphQLError) {
521
- throw hookContext;
522
- }
523
- }
524
- return resolved;
525
- },
526
- (error) => {
527
- afterFieldSubscribeHandle(void 0, error);
528
- throw locatedError(error, fieldGroup, pathToArray(path));
529
- }
530
- );
506
+ return result.then(assertEventStream, (error) => {
507
+ afterFieldSubscribeHandle(void 0, error);
508
+ throw locatedError(error, fieldGroup, pathToArray(path));
509
+ }).then((resolved) => {
510
+ afterFieldSubscribeHandle(resolved);
511
+ return resolved;
512
+ });
531
513
  }
532
514
  const stream = assertEventStream(result);
533
515
  afterFieldSubscribeHandle(stream);
534
516
  return stream;
535
517
  } catch (error) {
536
518
  if (!isDefaultResolverUsed && (hooks == null ? void 0 : hooks.afterFieldSubscribe)) {
537
- hookContext = invokeAfterFieldSubscribeHook(
519
+ invokeAfterFieldSubscribeHook(
538
520
  info,
539
521
  exeContext,
540
522
  hookContext,
@@ -542,9 +524,6 @@ function executeSubscriptionImpl(exeContext) {
542
524
  error
543
525
  );
544
526
  }
545
- if (hookContext instanceof GraphQLError) {
546
- throw hookContext;
547
- }
548
527
  throw locatedError(error, fieldGroup, pathToArray(path));
549
528
  }
550
529
  }
@@ -738,13 +717,10 @@ function resolveAndCompleteField(exeContext, parentTypeName, fieldDefinition, fi
738
717
  ),
739
718
  (rawError) => {
740
719
  const error = locatedError(rawError, fieldGroup, pathToArray(path));
741
- const hookResult = handleAfterFieldHooks(
720
+ handleAfterFieldHooks(
742
721
  invokeAfterFieldCompleteHook,
743
722
  !!(hooks == null ? void 0 : hooks.afterFieldComplete)
744
723
  )(void 0, error);
745
- if (hookResult === null) {
746
- return null;
747
- }
748
724
  handleFieldError(
749
725
  rawError,
750
726
  exeContext,
@@ -1275,7 +1251,7 @@ function invokeBeforeFieldSubscribeHook(resolveInfo, exeContext) {
1275
1251
  "Unexpected error in beforeFieldSubscribe hook"
1276
1252
  );
1277
1253
  exeContext.errors.push(error);
1278
- return error;
1254
+ throw error;
1279
1255
  } else if (result instanceof Error) {
1280
1256
  const error = toGraphQLError(
1281
1257
  result,
@@ -1283,7 +1259,7 @@ function invokeBeforeFieldSubscribeHook(resolveInfo, exeContext) {
1283
1259
  "Unexpected error in beforeFieldSubscribe hook"
1284
1260
  );
1285
1261
  exeContext.errors.push(error);
1286
- return error;
1262
+ throw error;
1287
1263
  }
1288
1264
  return result;
1289
1265
  }
@@ -1378,7 +1354,7 @@ function invokeAfterFieldSubscribeHook(resolveInfo, exeContext, hookContext, res
1378
1354
  "Unexpected error in afterFieldSubscribe hook"
1379
1355
  );
1380
1356
  exeContext.errors.push(error2);
1381
- return error2;
1357
+ throw error2;
1382
1358
  } else if (result2 instanceof Error) {
1383
1359
  const error2 = toGraphQLError(
1384
1360
  result2,
@@ -1386,7 +1362,7 @@ function invokeAfterFieldSubscribeHook(resolveInfo, exeContext, hookContext, res
1386
1362
  "Unexpected error in afterFieldSubscribe hook"
1387
1363
  );
1388
1364
  exeContext.errors.push(error2);
1389
- return error2;
1365
+ throw error2;
1390
1366
  }
1391
1367
  return result2;
1392
1368
  }
@@ -1449,7 +1425,7 @@ function invokeBeforeOperationExecuteHook(exeContext) {
1449
1425
  }
1450
1426
  if (result instanceof Error) {
1451
1427
  const error = toGraphQLError(
1452
- rawError,
1428
+ result,
1453
1429
  void 0,
1454
1430
  "Unexpected error in beforeOperationExecute hook"
1455
1431
  );
@@ -1504,7 +1480,7 @@ function invokeAfterBuildResponseHook(exeContext, result) {
1504
1480
  operation: exeContext.operation,
1505
1481
  result
1506
1482
  }),
1507
- (_, rawError) => {
1483
+ (result2, rawError) => {
1508
1484
  if (rawError) {
1509
1485
  const error = toGraphQLError(
1510
1486
  rawError,
@@ -1512,6 +1488,14 @@ function invokeAfterBuildResponseHook(exeContext, result) {
1512
1488
  "Unexpected error in afterBuildResponse hook"
1513
1489
  );
1514
1490
  exeContext.errors.push(error);
1491
+ return error;
1492
+ } else if (result2 instanceof Error) {
1493
+ const error = toGraphQLError(
1494
+ result2,
1495
+ void 0,
1496
+ "Unexpected error in afterBuildResponse hook"
1497
+ );
1498
+ exeContext.errors.push(error);
1515
1499
  }
1516
1500
  }
1517
1501
  );