graphql-modules 2.1.3-alpha-20230725013707-39be59f9 → 2.2.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.
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,9 @@
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,12 +1,8 @@
1
- export interface ExecutionContextPicker {
2
- getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
3
- getApplicationContext(): GraphQLModules.AppContext;
4
- }
1
+ import * as Hooks from './execution-context-hooks';
2
+ export type { ExecutionContextPicker } from './execution-context.interface';
5
3
  export declare const executionContext: {
6
- create(picker: ExecutionContextPicker): () => void;
7
- getModuleContext: ExecutionContextPicker['getModuleContext'];
8
- getApplicationContext: ExecutionContextPicker['getApplicationContext'];
4
+ create(picker: import("./execution-context.interface").ExecutionContextPicker): () => void;
5
+ getModuleContext: (moduleId: string) => GraphQLModules.ModuleContext;
6
+ getApplicationContext: () => GraphQLModules.AppContext;
9
7
  };
10
- export declare function enableExecutionContext(): void;
11
- export declare function getExecutionContextStore(): Map<number, ExecutionContextPicker>;
12
- export declare function getExecutionContextDependencyStore(): Map<number, Set<number>>;
8
+ export declare const enableExecutionContext: typeof Hooks.enableExecutionContext;
@@ -0,0 +1,4 @@
1
+ export interface ExecutionContextPicker {
2
+ getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
3
+ getApplicationContext(): GraphQLModules.AppContext;
4
+ }
package/index.js CHANGED
@@ -231,6 +231,29 @@ function enableExecutionContext() {
231
231
  }
232
232
  }
233
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
+
234
257
  function ensureReflect() {
235
258
  if (!(Reflect && Reflect.getOwnMetadata)) {
236
259
  throw 'reflect-metadata shim is required when using class decorators';
@@ -240,7 +263,7 @@ function Injectable(options) {
240
263
  return (target) => {
241
264
  var _a;
242
265
  ensureReflect();
243
- enableExecutionContext();
266
+ enableExecutionContext$1();
244
267
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
245
268
  const existingMeta = readInjectableMetadata(target);
246
269
  const meta = {
@@ -939,10 +962,10 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
939
962
  return modulesMap.get(moduleId).injector;
940
963
  },
941
964
  });
942
- appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
965
+ appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
943
966
  function createModuleExecutionContextGetter(moduleId) {
944
967
  return function moduleExecutionContextGetter() {
945
- return executionContext.getModuleContext(moduleId);
968
+ return executionContext$2.getModuleContext(moduleId);
946
969
  };
947
970
  }
948
971
  modulesMap.forEach((mod, moduleId) => {
@@ -956,7 +979,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
956
979
  return getModuleContext(moduleId, context);
957
980
  },
958
981
  };
959
- const destroyExecutionContext = executionContext.create(executionContextPicker);
982
+ const destroyExecutionContext = executionContext$2.create(executionContextPicker);
960
983
  // As the name of the Injector says, it's an Operation scoped Injector
961
984
  // Application level
962
985
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { makeExecutableSchema } from '@graphql-tools/schema';
2
- import { createHook, executionAsyncId } from 'async_hooks';
2
+ import { createHook, executionAsyncId, AsyncLocalStorage } from 'async_hooks';
3
3
  import { GraphQLSchema, execute as execute$1, subscribe, visit, Kind, GraphQLScalarType, concatAST, defaultFieldResolver, parse } from 'graphql';
4
4
  import { wrapSchema } from '@graphql-tools/wrap';
5
5
  import { mergeDeepWith } from 'ramda';
@@ -228,6 +228,29 @@ function enableExecutionContext() {
228
228
  }
229
229
  }
230
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
+
231
254
  function ensureReflect() {
232
255
  if (!(Reflect && Reflect.getOwnMetadata)) {
233
256
  throw 'reflect-metadata shim is required when using class decorators';
@@ -237,7 +260,7 @@ function Injectable(options) {
237
260
  return (target) => {
238
261
  var _a;
239
262
  ensureReflect();
240
- enableExecutionContext();
263
+ enableExecutionContext$1();
241
264
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
242
265
  const existingMeta = readInjectableMetadata(target);
243
266
  const meta = {
@@ -936,10 +959,10 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
936
959
  return modulesMap.get(moduleId).injector;
937
960
  },
938
961
  });
939
- appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
962
+ appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
940
963
  function createModuleExecutionContextGetter(moduleId) {
941
964
  return function moduleExecutionContextGetter() {
942
- return executionContext.getModuleContext(moduleId);
965
+ return executionContext$2.getModuleContext(moduleId);
943
966
  };
944
967
  }
945
968
  modulesMap.forEach((mod, moduleId) => {
@@ -953,7 +976,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
953
976
  return getModuleContext(moduleId, context);
954
977
  },
955
978
  };
956
- const destroyExecutionContext = executionContext.create(executionContextPicker);
979
+ const destroyExecutionContext = executionContext$2.create(executionContextPicker);
957
980
  // As the name of the Injector says, it's an Operation scoped Injector
958
981
  // Application level
959
982
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
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.0",
4
4
  "description": "Create reusable, maintainable, testable and extendable GraphQL modules",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {