graphql-modules 3.0.0-alpha-20231018162945-f59bbaea → 3.0.0-alpha-20231106133212-0b04b56e

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 ramda = require('ramda');
9
8
 
@@ -174,85 +173,6 @@ function isFactoryProvider(provider) {
174
173
  return typeof provider.useFactory !== 'undefined';
175
174
  }
176
175
 
177
- const executionContextStore = new Map();
178
- const executionContextDependencyStore = new Map();
179
- const executionContextHook = async_hooks.createHook({
180
- init(asyncId, _, triggerAsyncId) {
181
- var _a;
182
- // Store same context data for child async resources
183
- const ctx = executionContextStore.get(triggerAsyncId);
184
- if (ctx) {
185
- const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
186
- .set(triggerAsyncId, new Set())
187
- .get(triggerAsyncId);
188
- dependencies.add(asyncId);
189
- executionContextStore.set(asyncId, ctx);
190
- }
191
- },
192
- destroy(asyncId) {
193
- if (executionContextStore.has(asyncId)) {
194
- executionContextStore.delete(asyncId);
195
- }
196
- },
197
- });
198
- function destroyContextAndItsChildren(id) {
199
- if (executionContextStore.has(id)) {
200
- executionContextStore.delete(id);
201
- }
202
- const deps = executionContextDependencyStore.get(id);
203
- if (deps) {
204
- for (const dep of deps) {
205
- destroyContextAndItsChildren(dep);
206
- }
207
- executionContextDependencyStore.delete(id);
208
- }
209
- }
210
- const executionContext = {
211
- create(picker) {
212
- const id = async_hooks.executionAsyncId();
213
- executionContextStore.set(id, picker);
214
- return function destroyContext() {
215
- destroyContextAndItsChildren(id);
216
- };
217
- },
218
- getModuleContext(moduleId) {
219
- const picker = executionContextStore.get(async_hooks.executionAsyncId());
220
- return picker.getModuleContext(moduleId);
221
- },
222
- getApplicationContext() {
223
- const picker = executionContextStore.get(async_hooks.executionAsyncId());
224
- return picker.getApplicationContext();
225
- },
226
- };
227
- function enableExecutionContext() {
228
- {
229
- executionContextHook.enable();
230
- }
231
- }
232
-
233
- const executionContextStore$1 = async_hooks.AsyncLocalStorage
234
- ? new async_hooks.AsyncLocalStorage()
235
- : undefined;
236
- const executionContext$1 = {
237
- create(picker) {
238
- executionContextStore$1.enterWith(picker);
239
- return function destroyContext() { };
240
- },
241
- getModuleContext(moduleId) {
242
- return executionContextStore$1.getStore().getModuleContext(moduleId);
243
- },
244
- getApplicationContext() {
245
- return executionContextStore$1.getStore().getApplicationContext();
246
- },
247
- };
248
-
249
- const executionContext$2 = async_hooks.AsyncLocalStorage
250
- ? executionContext$1
251
- : executionContext;
252
- const enableExecutionContext$1 = async_hooks.AsyncLocalStorage
253
- ? () => undefined
254
- : enableExecutionContext;
255
-
256
176
  function ensureReflect() {
257
177
  if (!(Reflect && Reflect.getOwnMetadata)) {
258
178
  throw 'reflect-metadata shim is required when using class decorators';
@@ -262,7 +182,6 @@ function Injectable(options) {
262
182
  return (target) => {
263
183
  var _a;
264
184
  ensureReflect();
265
- enableExecutionContext$1();
266
185
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
267
186
  const existingMeta = readInjectableMetadata(target);
268
187
  const meta = {
@@ -956,24 +875,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
956
875
  return modulesMap.get(moduleId).injector;
957
876
  },
958
877
  });
959
- appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
878
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
879
+ return appContext;
880
+ });
960
881
  function createModuleExecutionContextGetter(moduleId) {
961
882
  return function moduleExecutionContextGetter() {
962
- return executionContext$2.getModuleContext(moduleId);
883
+ return getModuleContext(moduleId, context);
963
884
  };
964
885
  }
