@envelop/core 2.0.1-alpha-304a55e.0 → 2.1.0-alpha-4ba70ab.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.
Files changed (3) hide show
  1. package/index.js +27 -16
  2. package/index.mjs +27 -16
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -534,6 +534,7 @@ function createEnvelopOrchestrator(plugins) {
534
534
  const afterCalls = [];
535
535
  const subscribeErrorHandlers = [];
536
536
  let context = args.contextValue || {};
537
+ let result;
537
538
  for (const onSubscribe of beforeCallbacks.subscribe) {
538
539
  const after = await onSubscribe({
539
540
  subscribeFn,
@@ -544,6 +545,9 @@ function createEnvelopOrchestrator(plugins) {
544
545
  context = { ...context, ...extension };
545
546
  },
546
547
  args: args,
548
+ setResultAndStopExecution: stopResult => {
549
+ result = stopResult;
550
+ },
547
551
  });
548
552
  if (after) {
549
553
  if (after.onSubscribeResult) {
@@ -553,16 +557,21 @@ function createEnvelopOrchestrator(plugins) {
553
557
  subscribeErrorHandlers.push(after.onSubscribeError);
554
558
  }
555
559
  }
560
+ if (result !== undefined) {
561
+ break;
562
+ }
556
563
  }
557
564
  if (onResolversHandlers.length) {
558
565
  context[resolversHooksSymbol] = onResolversHandlers;
559
566
  }
560
- let result = await subscribeFn({
561
- ...args,
562
- contextValue: context,
563
- // Casted for GraphQL.js 15 compatibility
564
- // Can be removed once we drop support for GraphQL.js 15
565
- });
567
+ if (result === undefined) {
568
+ result = await subscribeFn({
569
+ ...args,
570
+ contextValue: context,
571
+ // Casted for GraphQL.js 15 compatibility
572
+ // Can be removed once we drop support for GraphQL.js 15
573
+ });
574
+ }
566
575
  const onNextHandler = [];
567
576
  const onEndHandler = [];
568
577
  for (const afterCb of afterCalls) {
@@ -626,12 +635,14 @@ function createEnvelopOrchestrator(plugins) {
626
635
  const afterCalls = [];
627
636
  let context = args.contextValue || {};
628
637
  for (const onExecute of beforeCallbacks.execute) {
638
+ let stopCalled = false;
629
639
  const after = await onExecute({
630
640
  executeFn,
631
641
  setExecuteFn: newExecuteFn => {
632
642
  executeFn = newExecuteFn;
633
643
  },
634
644
  setResultAndStopExecution: stopResult => {
645
+ stopCalled = true;
635
646
  result = stopResult;
636
647
  },
637
648
  extendContext: extension => {
@@ -647,22 +658,22 @@ function createEnvelopOrchestrator(plugins) {
647
658
  },
648
659
  args: args,
649
660
  });
650
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
651
- afterCalls.push(after.onExecuteDone);
661
+ if (stopCalled) {
662
+ return result;
652
663
  }
653
- if (result !== undefined) {
654
- break;
664
+ if (after) {
665
+ if (after.onExecuteDone) {
666
+ afterCalls.push(after.onExecuteDone);
667
+ }
655
668
  }
656
669
  }
657
670
  if (onResolversHandlers.length) {
658
671
  context[resolversHooksSymbol] = onResolversHandlers;
659
672
  }
660
- if (result === undefined) {
661
- result = (await executeFn({
662
- ...args,
663
- contextValue: context,
664
- }));
665
- }
673
+ result = (await executeFn({
674
+ ...args,
675
+ contextValue: context,
676
+ }));
666
677
  const onNextHandler = [];
667
678
  const onEndHandler = [];
668
679
  for (const afterCb of afterCalls) {
package/index.mjs CHANGED
@@ -530,6 +530,7 @@ function createEnvelopOrchestrator(plugins) {
530
530
  const afterCalls = [];
531
531
  const subscribeErrorHandlers = [];
532
532
  let context = args.contextValue || {};
533
+ let result;
533
534
  for (const onSubscribe of beforeCallbacks.subscribe) {
534
535
  const after = await onSubscribe({
535
536
  subscribeFn,
@@ -540,6 +541,9 @@ function createEnvelopOrchestrator(plugins) {
540
541
  context = { ...context, ...extension };
541
542
  },
542
543
  args: args,
544
+ setResultAndStopExecution: stopResult => {
545
+ result = stopResult;
546
+ },
543
547
  });
544
548
  if (after) {
545
549
  if (after.onSubscribeResult) {
@@ -549,16 +553,21 @@ function createEnvelopOrchestrator(plugins) {
549
553
  subscribeErrorHandlers.push(after.onSubscribeError);
550
554
  }
551
555
  }
556
+ if (result !== undefined) {
557
+ break;
558
+ }
552
559
  }
553
560
  if (onResolversHandlers.length) {
554
561
  context[resolversHooksSymbol] = onResolversHandlers;
555
562
  }
556
- let result = await subscribeFn({
557
- ...args,
558
- contextValue: context,
559
- // Casted for GraphQL.js 15 compatibility
560
- // Can be removed once we drop support for GraphQL.js 15
561
- });
563
+ if (result === undefined) {
564
+ result = await subscribeFn({
565
+ ...args,
566
+ contextValue: context,
567
+ // Casted for GraphQL.js 15 compatibility
568
+ // Can be removed once we drop support for GraphQL.js 15
569
+ });
570
+ }
562
571
  const onNextHandler = [];
563
572
  const onEndHandler = [];
564
573
  for (const afterCb of afterCalls) {
@@ -622,12 +631,14 @@ function createEnvelopOrchestrator(plugins) {
622
631
  const afterCalls = [];
623
632
  let context = args.contextValue || {};
624
633
  for (const onExecute of beforeCallbacks.execute) {
634
+ let stopCalled = false;
625
635
  const after = await onExecute({
626
636
  executeFn,
627
637
  setExecuteFn: newExecuteFn => {
628
638
  executeFn = newExecuteFn;
629
639
  },
630
640
  setResultAndStopExecution: stopResult => {
641
+ stopCalled = true;
631
642
  result = stopResult;
632
643
  },
633
644
  extendContext: extension => {
@@ -643,22 +654,22 @@ function createEnvelopOrchestrator(plugins) {
643
654
  },
644
655
  args: args,
645
656
  });
646
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
647
- afterCalls.push(after.onExecuteDone);
657
+ if (stopCalled) {
658
+ return result;
648
659
  }
649
- if (result !== undefined) {
650
- break;
660
+ if (after) {
661
+ if (after.onExecuteDone) {
662
+ afterCalls.push(after.onExecuteDone);
663
+ }
651
664
  }
652
665
  }
653
666
  if (onResolversHandlers.length) {
654
667
  context[resolversHooksSymbol] = onResolversHandlers;
655
668
  }
656
- if (result === undefined) {
657
- result = (await executeFn({
658
- ...args,
659
- contextValue: context,
660
- }));
661
- }
669
+ result = (await executeFn({
670
+ ...args,
671
+ contextValue: context,
672
+ }));
662
673
  const onNextHandler = [];
663
674
  const onEndHandler = [];
664
675
  for (const afterCb of afterCalls) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.0.1-alpha-304a55e.0",
3
+ "version": "2.1.0-alpha-4ba70ab.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"