graphql-modules 3.1.0-alpha-20260116120626-0749090abe9d2dc233c8dc7d3ca6c7e01e0d7e60 → 3.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/context.d.ts +1 -4
- package/index.js +79 -107
- package/index.mjs +79 -103
- package/package.json +1 -7
- package/async-context.browser.mjs +0 -7
- package/async-context.node.cjs +0 -14
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 async_context = require('#async-context');
|
|
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 async_context__default = /*#__PURE__*/_interopDefaultLegacy(async_context);
|
|
14
|
-
|
|
15
10
|
const ERROR_ORIGINAL_ERROR = 'diOriginalError';
|
|
16
11
|
function getOriginalError(error) {
|
|
17
12
|
return error[ERROR_ORIGINAL_ERROR];
|
|
@@ -888,14 +883,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
888
883
|
},
|
|
889
884
|
});
|
|
890
885
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
891
|
-
|
|
892
|
-
return (((_a = async_context__default["default"].getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext);
|
|
886
|
+
return appContext;
|
|
893
887
|
});
|
|
894
888
|
function createModuleExecutionContextGetter(moduleId) {
|
|
895
889
|
return function moduleExecutionContextGetter() {
|
|
896
|
-
|
|
897
|
-
return (((_a = async_context__default["default"].getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
898
|
-
getModuleContext(moduleId, context));
|
|
890
|
+
return getModuleContext(moduleId, context);
|
|
899
891
|
};
|
|
900
892
|
}
|
|
901
893
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -965,7 +957,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
965
957
|
return getModuleContext(moduleId, sharedContext).injector;
|
|
966
958
|
},
|
|
967
959
|
});
|
|
968
|
-
|
|
960
|
+
return {
|
|
969
961
|
ɵdestroy: once(() => {
|
|
970
962
|
providersToDestroy.forEach(([injector, keyId]) => {
|
|
971
963
|
// If provider was instantiated
|
|
@@ -979,19 +971,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
979
971
|
ɵinjector: operationAppInjector,
|
|
980
972
|
context: sharedContext,
|
|
981
973
|
};
|
|
982
|
-
return {
|
|
983
|
-
...env,
|
|
984
|
-
runWithContext(cb) {
|
|
985
|
-
return async_context__default["default"].runWithAsyncContext({
|
|
986
|
-
getApplicationContext() {
|
|
987
|
-
return appContext;
|
|
988
|
-
},
|
|
989
|
-
getModuleContext(moduleId) {
|
|
990
|
-
return getModuleContext(moduleId, context);
|
|
991
|
-
},
|
|
992
|
-
}, cb, env);
|
|
993
|
-
},
|
|
994
|
-
};
|
|
995
974
|
};
|
|
996
975
|
return contextBuilder;
|
|
997
976
|
}
|
|
@@ -1001,34 +980,31 @@ function executionCreator({ contextBuilder, }) {
|
|
|
1001
980
|
// Custom or original execute function
|
|
1002
981
|
const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || graphql.execute;
|
|
1003
982
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
...argsOrSchema,
|
|
1008
|
-
contextValue: context,
|
|
1009
|
-
}
|
|
1010
|
-
: {
|
|
1011
|
-
schema: argsOrSchema,
|
|
1012
|
-
document: document,
|
|
1013
|
-
rootValue,
|
|
1014
|
-
contextValue: context,
|
|
1015
|
-
variableValues,
|
|
1016
|
-
operationName,
|
|
1017
|
-
fieldResolver,
|
|
1018
|
-
typeResolver,
|
|
1019
|
-
};
|
|
1020
|
-
// It's important to wrap the executeFn within a promise
|
|
1021
|
-
// so we can easily control the end of execution (with finally)
|
|
1022
|
-
return Promise.resolve()
|
|
1023
|
-
.then(() => executeFn(executionArgs))
|
|
1024
|
-
.finally(destroy);
|
|
1025
|
-
}
|
|
1026
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1027
|
-
return perform(options.controller);
|
|
1028
|
-
}
|
|
1029
|
-
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)
|
|
1030
986
|
? argsOrSchema.contextValue
|
|
1031
|
-
: 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);
|
|
1032
1008
|
};
|
|
1033
1009
|
};
|
|
1034
1010
|
return createExecution;
|
|
@@ -1039,46 +1015,43 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1039
1015
|
// Custom or original subscribe function
|
|
1040
1016
|
const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || graphql.subscribe;
|
|
1041
1017
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
...argsOrSchema,
|
|
1046
|
-
contextValue: context,
|
|
1047
|
-
}
|
|
1048
|
-
: {
|
|
1049
|
-
schema: argsOrSchema,
|
|
1050
|
-
document: document,
|
|
1051
|
-
rootValue,
|
|
1052
|
-
contextValue: context,
|
|
1053
|
-
variableValues,
|
|
1054
|
-
operationName,
|
|
1055
|
-
fieldResolver,
|
|
1056
|
-
subscribeFieldResolver,
|
|
1057
|
-
};
|
|
1058
|
-
let isIterable = false;
|
|
1059
|
-
// It's important to wrap the subscribeFn within a promise
|
|
1060
|
-
// so we can easily control the end of subscription (with finally)
|
|
1061
|
-
return Promise.resolve()
|
|
1062
|
-
.then(() => subscribeFn(subscriptionArgs))
|
|
1063
|
-
.then((sub) => {
|
|
1064
|
-
if (isAsyncIterable(sub)) {
|
|
1065
|
-
isIterable = true;
|
|
1066
|
-
return tapAsyncIterator(sub, destroy);
|
|
1067
|
-
}
|
|
1068
|
-
return sub;
|
|
1069
|
-
})
|
|
1070
|
-
.finally(() => {
|
|
1071
|
-
if (!isIterable) {
|
|
1072
|
-
destroy();
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1077
|
-
return perform(options.controller);
|
|
1078
|
-
}
|
|
1079
|
-
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)
|
|
1080
1021
|
? argsOrSchema.contextValue
|
|
1081
|
-
: 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
|
+
});
|
|
1082
1055
|
};
|
|
1083
1056
|
};
|
|
1084
1057
|
return createSubscription;
|
|
@@ -1103,9 +1076,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1103
1076
|
const createApolloSchema = () => {
|
|
1104
1077
|
const sessions = {};
|
|
1105
1078
|
const subscription = createSubscription();
|
|
1106
|
-
function getSession(ctx
|
|
1079
|
+
function getSession(ctx) {
|
|
1107
1080
|
if (!ctx[CONTEXT_ID]) {
|
|
1108
1081
|
ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
|
|
1082
|
+
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1109
1083
|
sessions[ctx[CONTEXT_ID]] = {
|
|
1110
1084
|
count: 0,
|
|
1111
1085
|
session: {
|
|
@@ -1137,22 +1111,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1137
1111
|
operationName: input.operationName,
|
|
1138
1112
|
});
|
|
1139
1113
|
}
|
|
1140
|
-
// Create an execution context
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
.finally(destroy);
|
|
1155
|
-
});
|
|
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);
|
|
1156
1128
|
},
|
|
1157
1129
|
});
|
|
1158
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 async_context from '#async-context';
|
|
4
3
|
import { wrapSchema } from '@graphql-tools/wrap';
|
|
5
4
|
import { mergeDeepWith } from 'ramda';
|
|
6
5
|
|
|
@@ -880,14 +879,11 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
880
879
|
},
|
|
881
880
|
});
|
|
882
881
|
appInjector.setExecutionContextGetter(function executionContextGetter() {
|
|
883
|
-
|
|
884
|
-
return (((_a = async_context.getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getApplicationContext()) || appContext);
|
|
882
|
+
return appContext;
|
|
885
883
|
});
|
|
886
884
|
function createModuleExecutionContextGetter(moduleId) {
|
|
887
885
|
return function moduleExecutionContextGetter() {
|
|
888
|
-
|
|
889
|
-
return (((_a = async_context.getAsyncContext()) === null || _a === void 0 ? void 0 : _a.getModuleContext(moduleId)) ||
|
|
890
|
-
getModuleContext(moduleId, context));
|
|
886
|
+
return getModuleContext(moduleId, context);
|
|
891
887
|
};
|
|
892
888
|
}
|
|
893
889
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -957,7 +953,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
957
953
|
return getModuleContext(moduleId, sharedContext).injector;
|
|
958
954
|
},
|
|
959
955
|
});
|
|
960
|
-
|
|
956
|
+
return {
|
|
961
957
|
ɵdestroy: once(() => {
|
|
962
958
|
providersToDestroy.forEach(([injector, keyId]) => {
|
|
963
959
|
// If provider was instantiated
|
|
@@ -971,19 +967,6 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
971
967
|
ɵinjector: operationAppInjector,
|
|
972
968
|
context: sharedContext,
|
|
973
969
|
};
|
|
974
|
-
return {
|
|
975
|
-
...env,
|
|
976
|
-
runWithContext(cb) {
|
|
977
|
-
return async_context.runWithAsyncContext({
|
|
978
|
-
getApplicationContext() {
|
|
979
|
-
return appContext;
|
|
980
|
-
},
|
|
981
|
-
getModuleContext(moduleId) {
|
|
982
|
-
return getModuleContext(moduleId, context);
|
|
983
|
-
},
|
|
984
|
-
}, cb, env);
|
|
985
|
-
},
|
|
986
|
-
};
|
|
987
970
|
};
|
|
988
971
|
return contextBuilder;
|
|
989
972
|
}
|
|
@@ -993,34 +976,31 @@ function executionCreator({ contextBuilder, }) {
|
|
|
993
976
|
// Custom or original execute function
|
|
994
977
|
const executeFn = (options === null || options === void 0 ? void 0 : options.execute) || execute$1;
|
|
995
978
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) => {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
...argsOrSchema,
|
|
1000
|
-
contextValue: context,
|
|
1001
|
-
}
|
|
1002
|
-
: {
|
|
1003
|
-
schema: argsOrSchema,
|
|
1004
|
-
document: document,
|
|
1005
|
-
rootValue,
|
|
1006
|
-
contextValue: context,
|
|
1007
|
-
variableValues,
|
|
1008
|
-
operationName,
|
|
1009
|
-
fieldResolver,
|
|
1010
|
-
typeResolver,
|
|
1011
|
-
};
|
|
1012
|
-
// It's important to wrap the executeFn within a promise
|
|
1013
|
-
// so we can easily control the end of execution (with finally)
|
|
1014
|
-
return Promise.resolve()
|
|
1015
|
-
.then(() => executeFn(executionArgs))
|
|
1016
|
-
.finally(destroy);
|
|
1017
|
-
}
|
|
1018
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1019
|
-
return perform(options.controller);
|
|
1020
|
-
}
|
|
1021
|
-
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)
|
|
1022
982
|
? argsOrSchema.contextValue
|
|
1023
|
-
: 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);
|
|
1024
1004
|
};
|
|
1025
1005
|
};
|
|
1026
1006
|
return createExecution;
|
|
@@ -1031,46 +1011,43 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1031
1011
|
// Custom or original subscribe function
|
|
1032
1012
|
const subscribeFn = (options === null || options === void 0 ? void 0 : options.subscribe) || subscribe;
|
|
1033
1013
|
return (argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) => {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
...argsOrSchema,
|
|
1038
|
-
contextValue: context,
|
|
1039
|
-
}
|
|
1040
|
-
: {
|
|
1041
|
-
schema: argsOrSchema,
|
|
1042
|
-
document: document,
|
|
1043
|
-
rootValue,
|
|
1044
|
-
contextValue: context,
|
|
1045
|
-
variableValues,
|
|
1046
|
-
operationName,
|
|
1047
|
-
fieldResolver,
|
|
1048
|
-
subscribeFieldResolver,
|
|
1049
|
-
};
|
|
1050
|
-
let isIterable = false;
|
|
1051
|
-
// It's important to wrap the subscribeFn within a promise
|
|
1052
|
-
// so we can easily control the end of subscription (with finally)
|
|
1053
|
-
return Promise.resolve()
|
|
1054
|
-
.then(() => subscribeFn(subscriptionArgs))
|
|
1055
|
-
.then((sub) => {
|
|
1056
|
-
if (isAsyncIterable(sub)) {
|
|
1057
|
-
isIterable = true;
|
|
1058
|
-
return tapAsyncIterator(sub, destroy);
|
|
1059
|
-
}
|
|
1060
|
-
return sub;
|
|
1061
|
-
})
|
|
1062
|
-
.finally(() => {
|
|
1063
|
-
if (!isIterable) {
|
|
1064
|
-
destroy();
|
|
1065
|
-
}
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
if (options === null || options === void 0 ? void 0 : options.controller) {
|
|
1069
|
-
return perform(options.controller);
|
|
1070
|
-
}
|
|
1071
|
-
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)
|
|
1072
1017
|
? argsOrSchema.contextValue
|
|
1073
|
-
: 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
|
+
});
|
|
1074
1051
|
};
|
|
1075
1052
|
};
|
|
1076
1053
|
return createSubscription;
|
|
@@ -1095,9 +1072,10 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1095
1072
|
const createApolloSchema = () => {
|
|
1096
1073
|
const sessions = {};
|
|
1097
1074
|
const subscription = createSubscription();
|
|
1098
|
-
function getSession(ctx
|
|
1075
|
+
function getSession(ctx) {
|
|
1099
1076
|
if (!ctx[CONTEXT_ID]) {
|
|
1100
1077
|
ctx[CONTEXT_ID] = uniqueId((id) => !sessions[id]);
|
|
1078
|
+
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1101
1079
|
sessions[ctx[CONTEXT_ID]] = {
|
|
1102
1080
|
count: 0,
|
|
1103
1081
|
session: {
|
|
@@ -1129,22 +1107,20 @@ function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }) {
|
|
|
1129
1107
|
operationName: input.operationName,
|
|
1130
1108
|
});
|
|
1131
1109
|
}
|
|
1132
|
-
// Create an execution context
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
.finally(destroy);
|
|
1147
|
-
});
|
|
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);
|
|
1148
1124
|
},
|
|
1149
1125
|
});
|
|
1150
1126
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-modules",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Create reusable, maintainable, testable and extendable GraphQL modules",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -37,11 +37,5 @@
|
|
|
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
|
-
}
|
|
46
40
|
}
|
|
47
41
|
}
|
package/async-context.node.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
};
|