965
886
  modulesMap.forEach((mod, moduleId) => {
966
887
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
967
888
  });
968
- const executionContextPicker = {
969
- getApplicationContext() {
970
- return appContext;
971
- },
972
- getModuleContext(moduleId) {
973
- return getModuleContext(moduleId, context);
974
- },
975
- };
976
- const destroyExecutionContext = executionContext$2.create(executionContextPicker);
977
889
  // As the name of the Injector says, it's an Operation scoped Injector
978
890
  // Application level
979
891
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1047,7 +959,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1047
959
  injector._getObjByKeyId(keyId).onDestroy();
1048
960
  }
1049
961
  });
1050
- destroyExecutionContext();
1051
962
  contextCache = {};
1052
963
  }),
1053
964
  ɵinjector: operationAppInjector,
@@ -1597,7 +1508,11 @@ function wrapResolver({ resolver, config, path, middlewareMap, isTypeResolver, i
1597
1508
  const wrappedResolver = (root, context, info) => {
1598
1509
  const ctx = {
1599
1510
  root,
1600
- context: context.ɵgetModuleContext(config.id, context),
1511
+ context: isReferenceResolver
1512
+ ? context.ɵgetModuleContext(config.id, context)
1513
+ : // We mark the context object as possibly undefined,
1514
+ // because graphql-jit for some reason doesn't pass it for isTypeOf or resolveType methods
1515
+ context === null || context === void 0 ? void 0 : context.ɵgetModuleContext(config.id, context),
1601
1516
  info,
1602
1517
  };
1603
1518
  return resolver(ctx.root, ctx.context, ctx.info);
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, print, concatAST, visit, Kind, GraphQLScalarType, defaultFieldResolver, parse } from 'graphql';
4
3
  import { mergeDeepWith } from 'ramda';
5
4
 
@@ -171,85 +170,6 @@ function isFactoryProvider(provider) {
171
170
  return typeof provider.useFactory !== 'undefined';
172
171
  }
173
172
 
174
- const executionContextStore = new Map();
175
- const executionContextDependencyStore = new Map();
176
- const executionContextHook = createHook({
177
- init(asyncId, _, triggerAsyncId) {
178
- var _a;
179
- // Store same context data for child async resources
180
- const ctx = executionContextStore.get(triggerAsyncId);
181
- if (ctx) {
182
- const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
183
- .set(triggerAsyncId, new Set())
184
- .get(triggerAsyncId);
185
- dependencies.add(asyncId);
186
- executionContextStore.set(asyncId, ctx);
187
- }
188
- },
189
- destroy(asyncId) {
190
- if (executionContextStore.has(asyncId)) {
191
- executionContextStore.delete(asyncId);
192
- }
193
- },
194
- });
195
- function destroyContextAndItsChildren(id) {
196
- if (executionContextStore.has(id)) {
197
- executionContextStore.delete(id);
198
- }
199
- const deps = executionContextDependencyStore.get(id);
200
- if (deps) {
201
- for (const dep of deps) {
202
- destroyContextAndItsChildren(dep);
203
- }
204
- executionContextDependencyStore.delete(id);
205
- }
206
- }
207
- const executionContext = {
208
- create(picker) {
209
- const id = executionAsyncId();
210
- executionContextStore.set(id, picker);
211
- return function destroyContext() {
212
- destroyContextAndItsChildren(id);
213
- };
214
- },
215
- getModuleContext(moduleId) {
216
- const picker = executionContextStore.get(executionAsyncId());
217
- return picker.getModuleContext(moduleId);
218
- },
219
- getApplicationContext() {
220
- const picker = executionContextStore.get(executionAsyncId());
221
- return picker.getApplicationContext();
222
- },
223
- };
224
- function enableExecutionContext() {
225
- {
226
- executionContextHook.enable();
227
- }
228
- }
229
-
230
- const executionContextStore$1 = AsyncLocalStorage
231
- ? new AsyncLocalStorage()
232
- : undefined;
233
- const executionContext$1 = {
234
- create(picker) {
235
- executionContextStore$1.enterWith(picker);
236
- return function destroyContext() { };
237
- },
238
- getModuleContext(moduleId) {
239
- return executionContextStore$1.getStore().getModuleContext(moduleId);
240
- },
241
- getApplicationContext() {
242
- return executionContextStore$1.getStore().getApplicationContext();
243
- },
244
- };
245
-
246
- const executionContext$2 = AsyncLocalStorage
247
- ? executionContext$1
248
- : executionContext;
249
- const enableExecutionContext$1 = AsyncLocalStorage
250
- ? () => undefined
251
- : enableExecutionContext;
252
-
253
173
  function ensureReflect() {
254
174
  if (!(Reflect && Reflect.getOwnMetadata)) {
255
175
  throw 'reflect-metadata shim is required when using class decorators';
@@ -259,7 +179,6 @@ function Injectable(options) {
259
179
  return (target) => {
260
180
  var _a;
261
181
  ensureReflect();
262
- enableExecutionContext$1();
263
182
  const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
264
183
  const existingMeta = readInjectableMetadata(target);
265
184
  const meta = {
@@ -953,24 +872,17 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
953
872
  return modulesMap.get(moduleId).injector;
954
873
  },
955
874
  });
956
- appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
875
+ appInjector.setExecutionContextGetter(function executionContextGetter() {
876
+ return appContext;
877
+ });
957
878
  function createModuleExecutionContextGetter(moduleId) {
958
879
  return function moduleExecutionContextGetter() {
959
- return executionContext$2.getModuleContext(moduleId);
880
+ return getModuleContext(moduleId, context);
960
881
  };
961
882
  }
962
883
  modulesMap.forEach((mod, moduleId) => {
963
884
  mod.injector.setExecutionContextGetter(createModuleExecutionContextGetter(moduleId));
964
885
  });
965
- const executionContextPicker = {
966
- getApplicationContext() {
967
- return appContext;
968
- },
969
- getModuleContext(moduleId) {
970
- return getModuleContext(moduleId, context);
971
- },
972
- };
973
- const destroyExecutionContext = executionContext$2.create(executionContextPicker);
974
886
  // As the name of the Injector says, it's an Operation scoped Injector
975
887
  // Application level
976
888
  // Operation scoped - means it's created and destroyed on every GraphQL Operation
@@ -1044,7 +956,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
1044
956
  injector._getObjByKeyId(keyId).onDestroy();
1045
957
  }
1046
958
  });
1047
- destroyExecutionContext();
1048
959
  contextCache = {};
1049
960
  }),
1050
961
  ɵinjector: operationAppInjector,
@@ -1594,7 +1505,11 @@ function wrapResolver({ resolver, config, path, middlewareMap, isTypeResolver, i
1594
1505
  const wrappedResolver = (root, context, info) => {
1595
1506
  const ctx = {
1596
1507
  root,
1597
- context: context.ɵgetModuleContext(config.id, context),
1508
+ context: isReferenceResolver
1509
+ ? context.ɵgetModuleContext(config.id, context)
1510
+ : // We mark the context object as possibly undefined,
1511
+ // because graphql-jit for some reason doesn't pass it for isTypeOf or resolveType methods
1512
+ context === null || context === void 0 ? void 0 : context.ɵgetModuleContext(config.id, context),
1598
1513
  info,
1599
1514
  };
1600
1515
  return resolver(ctx.root, ctx.context, ctx.info);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-modules",
3
- "version": "3.0.0-alpha-20231018162945-f59bbaea",
3
+ "version": "3.0.0-alpha-20231106133212-0b04b56e",
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
- }