graphql-modules 2.1.3-alpha-20230725013707-39be59f9 → 2.2.1-alpha-20231102120726-44db491f

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/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const schema = require('@graphql-tools/schema');
6
- const async_hooks = require('async_hooks');
7
6
  const graphql = require('graphql');
8
7
  const wrap = require('@graphql-tools/wrap');
9
8
  const ramda = require('ramda');
@@ -175,62 +174,6 @@ function isFactoryProvider(provider) {
175
174
  return typeof provider.useFactory !== 'undefined';
176
175
  }
177
176
 
178
- const executionContextStore = new Map();
179
- const executionContextDependencyStore = new Map();
180
- const executionContextHook = async_hooks.createHook({
181
- init(asyncId, _, triggerAsyncId) {
182
- var _a;
183
- // Store same context data for child async resources
184
- const ctx = executionContextStore.get(triggerAsyncId);
185
- if (ctx) {
186
- const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
187
- .set(triggerAsyncId, new Set())
188
- .get(triggerAsyncId);
189
- dependencies.add(asyncId);
190
- executionContextStore.set(asyncId, ctx);
191
- }
192
- },
193
- destroy(asyncId) {
194
- if (executionContextStore.has(asyncId)) {
195
- executionContextStore.delete(asyncId);
196
- }
197
- },
198
- });
199
- function destroyContextAndItsChildren(id) {
200
- if (executionContextStore.has(id)) {
201
- executionContextStore.delete(id);
202
- }
203
- const deps = executionContextDependencyStore.get(id);
204
- if (deps) {
205
- for (const dep of deps) {
206
- destroyContextAndItsChildren(dep);
207
- }
208
- executionContextDependencyStore.delete(id);
209
- }
210
- }
211
- const executionContext = {
212
- create(picker) {
213
- const id = async_hooks.executionAsyncId();
214
- executionContextStore.set(id, picker);
215
- return function destroyContext() {
216
- destroyContextAndItsChildren(id);
217
- };
218
- },
219
- getModuleContext(moduleId) {
220
- const picker = executionContextStore.get(async_hooks.executionAsyncId());
221
- return picker.getModuleContext(moduleId);
222
- },
223
- getApplicationContext() {
224
- const picker = executionContextStore.get(async_hooks.executionAsyncId());
225
- return picker.getApplicationContext();
226
- },
227
- };
228
- function enableExecutionContext() {
229
- {
230
- executionContextHook.enable();
231
- }
232
- }
233
-
234
177
  function ensureReflect() {
235
178
  if (!(Reflect && Reflect.getOwnMetadata)) {
236
179
  throw 'reflect-metadata shim is required when using class decorators';
@@ -240,7 +183,6 @@ function Injectable(options) {
240
183
  return (target) => {
241
184
  var _a;
242
185
  ensureReflect();
243
- enableExecutionContext();
244
186
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
245
187
  const existingMeta = readInjectableMetadata(target);
246
188
  const meta = {
@@ -939,24 +881,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
939
881
  return modulesMap.get(moduleId).injector;
940
882
  },
941
883
  });
942
- appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
884
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
885
+ return appContext;
886
+ });
943
887
  function createModuleExecutionContextGetter(moduleId) {
944
888
  return function moduleExecutionContextGetter() {
945
- return executionContext.getModuleContext(moduleId);
889
+ return getModuleContext(moduleId, context);
946
890
  };
947
891
  }
948
892
  modulesMap.forEach((mod, moduleId) => {
949
893
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
950
894
  });
951
- const executionContextPicker = {
952
- getApplicationContext() {
953
- return appContext;
954
- },
955
- getModuleContext(moduleId) {
956
- return getModuleContext(moduleId, context);
957
- },
958
- };
959
- const destroyExecutionContext = executionContext.create(executionContextPicker);
960
895
  // As the name of the Injector says, it's an Operation scoped Injector
961
896
  // Application level
962
897
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1030,7 +965,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1030
965
  injector._getObjByKeyId(keyId).onDestroy();
1031
966
  }
1032
967
  });
1033
- destroyExecutionContext();
1034
968
  contextCache = {};
1035
969
  }),
1036
970
  ɵinjector: operationAppInjector,
package/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { makeExecutableSchema } from '@graphql-tools/schema';
2
- import { createHook, executionAsyncId } from 'async_hooks';
3
2
  import { GraphQLSchema, execute as execute$1, subscribe, visit, Kind, GraphQLScalarType, concatAST, defaultFieldResolver, parse } from 'graphql';
4
3
  import { wrapSchema } from '@graphql-tools/wrap';
5
4
  import { mergeDeepWith } from 'ramda';
