graphql-modules 3.1.0-alpha-20260116090824-8472185427836c94f78f09105670ec509014b5d7 → 3.1.0-alpha-20260116090853-00f0aa9d636b258ea952ebd5f8d5ca0416ec8461
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/context.d.ts +1 -4
- package/index.js +79 -124
- package/index.mjs +79 -120
- package/package.json +1 -1
- package/application/async-context.d.ts +0 -6
package/application/context.d.ts
CHANGED
|
@@ -3,10 +3,7 @@ import { ResolvedProvider } from '../di/resolution';
|
|
|
3
3
|
import type { InternalAppContext, ModulesMap } from './application';
|
|
4
4
|
export type ExecutionContextBuilder<TContext extends {
|
|
5
5
|
[key: string]: any;
|
|
6
|
-
} = {}> = (context: TContext) =>
|
|
7
|
-
runWithContext<TReturn = any>(cb: (env: ExecutionContextEnv) => TReturn): TReturn;
|
|
8
|
-
};
|
|
9
|
-
export type ExecutionContextEnv = {
|
|
6
|
+
} = {}> = (context: TContext) => {
|
|
10
7
|
context: InternalAppContext;
|
|
11
8
|
ɵdestroy(): void;
|
|
12
9
|
ɵinjector: Injector;
|
package/index.js
CHANGED
|
@@ -4,14 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const schema = require('@graphql-tools/schema');
|
|
6
6
|
const graphql = require('graphql');
|
|
7
|
-
const module$1 = require('module');
|
|
8
7
|
const wrap = require('@graphql-tools/wrap');
|
|
9
8
|
const ramda = require('ramda');
|
|
10
9
|
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
const module__default = /*#__PURE__*/_interopDefaultLegacy(module$1);
|
|
14
|
-
|
|
15
10
|
const ERROR_ORIGINAL_ERROR = 'diOriginalError';
|
|
16
11
|
function getOriginalError(error) {
|
|
17
12
|
return error[ERROR_ORIGINAL_ERROR];
|
|
@@ -843,23 +838,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
843
838
|
].join(' '));
|
|
844
839
|
}
|
|
845
840
|
|
|
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
841
|
/**
|
|
864
842
|
* @api
|
|
865
843
|
* `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
|
|
@@ -905,14 +883,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
905
883
|
},
|
|
906
884
|
});
|
|
907
885
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
908
|
-
|
|
909
|
-
return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
|
|
886
|
+
return appContext;
|
|
910
887
|
});
|
|
911
888
|
function createModuleExecutionContextGetter(moduleId) {
|
|
912
889
|
return function moduleExecutionContextGetter() {
|
|
913
|
-
|
|
914
|
-
return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
915
|
-
getModuleContext(moduleId, context));
|
|
890
|
+
return getModuleContext(moduleId, context);
|
|
916
891
|
};
|
|
917
892
|
}
|
|
918
893
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -982,7 +957,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
982
957
|
return getModuleContext(moduleId, sharedContext).injector;
|
|
983
958
|
},
|
|
984
959
|
});
|
|
985
|
-
|
|
960
|
+
return {
|
|
986
961
|
ɵdestroy: once(() => {
|
|
987
962
|
providersToDestroy.forEach(([injector, keyId]) => {
|
|
988
963
|
// If provider was instantiated
|
|
@@ -996,19 +971,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
996
971
|
ɵinjector: operationAppInjector,
|
|
997
972
|
context: sharedContext,
|
|
998
973
|
};
|
|
999
|
-
return {
|
|
1000
|
-
...env,
|
|
1001
|
-
runWithContext(cb) {
|
|
1002
|
-
return runWithAsyncContext({
|
|
1003
|
-
getApplicationContext() {
|
|
1004
|
-
return appContext;
|
|
1005
|
-
},
|
|
1006
|
-
getModuleContext(moduleId) {
|
|
1007
|
-
return getModuleContext(moduleId, context);
|
|
1008
|
-
},
|
|
1009
|
-
}, cb, env);
|
|
1010
|
-
},
|
|
1011
|
-
};
|
|
1012
974
|
};
|
|
1013
975
|
return contextBuilder;
|
|
1014
976
|
}
|
|
@@ -1018,34 +980,31 @@ function executionCreator({ contextBuilder, }) {
|
|
|
1018
980
|
// Custom or original execute function
|
|
1019
981
|
const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || graphql.execute;
|
|
1020
982
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
...argsOrSchema,
|
|
1025
|
-
contextValue: context,
|
|
1026
|
-
}
|
|
1027
|
-
: {
|
|
1028
|
-
schema: argsOrSchema,
|
|
1029
|
-
document: document,
|
|
1030
|
-
rootValue,
|
|
1031
|
-
contextValue: context,
|
|
1032
|
-
variableValues,
|
|
1033
|
-
operationName,
|
|
1034
|
-
fieldResolver,
|
|
1035
|
-
typeResolver,
|
|
1036
|
-
};
|
|
1037
|
-
// It's important to wrap the executeFn within a promise
|
|
1038
|
-
// so we can easily control the end of execution (with finally)
|
|
1039
|
-
return Promise.resolve()
|
|
1040
|
-
.then(() => executeFn(executionArgs))
|
|
1041
|
-
.finally(destroy);
|
|
1042
|
-
}
|
|
1043
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1044
|
-
return perform(options.controller);
|
|
1045
|
-
}
|
|
1046
|
-
return contextBuilder(isNotSchema(argsOrSchema)
|
|
983
|
+
var _a;
|
|
984
|
+
// Create an execution context
|
|
985
|
+
const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
|
|
1047
986
|
? argsOrSchema.contextValue
|
|
1048
|
-
: contextValue)
|
|
987
|
+
: contextValue);
|
|
988
|
+
const executionArgs = isNotSchema(argsOrSchema)
|
|
989
|
+
? {
|
|
990
|
+
...argsOrSchema,
|
|
991
|
+
contextValue: context,
|
|
992
|
+
}
|
|
993
|
+
: {
|
|
994
|
+
schema: argsOrSchema,
|
|
995
|
+
document: document,
|
|
996
|
+
rootValue,
|
|
997
|
+
contextValue: context,
|
|
998
|
+
variableValues,
|
|
999
|
+
operationName,
|
|
1000
|
+
fieldResolver,
|
|
1001
|
+
typeResolver,
|
|
1002
|
+
};
|
|
1003
|
+
// It's important to wrap the executeFn within a promise
|
|
1004
|
+
// so we can easily control the end of execution (with finally)
|
|
1005
|
+
return Promise.resolve()
|
|
1006
|
+
.then(() => executeFn(executionArgs))
|
|
1007
|
+
.finally(destroy);
|
|
1049
1008
|
};
|
|
1050
1009
|
};
|
|
1051
1010
|
return createExecution;
|
|
@@ -1056,46 +1015,43 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1056
1015
|
// Custom or original subscribe function
|
|
1057
1016
|
const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || graphql.subscribe;
|
|
1058
1017
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
...argsOrSchema,
|
|
1063
|
-
contextValue: context,
|
|
1064
|
-
}
|
|
1065
|
-
: {
|
|
1066
|
-
schema: argsOrSchema,
|
|
1067
|
-
document: document,
|
|
1068
|
-
rootValue,
|
|
1069
|
-
contextValue: context,
|
|
1070
|
-
variableValues,
|
|
1071
|
-
operationName,
|
|
1072
|
-
fieldResolver,
|
|
1073
|
-
subscribeFieldResolver,
|
|
1074
|
-
};
|
|
1075
|
-
let isIterable = false;
|
|
1076
|
-
// It's important to wrap the subscribeFn within a promise
|
|
1077
|
-
// so we can easily control the end of subscription (with finally)
|
|
1078
|
-
return Promise.resolve()
|
|
1079
|
-
.then(() => subscribeFn(subscriptionArgs))
|
|
1080
|
-
.then((sub) => {
|
|
1081
|
-
if (isAsyncIterable(sub)) {
|
|
1082
|
-
isIterable = true;
|
|
1083
|
-
return tapAsyncIterator(sub, destroy);
|
|
1084
|
-
}
|
|
1085
|
-
return sub;
|
|
1086
|
-
})
|
|
1087
|
-
.finally(() => {
|
|
1088
|
-
if (!isIterable) {
|
|
1089
|
-
destroy();
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1094
|
-
return perform(options.controller);
|
|
1095
|
-
}
|
|
1096
|
-
return contextBuilder(isNotSchema(argsOrSchema)
|
|
1018
|
+
var _a;
|
|
1019
|
+
// Create an subscription context
|
|
1020
|
+
const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
|
|
1097
1021
|
? argsOrSchema.contextValue
|
|
1098
|
-
: contextValue)
|
|
1022
|
+
: contextValue);
|
|
1023
|
+
const subscriptionArgs = isNotSchema(argsOrSchema)
|
|
1024
|
+
? {
|
|
1025
|
+
...argsOrSchema,
|
|
1026
|
+
contextValue: context,
|
|
1027
|
+
}
|
|
1028
|
+
: {
|
|
1029
|
+
schema: argsOrSchema,
|
|
1030
|
+
document: document,
|
|
1031
|
+
rootValue,
|
|
1032
|
+
contextValue: context,
|
|
1033
|
+
variableValues,
|
|
1034
|
+
operationName,
|
|
1035
|
+
fieldResolver,
|
|
1036
|
+
subscribeFieldResolver,
|
|
1037
|
+
};
|
|
1038
|
+
let isIterable = false;
|
|
1039
|
+
// It's important to wrap the subscribeFn within a promise
|
|
1040
|
+
// so we can easily control the end of subscription (with finally)
|
|
1041
|
+
return Promise.resolve()
|
|
1042
|
+
.then(() => subscribeFn(subscriptionArgs))
|
|
1043
|
+
.then((sub) => {
|
|
1044
|
+
if (isAsyncIterable(sub)) {
|
|
1045
|
+
isIterable = true;
|
|
1046
|
+
return tapAsyncIterator(sub, destroy);
|
|
1047
|
+
}
|
|
1048
|
+
return sub;
|
|
1049
|
+
})
|
|
1050
|
+
.finally(() => {
|
|
1051
|
+
if (!isIterable) {
|
|
1052
|
+
destroy();
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1099
1055
|
};
|
|
1100
1056
|
};
|
|
1101
1057
|
return createSubscription;
|
|
@@ -1120,9 +1076,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1120
1076
|
const createApolloSchema = () => {
|
|
1121
1077
|
const sessions = {};
|
|
1122
1078
|
const subscription = createSubscription();
|
|
1123
|
-
function getSession(ctx
|
|
1079
|
+
function getSession(ctx) {
|
|
1124
1080
|
if (!ctx[CONTEXT_ID]) {
|
|
1125
1081
|
ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
|
|
1082
|
+
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1126
1083
|
sessions[ctx[CONTEXT_ID]] = {
|
|
1127
1084
|
count: 0,
|
|
1128
1085
|
session: {
|
|
@@ -1154,22 +1111,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1154
1111
|
operationName: input.operationName,
|
|
1155
1112
|
});
|
|
1156
1113
|
}
|
|
1157
|
-
// Create an execution context
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
.finally(destroy);
|
|
1172
|
-
});
|
|
1114
|
+
// Create an execution context
|
|
1115
|
+
const { context, destroy } = getSession(input.context);
|
|
1116
|
+
// It's important to wrap the executeFn within a promise
|
|
1117
|
+
// so we can easily control the end of execution (with finally)
|
|
1118
|
+
return Promise.resolve()
|
|
1119
|
+
.then(() => graphql.execute({
|
|
1120
|
+
schema,
|
|
1121
|
+
document: input.document,
|
|
1122
|
+
contextValue: context,
|
|
1123
|
+
variableValues: input.variables,
|
|
1124
|
+
rootValue: input.rootValue,
|
|
1125
|
+
operationName: input.operationName,
|
|
1126
|
+
}))
|
|
1127
|
+
.finally(destroy);
|
|
1173
1128
|
},
|
|
1174
1129
|
});
|
|
1175
1130
|
};
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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 module from 'module';
|
|
4
3
|
import { wrapSchema } from '@graphql-tools/wrap';
|
|
5
4
|
import { mergeDeepWith } from 'ramda';
|
|
6
5
|
|
|
@@ -835,23 +834,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
835
834
|
].join(' '));
|
|
836
835
|
}
|
|
837
836
|
|
|
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
837
|
/**
|
|
856
838
|
* @api
|
|
857
839
|
* `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
|
|
@@ -897,14 +879,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
897
879
|
},
|
|
898
880
|
});
|
|
899
881
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
900
|
-
|
|
901
|
-
return ((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext;
|
|
882
|
+
return appContext;
|
|
902
883
|
});
|
|
903
884
|
function createModuleExecutionContextGetter(moduleId) {
|
|
904
885
|
return function moduleExecutionContextGetter() {
|
|
905
|
-
|
|
906
|
-
return (((_a = getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
907
|
-
getModuleContext(moduleId, context));
|
|
886
|
+
return getModuleContext(moduleId, context);
|
|
908
887
|
};
|
|
909
888
|
}
|
|
910
889
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -974,7 +953,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
974
953
|
return getModuleContext(moduleId, sharedContext).injector;
|
|
975
954
|
},
|
|
976
955
|
});
|
|
977
|
-
|
|
956
|
+
return {
|
|
978
957
|
ɵdestroy: once(() => {
|
|
979
958
|
providersToDestroy.forEach(([injector, keyId]) => {
|
|
980
959
|
// If provider was instantiated
|
|
@@ -988,19 +967,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
988
967
|
ɵinjector: operationAppInjector,
|
|
989
968
|
context: sharedContext,
|
|
990
969
|
};
|
|
991
|
-
return {
|
|
992
|
-
...env,
|
|
993
|
-
runWithContext(cb) {
|
|
994
|
-
return runWithAsyncContext({
|
|
995
|
-
getApplicationContext() {
|
|
996
|
-
return appContext;
|
|
997
|
-
},
|
|
998
|
-
getModuleContext(moduleId) {
|
|
999
|
-
return getModuleContext(moduleId, context);
|
|
1000
|
-
},
|
|
1001
|
-
}, cb, env);
|
|
1002
|
-
},
|
|
1003
|
-
};
|
|
1004
970
|
};
|
|
1005
971
|
return contextBuilder;
|
|
1006
972
|
}
|
|
@@ -1010,34 +976,31 @@ function executionCreator({ contextBuilder, }) {
|
|
|
1010
976
|
// Custom or original execute function
|
|
1011
977
|
const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || execute$1;
|
|
1012
978
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
...argsOrSchema,
|
|
1017
|
-
contextValue: context,
|
|
1018
|
-
}
|
|
1019
|
-
: {
|
|
1020
|
-
schema: argsOrSchema,
|
|
1021
|
-
document: document,
|
|
1022
|
-
rootValue,
|
|
1023
|
-
contextValue: context,
|
|
1024
|
-
variableValues,
|
|
1025
|
-
operationName,
|
|
1026
|
-
fieldResolver,
|
|
1027
|
-
typeResolver,
|
|
1028
|
-
};
|
|
1029
|
-
// It's important to wrap the executeFn within a promise
|
|
1030
|
-
// so we can easily control the end of execution (with finally)
|
|
1031
|
-
return Promise.resolve()
|
|
1032
|
-
.then(() => executeFn(executionArgs))
|
|
1033
|
-
.finally(destroy);
|
|
1034
|
-
}
|
|
1035
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1036
|
-
return perform(options.controller);
|
|
1037
|
-
}
|
|
1038
|
-
return contextBuilder(isNotSchema(argsOrSchema)
|
|
979
|
+
var _a;
|
|
980
|
+
// Create an execution context
|
|
981
|
+
const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
|
|
1039
982
|
? argsOrSchema.contextValue
|
|
1040
|
-
: contextValue)
|
|
983
|
+
: contextValue);
|
|
984
|
+
const executionArgs = isNotSchema(argsOrSchema)
|
|
985
|
+
? {
|
|
986
|
+
...argsOrSchema,
|
|
987
|
+
contextValue: context,
|
|
988
|
+
}
|
|
989
|
+
: {
|
|
990
|
+
schema: argsOrSchema,
|
|
991
|
+
document: document,
|
|
992
|
+
rootValue,
|
|
993
|
+
contextValue: context,
|
|
994
|
+
variableValues,
|
|
995
|
+
operationName,
|
|
996
|
+
fieldResolver,
|
|
997
|
+
typeResolver,
|
|
998
|
+
};
|
|
999
|
+
// It's important to wrap the executeFn within a promise
|
|
1000
|
+
// so we can easily control the end of execution (with finally)
|
|
1001
|
+
return Promise.resolve()
|
|
1002
|
+
.then(() => executeFn(executionArgs))
|
|
1003
|
+
.finally(destroy);
|
|
1041
1004
|
};
|
|
1042
1005
|
};
|
|
1043
1006
|
return createExecution;
|
|
@@ -1048,46 +1011,43 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1048
1011
|
// Custom or original subscribe function
|
|
1049
1012
|
const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || subscribe;
|
|
1050
1013
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
...argsOrSchema,
|
|
1055
|
-
contextValue: context,
|
|
1056
|
-
}
|
|
1057
|
-
: {
|
|
1058
|
-
schema: argsOrSchema,
|
|
1059
|
-
document: document,
|
|
1060
|
-
rootValue,
|
|
1061
|
-
contextValue: context,
|
|
1062
|
-
variableValues,
|
|
1063
|
-
operationName,
|
|
1064
|
-
fieldResolver,
|
|
1065
|
-
subscribeFieldResolver,
|
|
1066
|
-
};
|
|
1067
|
-
let isIterable = false;
|
|
1068
|
-
// It's important to wrap the subscribeFn within a promise
|
|
1069
|
-
// so we can easily control the end of subscription (with finally)
|
|
1070
|
-
return Promise.resolve()
|
|
1071
|
-
.then(() => subscribeFn(subscriptionArgs))
|
|
1072
|
-
.then((sub) => {
|
|
1073
|
-
if (isAsyncIterable(sub)) {
|
|
1074
|
-
isIterable = true;
|
|
1075
|
-
return tapAsyncIterator(sub, destroy);
|
|
1076
|
-
}
|
|
1077
|
-
return sub;
|
|
1078
|
-
})
|
|
1079
|
-
.finally(() => {
|
|
1080
|
-
if (!isIterable) {
|
|
1081
|
-
destroy();
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1086
|
-
return perform(options.controller);
|
|
1087
|
-
}
|
|
1088
|
-
return contextBuilder(isNotSchema(argsOrSchema)
|
|
1014
|
+
var _a;
|
|
1015
|
+
// Create an subscription context
|
|
1016
|
+
const { context, ɵdestroy: destroy } = (_a = options === null || options === void 0 ? void 0 : options.controller) !== null && _a !== void 0 ? _a : contextBuilder(isNotSchema(argsOrSchema)
|
|
1089
1017
|
? argsOrSchema.contextValue
|
|
1090
|
-
: contextValue)
|
|
1018
|
+
: contextValue);
|
|
1019
|
+
const subscriptionArgs = isNotSchema(argsOrSchema)
|
|
1020
|
+
? {
|
|
1021
|
+
...argsOrSchema,
|
|
1022
|
+
contextValue: context,
|
|
1023
|
+
}
|
|
1024
|
+
: {
|
|
1025
|
+
schema: argsOrSchema,
|
|
1026
|
+
document: document,
|
|
1027
|
+
rootValue,
|
|
1028
|
+
contextValue: context,
|
|
1029
|
+
variableValues,
|
|
1030
|
+
operationName,
|
|
1031
|
+
fieldResolver,
|
|
1032
|
+
subscribeFieldResolver,
|
|
1033
|
+
};
|
|
1034
|
+
let isIterable = false;
|
|
1035
|
+
// It's important to wrap the subscribeFn within a promise
|
|
1036
|
+
// so we can easily control the end of subscription (with finally)
|
|
1037
|
+
return Promise.resolve()
|
|
1038
|
+
.then(() => subscribeFn(subscriptionArgs))
|
|
1039
|
+
.then((sub) => {
|
|
1040
|
+
if (isAsyncIterable(sub)) {
|
|
1041
|
+
isIterable = true;
|
|
1042
|
+
return tapAsyncIterator(sub, destroy);
|
|
1043
|
+
}
|
|
1044
|
+
return sub;
|
|
1045
|
+
})
|
|
1046
|
+
.finally(() => {
|
|
1047
|
+
if (!isIterable) {
|
|
1048
|
+
destroy();
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1091
1051
|
};
|
|
1092
1052
|
};
|
|
1093
1053
|
return createSubscription;
|
|
@@ -1112,9 +1072,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1112
1072
|
const createApolloSchema = () => {
|
|
1113
1073
|
const sessions = {};
|
|
1114
1074
|
const subscription = createSubscription();
|
|
1115
|
-
function getSession(ctx
|
|
1075
|
+
function getSession(ctx) {
|
|
1116
1076
|
if (!ctx[CONTEXT_ID]) {
|
|
1117
1077
|
ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
|
|
1078
|
+
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1118
1079
|
sessions[ctx[CONTEXT_ID]] = {
|
|
1119
1080
|
count: 0,
|
|
1120
1081
|
session: {
|
|
@@ -1146,22 +1107,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1146
1107
|
operationName: input.operationName,
|
|
1147
1108
|
});
|
|
1148
1109
|
}
|
|
1149
|
-
// Create an execution context
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
.finally(destroy);
|
|
1164
|
-
});
|
|
1110
|
+
// Create an execution context
|
|
1111
|
+
const { context, destroy } = getSession(input.context);
|
|
1112
|
+
// It's important to wrap the executeFn within a promise
|
|
1113
|
+
// so we can easily control the end of execution (with finally)
|
|
1114
|
+
return Promise.resolve()
|
|
1115
|
+
.then(() => execute$1({
|
|
1116
|
+
schema,
|
|
1117
|
+
document: input.document,
|
|
1118
|
+
contextValue: context,
|
|
1119
|
+
variableValues: input.variables,
|
|
1120
|
+
rootValue: input.rootValue,
|
|
1121
|
+
operationName: input.operationName,
|
|
1122
|
+
}))
|
|
1123
|
+
.finally(destroy);
|
|
1165
1124
|
},
|
|
1166
1125
|
});
|
|
1167
1126
|
};
|
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-20260116090853-00f0aa9d636b258ea952ebd5f8d5ca0416ec8461",
|
|
4
4
|
"description": "Create reusable, maintainable, testable and extendable GraphQL modules",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -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;
|