graphql-modules 2.4.1-alpha-20250121160438-0491f4c48e11d9b869a28a3d5dc1f2c339cfdb5c → 2.4.1-alpha-20250121221848-ff77106387e981a83abd3a33c99efc5d874058ce

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.
@@ -3,10 +3,7 @@ import { ResolvedProvider } from '../di/resolution';
3
3
  import type { InternalAppContext, ModulesMap } from './application';
4
4
  export type ExecutionContextBuilder<TContext extends {
5
5
  [key: string]: any;
6
- } = {}> = (context: TContext) => ExecutionContextEnv & {
7
- runWithContext<TReturn = any>(cb: (env: ExecutionContextEnv) => TReturn): TReturn;
8
- };
9
- export type ExecutionContextEnv = {
6
+ } = {}> = (context: TContext) => {
10
7
  context: InternalAppContext;
11
8
  ɵdestroy(): void;
12
9
  ɵinjector: Injector;
@@ -3,6 +3,6 @@ import { ExecutionContextBuilder } from './context';
3
3
  export declare function executionCreator({ contextBuilder, }: {
4
4
  contextBuilder: ExecutionContextBuilder;
5
5
  }): (options?: {
6
- execute?: typeof execute | undefined;
7
- controller?: import("./types").OperationController | undefined;
8
- } | undefined) => typeof execute;
6
+ execute?: typeof execute;
7
+ controller?: import("./types").OperationController;
8
+ }) => typeof execute;
@@ -3,6 +3,6 @@ import { ExecutionContextBuilder } from './context';
3
3
  export declare function subscriptionCreator({ contextBuilder, }: {
4
4
  contextBuilder: ExecutionContextBuilder;
5
5
  }): (options?: {
6
- subscribe?: typeof subscribe | undefined;
7
- controller?: import("./types").OperationController | undefined;
8
- } | undefined) => typeof subscribe;
6
+ subscribe?: typeof subscribe;
7
+ controller?: import("./types").OperationController;
8
+ }) => typeof subscribe;
package/index.js CHANGED
@@ -2,11 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
5
  const schema = require('@graphql-tools/schema');
8
6
  const graphql = require('graphql');
9
- const module$1 = _interopDefault(require('module'));
10
7
  const wrap = require('@graphql-tools/wrap');
11
8
  const ramda = require('ramda');
12
9
 
@@ -735,9 +732,9 @@ function tapAsyncIterator(iterable, doneCallback) {
735
732
  throw error;
736
733
  }
737
734
  },