@@ -172,62 +171,6 @@ function isFactoryProvider(provider) {
172
171
  return typeof provider.useFactory !== 'undefined';
173
172
  }
174
173
 
175
- const executionContextStore = new Map();
176
- const executionContextDependencyStore = new Map();
177
- const executionContextHook = createHook({
178
- init(asyncId, _, triggerAsyncId) {
179
- var _a;
180
- // Store same context data for child async resources
181
- const ctx = executionContextStore.get(triggerAsyncId);
182
- if (ctx) {
183
- const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
184
- .set(triggerAsyncId, new Set())
185
- .get(triggerAsyncId);
186
- dependencies.add(asyncId);
187
- executionContextStore.set(asyncId, ctx);
188
- }
189
- },
190
- destroy(asyncId) {
191
- if (executionContextStore.has(asyncId)) {
192
- executionContextStore.delete(asyncId);
193
- }
194
- },
195
- });
196
- function destroyContextAndItsChildren(id) {
197
- if (executionContextStore.has(id)) {
198
- executionContextStore.delete(id);
199
- }
200
- const deps = executionContextDependencyStore.get(id);
201
- if (deps) {
202
- for (const dep of deps) {
203
- destroyContextAndItsChildren(dep);
204
- }
205
- executionContextDependencyStore.delete(id);
206
- }
207
- }
208
- const executionContext = {
209
- create(picker) {
210
- const id = executionAsyncId();
211
- executionContextStore.set(id, picker);
212
- return function destroyContext() {
213
- destroyContextAndItsChildren(id);
214
- };
215
- },
216
- getModuleContext(moduleId) {
217
- const picker = executionContextStore.get(executionAsyncId());
218
- return picker.getModuleContext(moduleId);
219
- },
220
- getApplicationContext() {
221
- const picker = executionContextStore.get(executionAsyncId());
222
- return picker.getApplicationContext();
223
- },
224
- };
225
- function enableExecutionContext() {
226
- {
227
- executionContextHook.enable();
228
- }
229
- }
230
-
231
174
  function ensureReflect() {
232
175
  if (!(Reflect && Reflect.getOwnMetadata)) {
233
176
  throw 'reflect-metadata shim is required when using class decorators';
@@ -237,7 +180,6 @@ function Injectable(options) {
237
180
  return (target) => {
238
181
  var _a;
239
182
  ensureReflect();
240
- enableExecutionContext();
241
183
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
242
184
  const existingMeta = readInjectableMetadata(target);
243
185
  const meta = {
@@ -936,24 +878,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
936
878
  return modulesMap.get(moduleId).injector;
937
879
  },
938
880
  });
939
- appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
881
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
882
+ return appContext;
883
+ });
940
884
  function createModuleExecutionContextGetter(moduleId) {
941
885
  return function moduleExecutionContextGetter() {
942
- return executionContext.getModuleContext(moduleId);
886
+ return getModuleContext(moduleId, context);
943
887
  };
944
888
  }
945
889
  modulesMap.forEach((mod, moduleId) => {
946
890
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
947
891
  });
948
- const executionContextPicker = {
949
- getApplicationContext() {
950
- return appContext;
951
- },
952
- getModuleContext(moduleId) {
953
- return getModuleContext(moduleId, context);
954
- },
955
- };
956
- const destroyExecutionContext = executionContext.create(executionContextPicker);
957
892
  // As the name of the Injector says, it's an Operation scoped Injector
958
893
  // Application level
959
894
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1027,7 +962,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1027
962
  injector._getObjByKeyId(keyId).onDestroy();
1028
963
  }
1029
964
  });
1030
- destroyExecutionContext();
1031
965
  contextCache = {};
1032
966
  }),
1033
967
  ɵinjector: operationAppInjector,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-modules",
3
- "version": "2.1.3-alpha-20230725013707-39be59f9",
3
+ "version": "2.2.1-alpha-20231102120726-44db491f",
4
4
  "description": "Create reusable, maintainable, testable and extendable GraphQL modules",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,12 +0,0 @@
1
- export interface ExecutionContextPicker {
2
- getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
3
- getApplicationContext(): GraphQLModules.AppContext;
4
- }
5
- export declare const executionContext: {
6
- create(picker: ExecutionContextPicker): () => void;
7
- getModuleContext: ExecutionContextPicker['getModuleContext'];
8
- getApplicationContext: ExecutionContextPicker['getApplicationContext'];
9
- };
10
- export declare function enableExecutionContext(): void;
11
- export declare function getExecutionContextStore(): Map<number, ExecutionContextPicker>;
12
- export declare function getExecutionContextDependencyStore(): Map<number, Set<number>>;