graphql-modules 2.1.0-alpha-d1b812f5.0 → 2.1.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.
- package/application/execution-context.d.ts +3 -1
- package/index.js +28 -4
- package/index.mjs +28 -4
- package/package.json +1 -1
|
@@ -3,8 +3,10 @@ export interface ExecutionContextPicker {
|
|
|
3
3
|
getApplicationContext(): GraphQLModules.AppContext;
|
|
4
4
|
}
|
|
5
5
|
export declare const executionContext: {
|
|
6
|
-
create(picker: ExecutionContextPicker): void;
|
|
6
|
+
create(picker: ExecutionContextPicker): () => void;
|
|
7
7
|
getModuleContext: ExecutionContextPicker['getModuleContext'];
|
|
8
8
|
getApplicationContext: ExecutionContextPicker['getApplicationContext'];
|
|
9
9
|
};
|
|
10
10
|
export declare function enableExecutionContext(): void;
|
|
11
|
+
export declare function getExecutionContextStore(): Map<number, ExecutionContextPicker>;
|
|
12
|
+
export declare function getExecutionContextDependencyStore(): Map<number, Set<number>>;
|
package/index.js
CHANGED
|
@@ -176,11 +176,18 @@ function isFactoryProvider(provider) {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
const executionContextStore = new Map();
|
|
179
|
+
const executionContextDependencyStore = new Map();
|
|
179
180
|
const executionContextHook = async_hooks.createHook({
|
|
180
181
|
init(asyncId, _, triggerAsyncId) {
|
|
182
|
+
var _a;
|
|
181
183
|
// Store same context data for child async resources
|
|
182
|
-
|
|
183
|
-
|
|
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);
|
|
184
191
|
}
|
|
185
192
|
},
|
|
186
193
|
destroy(asyncId) {
|
|
@@ -189,9 +196,25 @@ const executionContextHook = async_hooks.createHook({
|
|
|
189
196
|
}
|
|
190
197
|
},
|
|
191
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
|
+
}
|
|
192
211
|
const executionContext = {
|
|
193
212
|
create(picker) {
|
|
194
|
-
|
|
213
|
+
const id = async_hooks.executionAsyncId();
|
|
214
|
+
executionContextStore.set(id, picker);
|
|
215
|
+
return function destroyContext() {
|
|
216
|
+
destroyContextAndItsChildren(id);
|
|
217
|
+
};
|
|
195
218
|
},
|
|
196
219
|
getModuleContext(moduleId) {
|
|
197
220
|
const picker = executionContextStore.get(async_hooks.executionAsyncId());
|
|
@@ -933,7 +956,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
933
956
|
return getModuleContext(moduleId, context);
|
|
934
957
|
},
|
|
935
958
|
};
|
|
936
|
-
executionContext.create(executionContextPicker);
|
|
959
|
+
const destroyExecutionContext = executionContext.create(executionContextPicker);
|
|
937
960
|
// As the name of the Injector says, it's an Operation scoped Injector
|
|
938
961
|
// Application level
|
|
939
962
|
// Operation scoped - means it's created and destroyed on every GraphQL Operation
|
|
@@ -1007,6 +1030,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
1007
1030
|
injector._getObjByKeyId(keyId).onDestroy();
|
|
1008
1031
|
}
|
|
1009
1032
|
});
|
|
1033
|
+
destroyExecutionContext();
|
|
1010
1034
|
contextCache = {};
|
|
1011
1035
|
}),
|
|
1012
1036
|
ɵinjector: operationAppInjector,
|
package/index.mjs
CHANGED
|
@@ -173,11 +173,18 @@ function isFactoryProvider(provider) {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
const executionContextStore = new Map();
|
|
176
|
+
const executionContextDependencyStore = new Map();
|
|
176
177
|
const executionContextHook = createHook({
|
|
177
178
|
init(asyncId, _, triggerAsyncId) {
|
|
179
|
+
var _a;
|
|
178
180
|
// Store same context data for child async resources
|
|
179
|
-
|
|
180
|
-
|
|
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);
|
|
181
188
|
}
|
|
182
189
|
},
|
|
183
190
|
destroy(asyncId) {
|
|
@@ -186,9 +193,25 @@ const executionContextHook = createHook({
|
|
|
186
193
|
}
|
|
187
194
|
},
|
|
188
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
|
+
}
|
|
189
208
|
const executionContext = {
|
|
190
209
|
create(picker) {
|
|
191
|
-
|
|
210
|
+
const id = executionAsyncId();
|
|
211
|
+
executionContextStore.set(id, picker);
|
|
212
|
+
return function destroyContext() {
|
|
213
|
+
destroyContextAndItsChildren(id);
|
|
214
|
+
};
|
|
192
215
|
},
|
|
193
216
|
getModuleContext(moduleId) {
|
|
194
217
|
const picker = executionContextStore.get(executionAsyncId());
|
|
@@ -930,7 +953,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
930
953
|
return getModuleContext(moduleId, context);
|
|
931
954
|
},
|
|
932
955
|
};
|
|
933
|
-
executionContext.create(executionContextPicker);
|
|
956
|
+
const destroyExecutionContext = executionContext.create(executionContextPicker);
|
|
934
957
|
// As the name of the Injector says, it's an Operation scoped Injector
|
|
935
958
|
// Application level
|
|
936
959
|
// Operation scoped - means it's created and destroyed on every GraphQL Operation
|
|
@@ -1004,6 +1027,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
1004
1027
|
injector._getObjByKeyId(keyId).onDestroy();
|
|
1005
1028
|
}
|
|
1006
1029
|
});
|
|
1030
|
+
destroyExecutionContext();
|
|
1007
1031
|
contextCache = {};
|
|
1008
1032
|
}),
|
|
1009
1033
|
ɵinjector: operationAppInjector,
|