graphql-modules 2.2.0 → 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,85 +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
- const executionContextStore$1 = async_hooks.AsyncLocalStorage
235
- ? new async_hooks.AsyncLocalStorage()
236
- : undefined;
237
- const executionContext$1 = {
238
- create(picker) {
239
- executionContextStore$1.enterWith(picker);
240
- return function destroyContext() { };
241
- },
242
- getModuleContext(moduleId) {
243
- return executionContextStore$1.getStore().getModuleContext(moduleId);
244
- },
245
- getApplicationContext() {
246
- return executionContextStore$1.getStore().getApplicationContext();
247
- },
248
- };
249
-
250
- const executionContext$2 = async_hooks.AsyncLocalStorage
251
- ? executionContext$1
252
- : executionContext;
253
- const enableExecutionContext$1 = async_hooks.AsyncLocalStorage
254
- ? () => undefined
255
- : enableExecutionContext;
256
-
257
177
  function ensureReflect() {
258
178
  if (!(Reflect && Reflect.getOwnMetadata)) {
259
179
  throw 'reflect-metadata shim is required when using class decorators';
@@ -263,7 +183,6 @@ function Injectable(options) {
263
183
  return (target) => {
264
184
  var _a;
265
185
  ensureReflect();
266
- enableExecutionContext$1();
267
186
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
268
187
  const existingMeta = readInjectableMetadata(target);
269
188
  const meta = {
@@ -962,24 +881,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
962
881
  return modulesMap.get(moduleId).injector;
963
882
  },
964
883
  });
965
- appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
884
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
885
+ return appContext;
886
+ });
966
887
  function createModuleExecutionContextGetter(moduleId) {
967
888
  return function moduleExecutionContextGetter() {
968
- return executionContext$2.getModuleContext(moduleId);
889
+ return getModuleContext(moduleId, context);
969
890
  };
970
891
  }
971
892
  modulesMap.forEach((mod, moduleId) => {
972
893
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
973
894
  });
974
- const executionContextPicker = {
975
- getApplicationContext() {
976
- return appContext;
977
- },
978
- getModuleContext(moduleId) {
979
- return getModuleContext(moduleId, context);
980
- },
981
- };
982
- const destroyExecutionContext = executionContext$2.create(executionContextPicker);
983
895
  // As the name of the Injector says, it's an Operation scoped Injector
984
896
  // Application level
985
897
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1053,7 +965,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1053
965
  injector._getObjByKeyId(keyId).onDestroy();
1054
966
  }
1055
967
  });
1056
- destroyExecutionContext();
1057
968
  contextCache = {};
1058
969
  }),
1059
970
  ɵinjector: operationAppInjector,
package/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { makeExecutableSchema } from '@graphql-tools/schema';
2
- import { createHook, executionAsyncId, AsyncLocalStorage } 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,85 +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
- const executionContextStore$1 = AsyncLocalStorage
232
- ? new AsyncLocalStorage()
233
- : undefined;
234
- const executionContext$1 = {
235
- create(picker) {
236
- executionContextStore$1.enterWith(picker);
237
- return function destroyContext() { };
238
- },
239
- getModuleContext(moduleId) {
240
- return executionContextStore$1.getStore().getModuleContext(moduleId);
241
- },
242
- getApplicationContext() {
243
- return executionContextStore$1.getStore().getApplicationContext();
244
- },
245
- };
246
-
247
- const executionContext$2 = AsyncLocalStorage
248
- ? executionContext$1
249
- : executionContext;
250
- const enableExecutionContext$1 = AsyncLocalStorage
251
- ? () => undefined
252
- : enableExecutionContext;
253
-
254
174
  function ensureReflect() {
255
175
  if (!(Reflect && Reflect.getOwnMetadata)) {
256
176
  throw 'reflect-metadata shim is required when using class decorators';
@@ -260,7 +180,6 @@ function Injectable(options) {
260
180
  return (target) => {
261
181
  var _a;
262
182
  ensureReflect();
263
- enableExecutionContext$1();
264
183
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
265
184
  const existingMeta = readInjectableMetadata(target);
266
185
  const meta = {
@@ -959,24 +878,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
959
878
  return modulesMap.get(moduleId).injector;
960
879
  },
961
880
  });
962
- appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
881
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
882
+ return appContext;
883
+ });
963
884
  function createModuleExecutionContextGetter(moduleId) {
964
885
  return function moduleExecutionContextGetter() {
965
- return executionContext$2.getModuleContext(moduleId);
886
+ return getModuleContext(moduleId, context);
966
887
  };
967
888
  }
968
889
  modulesMap.forEach((mod, moduleId) => {
969
890
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
970
891
  });
971
- const executionContextPicker = {
972
- getApplicationContext() {
973
- return appContext;
974
- },
975
- getModuleContext(moduleId) {
976
- return getModuleContext(moduleId, context);
977
- },
978
- };
979
- const destroyExecutionContext = executionContext$2.create(executionContextPicker);
980
892
  // As the name of the Injector says, it's an Operation scoped Injector
981
893
  // Application level
982
894
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1050,7 +962,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1050
962
  injector._getObjByKeyId(keyId).onDestroy();
1051
963
  }
1052
964
  });
1053
- destroyExecutionContext();
1054
965
  contextCache = {};
1055
966
  }),
1056
967
  ɵinjector: operationAppInjector,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-modules",
3
- "version": "2.2.0",
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,10 +0,0 @@
1
- /// <reference types="node" />
2
- import { AsyncLocalStorage } from 'async_hooks';
3
- import { type ExecutionContextPicker } from './execution-context.interface';
4
- export declare const executionContext: {
5
- create(picker: ExecutionContextPicker): () => void;
6
- getModuleContext: ExecutionContextPicker['getModuleContext'];
7
- getApplicationContext: ExecutionContextPicker['getApplicationContext'];
8
- };
9
- export declare function enableExecutionContext(): void;
10
- export declare function getExecutionContextStore(): AsyncLocalStorage<ExecutionContextPicker> | undefined;
@@ -1,9 +0,0 @@
1
- import { type ExecutionContextPicker } from './execution-context.interface';
2
- export declare const executionContext: {
3
- create(picker: ExecutionContextPicker): () => void;
4
- getModuleContext: ExecutionContextPicker['getModuleContext'];
5
- getApplicationContext: ExecutionContextPicker['getApplicationContext'];
6
- };
7
- export declare function enableExecutionContext(): void;
8
- export declare function getExecutionContextStore(): Map<number, ExecutionContextPicker>;
9
- export declare function getExecutionContextDependencyStore(): Map<number, Set<number>>;
@@ -1,8 +0,0 @@
1
- import * as Hooks from './execution-context-hooks';
2
- export type { ExecutionContextPicker } from './execution-context.interface';
3
- export declare const executionContext: {
4
- create(picker: import("./execution-context.interface").ExecutionContextPicker): () => void;
5
- getModuleContext: (moduleId: string) => GraphQLModules.ModuleContext;
6
- getApplicationContext: () => GraphQLModules.AppContext;
7
- };
8
- export declare const enableExecutionContext: typeof Hooks.enableExecutionContext;
@@ -1,4 +0,0 @@
1
- export interface ExecutionContextPicker {
2
- getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
3
- getApplicationContext(): GraphQLModules.AppContext;
4
- }