738
- async return() {
735
+ async return(value) {
739
736
  try {
740
- const result = await iterator.return();
737
+ const result = await iterator.return(value);
741
738
  return mapResult(result);
742
739
  }
743
740
  catch (error) {
@@ -745,7 +742,7 @@ function tapAsyncIterator(iterable, doneCallback) {
745
742
  throw error;
746
743
  }
747
744
  },
748
- async throw(error) {
745
+ throw(error) {
749
746
  doneCallback();
750
747
  return iterator.throw(error);
751
748
  },
@@ -840,23 +837,6 @@ function duplicatedGlobalTokenError(provider, modules) {
840
837
  ].join(' '));
841
838
  }
842
839
 
843
- let alc;
844
- if (typeof process !== 'undefined') {
845
- // probably nodejs runtime
846
- const require = module$1.createRequire('file:///' /** path is not relevant since we're only loading a builtin */);
847
- const hooks = require('async_hooks');
848
- alc = new hooks.AsyncLocalStorage();
849
- }
850
- function getAsyncContext() {
851
- return alc === null || alc === void 0 ? void 0 : alc.getStore();
852
- }
853
- function runWithAsyncContext(asyncContext, callback, ...args) {
854
- if (!alc) {
855
- return callback(...args);
856
- }
857
- return alc.run(asyncContext, callback, ...args);
858
- }
859
-
860
840
  /**
861
841
  * @api
862
842
  * `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
@@ -902,14 +882,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
902
882
  },
903
883
  });
904
884
  appInjector.setExecutionContextGetter(function executionContextGetter() {
905
- var _a;
906
- return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
885
+ return appContext;
907
886
  });
908
887
  function createModuleExecutionContextGetter(moduleId) {
909
888
  return function moduleExecutionContextGetter() {
910
- var _a;
911
- return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
912
- getModuleContext(moduleId, context));
889
+ return getModuleContext(moduleId, context);
913
890
  };
914
891
  }
915
892
  modulesMap.forEach((mod, moduleId) => {
@@ -979,7 +956,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
979
956
  return getModuleContext(moduleId, sharedContext).injector;
980
957
  },
981
958
  });
982
- const env = {
959
+ return {
983
960
  ɵdestroy: once(() => {
984
961
  providersToDestroy.forEach(([injector, keyId]) => {
985
962
  // If provider was instantiated
@@ -993,19 +970,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
993
970
  ɵinjector: operationAppInjector,
994
971
  context: sharedContext,
995
972
  };
996
- return {
997
- ...env,
998
- runWithContext(cb) {
999
- return runWithAsyncContext({
1000
- getApplicationContext() {
1001
- return appContext;
1002
- },
1003
- getModuleContext(moduleId) {
1004
- return getModuleContext(moduleId, context);
1005
- },
1006
- }, cb, env);
1007
- },
1008
- };
1009
973
  };
1010
974
  return contextBuilder;
1011
975
  }
@@ -1015,34 +979,31 @@ function executionCreator({ contextBuilder, }) {
1015
979
  // Custom or original execute function
1016
980
  const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || graphql.execute;
1017
981
  return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
1018
- function perform({ context, ɵdestroy: destroy, }) {
1019
- const executionArgs = isNotSchema(argsOrSchema)
1020
- ? {
1021
- ...argsOrSchema,
1022
- contextValue: context,
1023
- }
1024
- : {
1025
- schema: argsOrSchema,
1026
- document: document,
1027
- rootValue,
1028
- contextValue: context,
1029
- variableValues,
1030
- operationName,
1031
- fieldResolver,
1032
- typeResolver,
1033
- };
1034
- // It's important to wrap the executeFn within a promise
1035
- // so we can easily control the end of execution (with finally)
1036
- return Promise.resolve()
1037
- .then(() => executeFn(executionArgs))
1038
- .finally(destroy);
1039
- }
1040
- if (options === null || options === void 0 ? void 0 : options.controller) {
1041
- return perform(options.controller);
1042
- }
1043
- return contextBuilder(isNotSchema(argsOrSchema)
982
+ var _a;
983
+ // Create an execution context
984
+ const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
1044
985
  ? argsOrSchema.contextValue
1045
- : contextValue).runWithContext(perform);
986
+ : contextValue);
987
+ const executionArgs = isNotSchema(argsOrSchema)
988
+ ? {
989
+ ...argsOrSchema,
990
+ contextValue: context,
991
+ }
992
+ : {
993
+ schema: argsOrSchema,
994
+ document: document,
995
+ rootValue,
996
+ contextValue: context,
997
+ variableValues,
998
+ operationName,
999
+ fieldResolver,
1000
+ typeResolver,
1001
+ };
1002
+ // It's important to wrap the executeFn within a promise
1003
+ // so we can easily control the end of execution (with finally)
1004
+ return Promise.resolve()
1005
+ .then(() => executeFn(executionArgs))
1006
+ .finally(destroy);
1046
1007
  };
1047
1008
  };
1048
1009
  return createExecution;
@@ -1053,46 +1014,43 @@ function subscriptionCreator({ contextBuilder, }) {
1053
1014
  // Custom or original subscribe function
1054
1015
  const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || graphql.subscribe;
1055
1016
  return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
1056
- function perform({ context, ɵdestroy: destroy, }) {
1057
- const subscriptionArgs = isNotSchema(argsOrSchema)
1058
- ? {
1059
- ...argsOrSchema,
1060
- contextValue: context,
1061
- }
1062
- : {
1063
- schema: argsOrSchema,
1064
- document: document,
1065
- rootValue,
1066
- contextValue: context,
1067
- variableValues,
1068
- operationName,
1069
- fieldResolver,
1070
- subscribeFieldResolver,
1071
- };
1072
- let isIterable = false;
1073
- // It's important to wrap the subscribeFn within a promise
1074
- // so we can easily control the end of subscription (with finally)
1075
- return Promise.resolve()
1076
- .then(() => subscribeFn(subscriptionArgs))
1077
- .then((sub) => {
1078
- if (isAsyncIterable(sub)) {
1079
- isIterable = true;
1080
- return tapAsyncIterator(sub, destroy);
1081
- }
1082
- return sub;
1083
- })
1084
- .finally(() => {
1085
- if (!isIterable) {
1086
- destroy();
1087
- }
1088
- });
1089
- }
1090
- if (options === null || options === void 0 ? void 0 : options.controller) {
1091
- return perform(options.controller);
1092
- }
1093
- return contextBuilder(isNotSchema(argsOrSchema)
1017
+ var _a;
1018
+ // Create an subscription context
1019
+ const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
1094
1020
  ? argsOrSchema.contextValue
1095
- : contextValue).runWithContext(perform);
1021
+ : contextValue);
1022
+ const subscriptionArgs = isNotSchema(argsOrSchema)
1023
+ ? {
1024
+ ...argsOrSchema,
1025
+ contextValue: context,
1026
+ }
1027
+ : {
1028
+ schema: argsOrSchema,
1029
+ document: document,
1030
+ rootValue,
1031
+ contextValue: context,
1032
+ variableValues,
1033
+ operationName,
1034
+ fieldResolver,
1035
+ subscribeFieldResolver,
1036
+ };
1037
+ let isIterable = false;
1038
+ // It's important to wrap the subscribeFn within a promise
1039
+ // so we can easily control the end of subscription (with finally)
1040
+ return Promise.resolve()
1041
+ .then(() => subscribeFn(subscriptionArgs))
1042
+ .then((sub) => {
1043
+ if (isAsyncIterable(sub)) {
1044
+ isIterable = true;
1045
+ return tapAsyncIterator(sub, destroy);
1046
+ }
1047
+ return sub;
1048
+ })
1049
+ .finally(() => {
1050
+ if (!isIterable) {
1051
+ destroy();
1052
+ }
1053
+ });
1096
1054
  };
1097
1055
  };
1098
1056
  return createSubscription;
@@ -1117,9 +1075,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
1117
1075
  const createApolloSchema = () => {
1118
1076
  const sessions = {};
1119
1077
  const subscription = createSubscription();
1120
- function getSession(ctx, { context, ɵdestroy: destroy }) {
1078
+ function getSession(ctx) {
1121
1079
  if (!ctx[CONTEXT_ID]) {
1122
1080
  ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
1081
+ const { context, ɵdestroy: destroy } = contextBuilder(ctx);
1123
1082
  sessions[ctx[CONTEXT_ID]] = {
1124
1083
  count: 0,
1125
1084
  session: {
@@ -1151,22 +1110,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
1151
1110
  operationName: input.operationName,
1152
1111
  });
1153
1112
  }
1154
- // Create an execution context and run within it
1155
- return contextBuilder(input.context).runWithContext((env) => {
1156
- const { context, destroy } = getSession(input.context, env);
1157
- // It's important to wrap the executeFn within a promise
1158
- // so we can easily control the end of execution (with finally)
1159
- return Promise.resolve()
1160
- .then(() => graphql.execute({
1161
- schema,
1162
- document: input.document,
1163
- contextValue: context,
1164
- variableValues: input.variables,
1165
- rootValue: input.rootValue,
1166
- operationName: input.operationName,
1167
- }))
1168
- .finally(destroy);
1169
- });
1113
+ // Create an execution context
1114
+ const { context, destroy } = getSession(input.context);
1115
+ // It's important to wrap the executeFn within a promise
1116
+ // so we can easily control the end of execution (with finally)
1117
+ return Promise.resolve()
1118
+ .then(() => graphql.execute({
1119
+ schema,
1120
+ document: input.document,
1121
+ contextValue: context,
1122
+ variableValues: input.variables,
1123
+ rootValue: input.rootValue,
1124
+ operationName: input.operationName,
1125
+ }))
1126
+ .finally(destroy);
1170
1127
  },
1171
1128
  });
1172
1129
  };
package/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { makeExecutableSchema } from '@graphql-tools/schema';
2
2
  import { GraphQLSchema, execute as execute$1, subscribe, visit, Kind, GraphQLScalarType, concatAST, defaultFieldResolver, parse } from 'graphql';
3
- import module$1 from 'module';
4
3
  import { wrapSchema } from '@graphql-tools/wrap';
5
4
  import { mergeDeepWith } from 'ramda';
6
5
 
@@ -730,9 +729,9 @@ function tapAsyncIterator(iterable, doneCallback) {
730
729
  throw error;
731
730
  }
732
731
  },
733
- async return() {
732
+ async return(value) {
734
733
  try {
735
- const result = await iterator.return();
734
+ const result = await iterator.return(value);
736
735
  return mapResult(result);
737
736
  }
738
737
  catch (error) {
@@ -740,7 +739,7 @@ function tapAsyncIterator(iterable, doneCallback) {
740
739
  throw error;
741
740
  }
742
741
  },
743
- async throw(error) {
742
+ throw(error) {
744
743
  doneCallback();
745
744
  return iterator.throw(error);
746
745
  },
@@ -835,23 +834,6 @@ function duplicatedGlobalTokenError(provider, modules) {
835
834
  ].join(' '));
836
835
  }
837
836
 
838
- let alc;
839
- if (typeof process !== 'undefined') {
840
- // probably nodejs runtime
841
- const require = module$1.createRequire('file:///' /** path is not relevant since we're only loading a builtin */);
842
- const hooks = require('async_hooks');
843
- alc = new hooks.AsyncLocalStorage();
844
- }
845
- function getAsyncContext() {
846
- return alc === null || alc === void 0 ? void 0 : alc.getStore();
847
- }
848
- function runWithAsyncContext(asyncContext, callback, ...args) {
849
- if (!alc) {
850
- return callback(...args);
851
- }
852
- return alc.run(asyncContext, callback, ...args);
853
- }
854
-
855
837
  /**
856
838
  * @api
857
839
  * `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
@@ -897,14 +879,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
897
879
  },
898
880
  });
899
881
  appInjector.setExecutionContextGetter(function executionContextGetter() {
900
- var _a;
901
- return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
882
+ return appContext;
902
883
  });
903
884
  function createModuleExecutionContextGetter(moduleId) {
904
885
  return function moduleExecutionContextGetter() {
905
- var _a;
906
- return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
907
- getModuleContext(moduleId, context));
886
+ return getModuleContext(moduleId, context);
908
887
  };
909
888
  }
910
889
  modulesMap.forEach((mod, moduleId) => {
@@ -974,7 +953,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
974
953
  return getModuleContext(moduleId, sharedContext).injector;
975
954
  },
976
955
  });
977
- const env = {
956
+ return {
978
957
  ɵdestroy: once(() => {
979
958
  providersToDestroy.forEach(([injector, keyId]) => {
980
959
  // If provider was instantiated
@@ -988,19 +967,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
988
967
  ɵinjector: operationAppInjector,
989
968
  context: sharedContext,
990
969
  };
991
- return {
992
- ...env,
993
- runWithContext(cb) {
994
- return runWithAsyncContext({
995
- getApplicationContext() {
996
- return appContext;
997
- },
998
- getModuleContext(moduleId) {
999
- return getModuleContext(moduleId, context);
1000
- },
1001
- }, cb, env);
1002
- },
1003
- };
1004
970
  };
1005
971
  return contextBuilder;
1006
972
  }
@@ -1010,34 +976,31 @@ function executionCreator({ contextBuilder, }) {
1010
976
  // Custom or original execute function
1011
977
  const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || execute$1;
1012
978
  return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
1013
- function perform({ context, ɵdestroy: destroy, }) {
1014
- const executionArgs = isNotSchema(argsOrSchema)
1015
- ? {
1016
- ...argsOrSchema,
1017
- contextValue: context,
1018
- }
1019
- : {
1020
- schema: argsOrSchema,
1021
- document: document,
1022
- rootValue,
1023
- contextValue: context,
1024
- variableValues,
1025
- operationName,
1026
- fieldResolver,
1027
- typeResolver,
1028
- };
1029
- // It's important to wrap the executeFn within a promise
1030
- // so we can easily control the end of execution (with finally)
1031
- return Promise.resolve()
1032
- .then(() => executeFn(executionArgs))
1033
- .finally(destroy);
1034
- }
1035
- if (options === null || options === void 0 ? void 0 : options.controller) {
1036
- return perform(options.controller);
1037
- }
1038
- return contextBuilder(isNotSchema(argsOrSchema)
979
+ var _a;
980
+ // Create an execution context
981
+ const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
1039
982
  ? argsOrSchema.contextValue
1040
- : contextValue).runWithContext(perform);
983
+ : contextValue);
984
+ const executionArgs = isNotSchema(argsOrSchema)
985
+ ? {
986
+ ...argsOrSchema,
987
+ contextValue: context,
988
+ }
989
+ : {
990
+ schema: argsOrSchema,
991
+ document: document,
992
+ rootValue,
993
+ contextValue: context,
994
+ variableValues,
995
+ operationName,
996
+ fieldResolver,
997
+ typeResolver,
998
+ };
999
+ // It's important to wrap the executeFn within a promise
1000
+ // so we can easily control the end of execution (with finally)
1001
+ return Promise.resolve()
1002
+ .then(() => executeFn(executionArgs))
1003
+ .finally(destroy);
1041
1004
  };
1042
1005
  };
1043
1006
  return createExecution;
@@ -1048,46 +1011,43 @@ function subscriptionCreator({ contextBuilder, }) {
1048
1011
  // Custom or original subscribe function
1049
1012
  const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || subscribe;
1050
1013
  return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
1051
- function perform({ context, ɵdestroy: destroy, }) {
1052
- const subscriptionArgs = isNotSchema(argsOrSchema)
1053
- ? {
1054
- ...argsOrSchema,
1055
- contextValue: context,
1056
- }
1057
- : {
1058
- schema: argsOrSchema,
1059
- document: document,
1060
- rootValue,
1061
- contextValue: context,
1062
- variableValues,
1063
- operationName,
1064
- fieldResolver,
1065
- subscribeFieldResolver,
1066
- };
1067
- let isIterable = false;
1068
- // It's important to wrap the subscribeFn within a promise
1069
- // so we can easily control the end of subscription (with finally)
1070
- return Promise.resolve()
1071
- .then(() => subscribeFn(subscriptionArgs))
1072
- .then((sub) => {
1073
- if (isAsyncIterable(sub)) {
1074
- isIterable = true;
1075
- return tapAsyncIterator(sub, destroy);
1076
- }
1077
- return sub;
1078
- })
1079
- .finally(() => {
1080
- if (!isIterable) {
1081
- destroy();
1082
- }
1083
- });
1084
- }
1085
- if (options === null || options === void 0 ? void 0 : options.controller) {
1086
- return perform(options.controller);
1087
- }
1088
- return contextBuilder(isNotSchema(argsOrSchema)
1014
+ var _a;
1015
+ // Create an subscription context
1016
+ const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
1089
1017
  ? argsOrSchema.contextValue
1090
- : contextValue).runWithContext(perform);
1018
+ : contextValue);
1019
+ const subscriptionArgs = isNotSchema(argsOrSchema)
1020
+ ? {
1021
+ ...argsOrSchema,
1022
+ contextValue: context,
1023
+ }
1024
+ : {
1025
+ schema: argsOrSchema,
1026
+ document: document,
1027
+ rootValue,
1028
+ contextValue: context,
1029
+ variableValues,
1030
+ operationName,
1031
+ fieldResolver,
1032
+ subscribeFieldResolver,
1033
+ };
1034
+ let isIterable = false;
1035
+ // It's important to wrap the subscribeFn within a promise
1036
+ // so we can easily control the end of subscription (with finally)
1037
+ return Promise.resolve()
1038
+ .then(() => subscribeFn(subscriptionArgs))
1039
+ .then((sub) => {
1040
+ if (isAsyncIterable(sub)) {
1041
+ isIterable = true;
1042
+ return tapAsyncIterator(sub, destroy);
1043
+ }
1044
+ return sub;
1045
+ })
1046
+ .finally(() => {
1047
+ if (!isIterable) {
1048
+ destroy();
1049
+ }
1050
+ });
1091
1051
  };
1092
1052
  };
1093
1053
  return createSubscription;
@@ -1112,9 +1072,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
1112
1072
  const createApolloSchema = () => {
1113
1073
  const sessions = {};
1114
1074
  const subscription = createSubscription();
1115
- function getSession(ctx, { context, ɵdestroy: destroy }) {
1075
+ function getSession(ctx) {
1116
1076
  if (!ctx[CONTEXT_ID]) {
1117
1077
  ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
1078
+ const { context, ɵdestroy: destroy } = contextBuilder(ctx);
1118
1079
  sessions[ctx[CONTEXT_ID]] = {
1119
1080
  count: 0,
1120
1081
  session: {
@@ -1146,22 +1107,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
1146
1107
  operationName: input.operationName,
1147
1108
  });
1148
1109
  }
1149
- // Create an execution context and run within it
1150
- return contextBuilder(input.context).runWithContext((env) => {
1151
- const { context, destroy } = getSession(input.context, env);
1152
- // It's important to wrap the executeFn within a promise
1153
- // so we can easily control the end of execution (with finally)
1154
- return Promise.resolve()
1155
- .then(() => execute$1({
1156
- schema,
1157
- document: input.document,
1158
- contextValue: context,
1159
- variableValues: input.variables,
1160
- rootValue: input.rootValue,
1161
- operationName: input.operationName,
1162
- }))
1163
- .finally(destroy);
1164
- });
1110
+ // Create an execution context
1111
+ const { context, destroy } = getSession(input.context);
1112
+ // It's important to wrap the executeFn within a promise
1113
+ // so we can easily control the end of execution (with finally)
1114
+ return Promise.resolve()
1115
+ .then(() => execute$1({
1116
+ schema,
1117
+ document: input.document,
1118
+ contextValue: context,
1119
+ variableValues: input.variables,
1120
+ rootValue: input.rootValue,
1121
+ operationName: input.operationName,
1122
+ }))
1123
+ .finally(destroy);
1165
1124
  },
1166
1125
  });
1167
1126
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-modules",
3
- "version": "2.4.1-alpha-20250121160438-0491f4c48e11d9b869a28a3d5dc1f2c339cfdb5c",
3
+ "version": "2.4.1-alpha-20250121221848-ff77106387e981a83abd3a33c99efc5d874058ce",
4
4
  "description": "Create reusable, maintainable, testable and extendable GraphQL modules",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -10,7 +10,7 @@
10
10
  "@graphql-tools/schema": "^10.0.0",
11
11
  "@graphql-tools/wrap": "^10.0.0",
12
12
  "@graphql-typed-document-node/core": "^3.1.0",
13
- "ramda": "^0.29.0"
13
+ "ramda": "^0.30.0"
14
14
  },
15
15
  "keywords": [
16
16
  "graphql",
@@ -16,6 +16,6 @@ export type MiddlewareMap = {
16
16
  [field: string]: Middleware[];
17
17
  };
18
18
  };
19
- export declare function createMiddleware(path: string[], middlewareMap?: MiddlewareMap): (context: MiddlewareContext, next: Next<any>) => Promise<any>;
19
+ export declare function createMiddleware(path: string[], middlewareMap?: MiddlewareMap): (context: MiddlewareContext, next: Next) => Promise<any>;
20
20
  export declare function mergeMiddlewareMaps(app: MiddlewareMap, mod: MiddlewareMap): MiddlewareMap;
21
21
  export declare function validateMiddlewareMap(middlewareMap: MiddlewareMap, metadata: ModuleMetadata): void;
package/shared/utils.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare function isNil<T>(val: T | null | undefined): val is null | undef
4
4
  export declare function isObject(val: any): boolean;
5
5
  export declare function isPrimitive(val: any): val is number | string | boolean | symbol | bigint;
6
6
  export declare function isAsyncIterable(obj: any): obj is AsyncIterableIterator<any>;
7
- export declare function tapAsyncIterator<T>(iterable: AsyncIterable<T>, doneCallback: () => void): AsyncGenerator<T>;
7
+ export declare function tapAsyncIterator<T, TAsyncIterableIterator extends AsyncIterableIterator<T>>(iterable: TAsyncIterableIterator, doneCallback: () => void): TAsyncIterableIterator;
8
8
  export declare function once(cb: () => void): () => void;
9
9
  export declare function share<T, A>(factory: (arg?: A) => T): (arg?: A) => T;
10
10
  export declare function uniqueId(isNotUsed: (id: string) => boolean): string;
@@ -1,6 +0,0 @@
1
- export interface AsyncContext {
2
- getApplicationContext(): GraphQLModules.AppContext;
3
- getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
4
- }
5
- export declare function getAsyncContext(): AsyncContext | undefined;
6
- export declare function runWithAsyncContext<R, TArgs extends any[]>(asyncContext: AsyncContext, callback: (...args: TArgs) => R, ...args: TArgs): R;