graphql-modules 3.1.0-alpha-20260116100600-27f3a402a486f5305eddcf90a40aed7f0c67071b → 3.1.0-alpha-20260116120626-0749090abe9d2dc233c8dc7d3ca6c7e01e0d7e60
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/async-context.browser.mjs +7 -0
- package/async-context.node.cjs +14 -0
- package/index.js +5 -22
- package/index.mjs +4 -21
- package/package.json +7 -1
- package/application/async-context.d.ts +0 -6
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// use async hooks
|
|
2
|
+
// TODO: typecheck
|
|
3
|
+
|
|
4
|
+
const hooks = require('async_hooks');
|
|
5
|
+
|
|
6
|
+
const alc = new hooks.AsyncLocalStorage();
|
|
7
|
+
|
|
8
|
+
// we dont use named exports (exports.getAsyncContext) because node with typescript is weird
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
getAsyncContext: () => alc.getStore(),
|
|
12
|
+
runWithAsyncContext: (asyncContext, callback, ...args) =>
|
|
13
|
+
alc.run(asyncContext, callback, ...args),
|
|
14
|
+
};
|
package/index.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const schema = require('@graphql-tools/schema');
|
|
6
6
|
const graphql = require('graphql');
|
|
7
|
-
const
|
|
7
|
+
const async_context = require('#async-context');
|
|
8
8
|
const wrap = require('@graphql-tools/wrap');
|
|
9
9
|
const ramda = require('ramda');
|
|
10
10
|
|
|
11
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const async_context__default = /*#__PURE__*/_interopDefaultLegacy(async_context);
|
|
14
14
|
|
|
15
15
|
const ERROR_ORIGINAL_ERROR = 'diOriginalError';
|
|
16
16
|
function getOriginalError(error) {
|
|
@@ -843,23 +843,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
843
843
|
].join(' '));
|
|
844
844
|
}
|
|
845
845
|
|
|
846
|
-
let alc;
|
|
847
|
-
if (typeof process !== 'undefined') {
|
|
848
|
-
// probably nodejs runtime
|
|
849
|
-
const require = module__default["default"].createRequire('file:///' /** path is not relevant since we're only loading a builtin */);
|
|
850
|
-
const hooks = require('async_hooks');
|
|
851
|
-
alc = new hooks.AsyncLocalStorage();
|
|
852
|
-
}
|
|
853
|
-
function getAsyncContext() {
|
|
854
|
-
return alc === null || alc === void 0 ? void 0 : alc.getStore();
|
|
855
|
-
}
|
|
856
|
-
function runWithAsyncContext(asyncContext, callback, ...args) {
|
|
857
|
-
if (!alc) {
|
|
858
|
-
return callback(...args);
|
|
859
|
-
}
|
|
860
|
-
return alc.run(asyncContext, callback, ...args);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
846
|
/**
|
|
864
847
|
* @api
|
|
865
848
|
* `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
|
|
@@ -906,12 +889,12 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
906
889
|
});
|
|
907
890
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
908
891
|
var _a;
|
|
909
|
-
return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
|
|
892
|
+
return (((_a = async_context__default["default"].getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext);
|
|
910
893
|
});
|
|
911
894
|
function createModuleExecutionContextGetter(moduleId) {
|
|
912
895
|
return function moduleExecutionContextGetter() {
|
|
913
896
|
var _a;
|
|
914
|
-
return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
897
|
+
return (((_a = async_context__default["default"].getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
915
898
|
getModuleContext(moduleId, context));
|
|
916
899
|
};
|
|
917
900
|
}
|
|
@@ -999,7 +982,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
999
982
|
return {
|
|
1000
983
|
...env,
|
|
1001
984
|
runWithContext(cb) {
|
|
1002
|
-
return runWithAsyncContext({
|
|
985
|
+
return async_context__default["default"].runWithAsyncContext({
|
|
1003
986
|
getApplicationContext() {
|
|
1004
987
|
return appContext;
|
|
1005
988
|
},
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema';
|
|
2
2
|
import { GraphQLSchema, execute as execute$1, subscribe, visit, Kind, concatAST, defaultFieldResolver, GraphQLScalarType, parse } from 'graphql';
|
|
3
|
-
import
|
|
3
|
+
import async_context from '#async-context';
|
|
4
4
|
import { wrapSchema } from '@graphql-tools/wrap';
|
|
5
5
|
import { mergeDeepWith } from 'ramda';
|
|
6
6
|
|
|
@@ -835,23 +835,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
835
835
|
].join(' '));
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
-
let alc;
|
|
839
|
-
if (typeof process !== 'undefined') {
|
|
840
|
-
// probably nodejs runtime
|
|
841
|
-
const require = module.createRequire('file:///' /** path is not relevant since we're only loading a builtin */);
|
|
842
|
-
const hooks = require('async_hooks');
|
|
843
|
-
alc = new hooks.AsyncLocalStorage();
|
|
844
|
-
}
|
|
845
|
-
function getAsyncContext() {
|
|
846
|
-
return alc === null || alc === void 0 ? void 0 : alc.getStore();
|
|
847
|
-
}
|
|
848
|
-
function runWithAsyncContext(asyncContext, callback, ...args) {
|
|
849
|
-
if (!alc) {
|
|
850
|
-
return callback(...args);
|
|
851
|
-
}
|
|
852
|
-
return alc.run(asyncContext, callback, ...args);
|
|
853
|
-
}
|
|
854
|
-
|
|
855
838
|
/**
|
|
856
839
|
* @api
|
|
857
840
|
* `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
|
|
@@ -898,12 +881,12 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
898
881
|
});
|
|
899
882
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
900
883
|
var _a;
|
|
901
|
-
return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
|
|
884
|
+
return (((_a = async_context.getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext);
|
|
902
885
|
});
|
|
903
886
|
function createModuleExecutionContextGetter(moduleId) {
|
|
904
887
|
return function moduleExecutionContextGetter() {
|
|
905
888
|
var _a;
|
|
906
|
-
return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
889
|
+
return (((_a = async_context.getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
907
890
|
getModuleContext(moduleId, context));
|
|
908
891
|
};
|
|
909
892
|
}
|
|
@@ -991,7 +974,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
991
974
|
return {
|
|
992
975
|
...env,
|
|
993
976
|
runWithContext(cb) {
|
|
994
|
-
return runWithAsyncContext({
|
|
977
|
+
return async_context.runWithAsyncContext({
|
|
995
978
|
getApplicationContext() {
|
|
996
979
|
return appContext;
|
|
997
980
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-modules",
|
|
3
|
-
"version": "3.1.0-alpha-
|
|
3
|
+
"version": "3.1.0-alpha-20260116120626-0749090abe9d2dc233c8dc7d3ca6c7e01e0d7e60",
|
|
4
4
|
"description": "Create reusable, maintainable, testable and extendable GraphQL modules",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -37,5 +37,11 @@
|
|
|
37
37
|
"import": "./*.mjs"
|
|
38
38
|
},
|
|
39
39
|
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"imports": {
|
|
42
|
+
"#async-context": {
|
|
43
|
+
"node": "./async-context.node.cjs",
|
|
44
|
+
"default": "./async-context.browser.mjs"
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export interface AsyncContext {
|
|
2
|
-
getApplicationContext(): GraphQLModules.AppContext;
|
|
3
|
-
getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
|
|
4
|
-
}
|
|
5
|
-
export declare function getAsyncContext(): AsyncContext | undefined;
|
|
6
|
-
export declare function runWithAsyncContext<R, TArgs extends any[]>(asyncContext: AsyncContext, callback: (...args: TArgs) => R, ...args: TArgs): R;
|