graphql-modules 3.0.0-alpha-20220929080337-2b91100e → 3.0.0-alpha-20231018162945-f59bbaea
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/apollo.d.ts +17 -9
- package/application/application.d.ts +2 -4
- package/application/context.d.ts +1 -1
- package/application/execution-context-async-local-storage.d.ts +10 -0
- package/application/execution-context-hooks.d.ts +9 -0
- package/application/execution-context.d.ts +6 -18
- package/application/execution-context.interface.d.ts +4 -0
- package/application/types.d.ts +6 -29
- package/di/decorators.d.ts +3 -1
- package/di/forward-ref.d.ts +1 -1
- package/di/injector.d.ts +1 -1
- package/di/providers.d.ts +2 -2
- package/di/resolution.d.ts +2 -2
- package/index.js +112 -166
- package/index.mjs +113 -167
- package/module/factory.d.ts +2 -2
- package/module/metadata.d.ts +1 -1
- package/module/types.d.ts +2 -2
- package/package.json +3 -4
- package/shared/middleware.d.ts +3 -3
- package/shared/types.d.ts +8 -8
- package/testing/test-module.d.ts +2 -2
package/application/apollo.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { ExecutionContextBuilder } from './context';
|
|
1
|
+
import { DocumentNode, ExecutionResult, GraphQLSchema } from 'graphql';
|
|
3
2
|
import { Application } from './types';
|
|
4
3
|
export interface ApolloRequestContext {
|
|
5
4
|
document: DocumentNode;
|
|
@@ -12,11 +11,20 @@ export interface ApolloRequestContext {
|
|
|
12
11
|
} | null;
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
|
-
export
|
|
14
|
+
export interface ApolloGatewayLoadResult {
|
|
15
|
+
executor: ApolloExecutor;
|
|
16
|
+
}
|
|
17
|
+
export type ApolloExecutor = (requestContext: ApolloRequestContext) => Promise<ExecutionResult>;
|
|
18
|
+
export interface ApolloGatewayInterface {
|
|
19
|
+
onSchemaLoadOrUpdate(callback: (schemaContext: {
|
|
20
|
+
apiSchema: GraphQLSchema;
|
|
21
|
+
coreSupergraphSdl: string;
|
|
22
|
+
}) => void): () => void;
|
|
23
|
+
load(): Promise<ApolloGatewayLoadResult>;
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare function apolloGatewayCreator({ schema, typeDefs, createExecution, }: {
|
|
27
|
+
schema: Application['schema'];
|
|
28
|
+
typeDefs: Application['typeDefs'];
|
|
16
29
|
createExecution: Application['createExecution'];
|
|
17
|
-
}): Application['
|
|
18
|
-
export declare function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }: {
|
|
19
|
-
createSubscription: Application['createSubscription'];
|
|
20
|
-
contextBuilder: ExecutionContextBuilder;
|
|
21
|
-
schema: GraphQLSchema;
|
|
22
|
-
}): () => GraphQLSchema;
|
|
30
|
+
}): Application['createApolloGateway'];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResolvedModule } from '../module/factory';
|
|
2
2
|
import { ID } from '../shared/types';
|
|
3
3
|
import { ApplicationConfig, Application } from './types';
|
|
4
|
-
export
|
|
4
|
+
export type ModulesMap = Map<ID, ResolvedModule>;
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
@@ -16,7 +16,6 @@ export interface InternalAppContext {
|
|
|
16
16
|
*
|
|
17
17
|
* ```typescript
|
|
18
18
|
* import { createApplication } from 'graphql-modules';
|
|
19
|
-
* import { createHook, executionAsyncId } from 'async_hooks';
|
|
20
19
|
* import { usersModule } from './users';
|
|
21
20
|
* import { postsModule } from './posts';
|
|
22
21
|
* import { commentsModule } from './comments';
|
|
@@ -26,8 +25,7 @@ export interface InternalAppContext {
|
|
|
26
25
|
* usersModule,
|
|
27
26
|
* postsModule,
|
|
28
27
|
* commentsModule
|
|
29
|
-
* ]
|
|
30
|
-
* executionContext: { createHook, executionAsyncId },
|
|
28
|
+
* ]
|
|
31
29
|
* })
|
|
32
30
|
* ```
|
|
33
31
|
*/
|
package/application/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Injector, ReflectiveInjector } from '../di';
|
|
2
2
|
import { ResolvedProvider } from '../di/resolution';
|
|
3
3
|
import type { InternalAppContext, ModulesMap } from './application';
|
|
4
|
-
export
|
|
4
|
+
export type ExecutionContextBuilder<TContext extends {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
} = {}> = (context: TContext) => {
|
|
7
7
|
context: InternalAppContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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,20 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
createHook(config: {
|
|
4
|
-
init(asyncId: number, _: string, triggerAsyncId: number): void;
|
|
5
|
-
destroy(asyncId: number): void;
|
|
6
|
-
}): void;
|
|
7
|
-
}
|
|
8
|
-
export interface ExecutionContextPicker {
|
|
9
|
-
getModuleContext(moduleId: string): GraphQLModules.ModuleContext;
|
|
10
|
-
getApplicationContext(): GraphQLModules.AppContext;
|
|
11
|
-
}
|
|
1
|
+
import * as Hooks from './execution-context-hooks';
|
|
2
|
+
export type { ExecutionContextPicker } from './execution-context.interface';
|
|
12
3
|
export declare const executionContext: {
|
|
13
|
-
create(picker: ExecutionContextPicker): () => void;
|
|
14
|
-
getModuleContext:
|
|
15
|
-
getApplicationContext:
|
|
4
|
+
create(picker: import("./execution-context.interface").ExecutionContextPicker): () => void;
|
|
5
|
+
getModuleContext: (moduleId: string) => GraphQLModules.ModuleContext;
|
|
6
|
+
getApplicationContext: () => GraphQLModules.AppContext;
|
|
16
7
|
};
|
|
17
|
-
export declare
|
|
18
|
-
export declare function assertExecutionContext(): void | never;
|
|
19
|
-
export declare function getExecutionContextStore(): Map<number, ExecutionContextPicker>;
|
|
20
|
-
export declare function getExecutionContextDependencyStore(): Map<number, Set<number>>;
|
|
8
|
+
export declare const enableExecutionContext: typeof Hooks.enableExecutionContext;
|
package/application/types.d.ts
CHANGED
|
@@ -2,13 +2,12 @@ import { execute, subscribe, DocumentNode, GraphQLSchema, ExecutionResult } from
|
|
|
2
2
|
import type { Provider, Injector } from '../di';
|
|
3
3
|
import type { Resolvers, Module, MockedModule } from '../module/types';
|
|
4
4
|
import type { MiddlewareMap } from '../shared/middleware';
|
|
5
|
-
import type {
|
|
6
|
-
import type { ApolloRequestContext } from './apollo';
|
|
5
|
+
import type { ApolloGatewayInterface, ApolloRequestContext } from './apollo';
|
|
7
6
|
import type { Single } from '../shared/types';
|
|
8
7
|
import type { InternalAppContext } from './application';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
8
|
+
type Execution = typeof execute;
|
|
9
|
+
type Subscription = typeof subscribe;
|
|
10
|
+
export type ApolloExecutor = (requestContext: ApolloRequestContext) => Promise<ExecutionResult>;
|
|
12
11
|
export interface MockedApplication extends Application {
|
|
13
12
|
replaceModule(mockedModule: MockedModule): MockedApplication;
|
|
14
13
|
addProviders(providers: ApplicationConfig['providers']): MockedApplication;
|
|
@@ -57,16 +56,9 @@ export interface Application {
|
|
|
57
56
|
execute?: typeof execute;
|
|
58
57
|
controller?: OperationController;
|
|
59
58
|
}): Execution;
|
|
60
|
-
|
|
61
|
-
* @deprecated Use `createApolloExecutor`, `createExecution` and `createSubscription` methods instead.
|
|
62
|
-
*/
|
|
63
|
-
createSchemaForApollo(): GraphQLSchema;
|
|
64
|
-
/**
|
|
65
|
-
* Experimental
|
|
66
|
-
*/
|
|
67
|
-
createApolloExecutor(options?: {
|
|
59
|
+
createApolloGateway(options?: {
|
|
68
60
|
controller?: OperationController;
|
|
69
|
-
}):
|
|
61
|
+
}): ApolloGatewayInterface;
|
|
70
62
|
/**
|
|
71
63
|
* @internal
|
|
72
64
|
*/
|
|
@@ -127,20 +119,5 @@ export interface ApplicationConfig {
|
|
|
127
119
|
typeDefs: DocumentNode[];
|
|
128
120
|
resolvers: Record<string, any>[];
|
|
129
121
|
}): GraphQLSchema;
|
|
130
|
-
/**
|
|
131
|
-
* Enables ExecutionContext
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
*
|
|
135
|
-
* ```typescript
|
|
136
|
-
* import { createHook, executionAsyncId } from 'async_hooks';
|
|
137
|
-
*
|
|
138
|
-
* const app = createApplication({
|
|
139
|
-
* modules: [],
|
|
140
|
-
* executionContext: { createHook, executionAsyncId }
|
|
141
|
-
* });
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
executionContext: ExecutionContextConfig | false;
|
|
145
122
|
}
|
|
146
123
|
export {};
|
package/di/decorators.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Type, ProviderOptions, InjectionToken } from './providers';
|
|
2
2
|
import { Injector } from './injector';
|
|
3
3
|
export declare function Injectable(options?: ProviderOptions): ClassDecorator;
|
|
4
|
+
type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
4
5
|
export declare function Optional(): ParameterDecorator;
|
|
5
6
|
export declare function Inject(type: Type<any> | InjectionToken<any>): ParameterDecorator;
|
|
6
|
-
export
|
|
7
|
+
export type ExecutionContext = {
|
|
7
8
|
injector: Injector;
|
|
8
9
|
} & GraphQLModules.ModuleContext;
|
|
9
10
|
export declare function ExecutionContext(): PropertyDecorator;
|
|
11
|
+
export {};
|
package/di/forward-ref.d.ts
CHANGED
package/di/injector.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Type, InjectionToken, Provider } from './providers';
|
|
|
2
2
|
import { ResolvedProvider, GlobalProviderMap } from './resolution';
|
|
3
3
|
import { Key } from './registry';
|
|
4
4
|
import { ExecutionContext } from './decorators';
|
|
5
|
-
|
|
5
|
+
type ExecutionContextGetter = () => ExecutionContext | never;
|
|
6
6
|
export declare abstract class Injector {
|
|
7
7
|
abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: any): T;
|
|
8
8
|
}
|
package/di/providers.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface ValueProvider<T> extends BaseProvider<T> {
|
|
|
18
18
|
export interface ClassProvider<T> extends BaseProvider<T> {
|
|
19
19
|
useClass: Type<T>;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type Factory<T> = (...args: any[]) => T;
|
|
22
22
|
export interface FactoryProvider<T> extends BaseProvider<T> {
|
|
23
23
|
useFactory: Factory<T>;
|
|
24
24
|
deps?: any[];
|
|
@@ -28,7 +28,7 @@ export interface BaseProvider<T> extends ProviderOptions {
|
|
|
28
28
|
}
|
|
29
29
|
export interface TypeProvider<T> extends Type<T> {
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export type Provider<T = any> = TypeProvider<T> | ValueProvider<T> | ClassProvider<T> | FactoryProvider<T>;
|
|
32
32
|
export interface ProviderOptions {
|
|
33
33
|
scope?: Scope;
|
|
34
34
|
executionContextIn?: Array<string | symbol>;
|
package/di/resolution.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Provider, ValueProvider, ClassProvider, FactoryProvider } from './providers';
|
|
2
2
|
import { Key } from './registry';
|
|
3
3
|
import { ReflectiveInjector } from './injector';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type NormalizedProvider<T = any> = ValueProvider<T> | ClassProvider<T> | FactoryProvider<T>;
|
|
5
|
+
export type GlobalProviderMap = {
|
|
6
6
|
has(key: Key['id']): boolean;
|
|
7
7
|
get(key: Key['id']): ReflectiveInjector;
|
|
8
8
|
};
|
package/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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');
|
|
6
7
|
const graphql = require('graphql');
|
|
7
|
-
const wrap = require('@graphql-tools/wrap');
|
|
8
8
|
const ramda = require('ramda');
|
|
9
9
|
|
|
10
10
|
const ERROR_ORIGINAL_ERROR = 'diOriginalError';
|
|
@@ -174,6 +174,85 @@ function isFactoryProvider(provider) {
|
|
|
174
174
|
return typeof provider.useFactory !== 'undefined';
|
|
175
175
|
}
|
|
176
176
|
|
|
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
|
+
|
|
177
256
|
function ensureReflect() {
|
|
178
257
|
if (!(Reflect && Reflect.getOwnMetadata)) {
|
|
179
258
|
throw 'reflect-metadata shim is required when using class decorators';
|
|
@@ -183,6 +262,7 @@ function Injectable(options) {
|
|
|
183
262
|
return (target) => {
|
|
184
263
|
var _a;
|
|
185
264
|
ensureReflect();
|
|
265
|
+
enableExecutionContext$1();
|
|
186
266
|
const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
|
|
187
267
|
const existingMeta = readInjectableMetadata(target);
|
|
188
268
|
const meta = {
|
|
@@ -769,11 +849,6 @@ function share(factory) {
|
|
|
769
849
|
return cached;
|
|
770
850
|
};
|
|
771
851
|
}
|
|
772
|
-
function uniqueId(isNotUsed) {
|
|
773
|
-
let id;
|
|
774
|
-
while (!isNotUsed((id = Math.random().toString(16).substr(2)))) { }
|
|
775
|
-
return id;
|
|
776
|
-
}
|
|
777
852
|
function isNotSchema(obj) {
|
|
778
853
|
return obj instanceof graphql.GraphQLSchema === false;
|
|
779
854
|
}
|
|
@@ -854,77 +929,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
854
929
|
*/
|
|
855
930
|
const CONTEXT = new InjectionToken('context');
|
|
856
931
|
|
|
857
|
-
const executionContextStore = new Map();
|
|
858
|
-
const executionContextDependencyStore = new Map();
|
|
859
|
-
let executionAsyncId = () => 0;
|
|
860
|
-
function destroyContextAndItsChildren(id) {
|
|
861
|
-
if (executionContextStore.has(id)) {
|
|
862
|
-
executionContextStore.delete(id);
|
|
863
|
-
}
|
|
864
|
-
const deps = executionContextDependencyStore.get(id);
|
|
865
|
-
if (deps) {
|
|
866
|
-
for (const dep of deps) {
|
|
867
|
-
destroyContextAndItsChildren(dep);
|
|
868
|
-
}
|
|
869
|
-
executionContextDependencyStore.delete(id);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
let executionContextEnabled = false;
|
|
873
|
-
const executionContext = {
|
|
874
|
-
create(picker) {
|
|
875
|
-
if (!executionContextEnabled) {
|
|
876
|
-
return function destroyContextNoop() {
|
|
877
|
-
// noop
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
const id = executionAsyncId();
|
|
881
|
-
executionContextStore.set(id, picker);
|
|
882
|
-
return function destroyContext() {
|
|
883
|
-
destroyContextAndItsChildren(id);
|
|
884
|
-
};
|
|
885
|
-
},
|
|
886
|
-
getModuleContext(moduleId) {
|
|
887
|
-
assertExecutionContext();
|
|
888
|
-
const picker = executionContextStore.get(executionAsyncId());
|
|
889
|
-
return picker.getModuleContext(moduleId);
|
|
890
|
-
},
|
|
891
|
-
getApplicationContext() {
|
|
892
|
-
assertExecutionContext();
|
|
893
|
-
const picker = executionContextStore.get(executionAsyncId());
|
|
894
|
-
return picker.getApplicationContext();
|
|
895
|
-
},
|
|
896
|
-
};
|
|
897
|
-
function enableExecutionContext(config) {
|
|
898
|
-
if (!executionContextEnabled) {
|
|
899
|
-
config.createHook({
|
|
900
|
-
init(asyncId, _, triggerAsyncId) {
|
|
901
|
-
var _a;
|
|
902
|
-
// Store same context data for child async resources
|
|
903
|
-
const ctx = executionContextStore.get(triggerAsyncId);
|
|
904
|
-
if (ctx) {
|
|
905
|
-
const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
|
|
906
|
-
.set(triggerAsyncId, new Set())
|
|
907
|
-
.get(triggerAsyncId);
|
|
908
|
-
dependencies.add(asyncId);
|
|
909
|
-
executionContextStore.set(asyncId, ctx);
|
|
910
|
-
}
|
|
911
|
-
},
|
|
912
|
-
destroy(asyncId) {
|
|
913
|
-
if (executionContextStore.has(asyncId)) {
|
|
914
|
-
executionContextStore.delete(asyncId);
|
|
915
|
-
}
|
|
916
|
-
},
|
|
917
|
-
});
|
|
918
|
-
executionAsyncId = config.executionAsyncId;
|
|
919
|
-
executionContextEnabled = true;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
function assertExecutionContext() {
|
|
923
|
-
if (!executionContextEnabled) {
|
|
924
|
-
throw new Error('Execution Context is not enabled. Please set `executionContext` option in `createApplication`');
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
932
|
function createContextBuilder({ appInjector, modulesMap, appLevelOperationProviders, singletonGlobalProvidersMap, operationGlobalProvidersMap, }) {
|
|
929
933
|
// This is very critical. It creates an execution context.
|
|
930
934
|
// It has to run on every operation.
|
|
@@ -952,10 +956,10 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
952
956
|
return modulesMap.get(moduleId).injector;
|
|
953
957
|
},
|
|
954
958
|
});
|
|
955
|
-
appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
|
|
959
|
+
appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
|
|
956
960
|
function createModuleExecutionContextGetter(moduleId) {
|
|
957
961
|
return function moduleExecutionContextGetter() {
|
|
958
|
-
return executionContext.getModuleContext(moduleId);
|
|
962
|
+
return executionContext$2.getModuleContext(moduleId);
|
|
959
963
|
};
|
|
960
964
|
}
|
|
961
965
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -969,7 +973,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
969
973
|
return getModuleContext(moduleId, context);
|
|
970
974
|
},
|
|
971
975
|
};
|
|
972
|
-
const destroyExecutionContext = executionContext.create(executionContextPicker);
|
|
976
|
+
const destroyExecutionContext = executionContext$2.create(executionContextPicker);
|
|
973
977
|
// As the name of the Injector says, it's an Operation scoped Injector
|
|
974
978
|
// Application level
|
|
975
979
|
// Operation scoped - means it's created and destroyed on every GraphQL Operation
|
|
@@ -1135,78 +1139,33 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1135
1139
|
return createSubscription;
|
|
1136
1140
|
}
|
|
1137
1141
|
|
|
1138
|
-
|
|
1139
|
-
function
|
|
1140
|
-
return function createApolloExecutor(options) {
|
|
1142
|
+
function apolloGatewayCreator({ schema, typeDefs, createExecution, }) {
|
|
1143
|
+
return function createApolloGateway(options) {
|
|
1141
1144
|
const executor = createExecution(options);
|
|
1142
|
-
return
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1161
|
-
sessions[ctx[CONTEXT_ID]] = {
|
|
1162
|
-
count: 0,
|
|
1163
|
-
session: {
|
|
1164
|
-
context,
|
|
1165
|
-
destroy() {
|
|
1166
|
-
if (--sessions[ctx[CONTEXT_ID]].count === 0) {
|
|
1167
|
-
destroy();
|
|
1168
|
-
delete sessions[ctx[CONTEXT_ID]];
|
|
1169
|
-
delete ctx[CONTEXT_ID];
|
|
1170
|
-
}
|
|
1171
|
-
},
|
|
1145
|
+
return {
|
|
1146
|
+
onSchemaLoadOrUpdate(callback) {
|
|
1147
|
+
callback({
|
|
1148
|
+
apiSchema: schema,
|
|
1149
|
+
coreSupergraphSdl: graphql.print(graphql.concatAST(typeDefs)),
|
|
1150
|
+
});
|
|
1151
|
+
return () => { };
|
|
1152
|
+
},
|
|
1153
|
+
async load() {
|
|
1154
|
+
return {
|
|
1155
|
+
async executor(requestContext) {
|
|
1156
|
+
return executor({
|
|
1157
|
+
schema: requestContext.schema,
|
|
1158
|
+
document: requestContext.document,
|
|
1159
|
+
operationName: requestContext.operationName,
|
|
1160
|
+
variableValues: requestContext.request.variables,
|
|
1161
|
+
contextValue: requestContext.context,
|
|
1162
|
+
});
|
|
1172
1163
|
},
|
|
1173
1164
|
};
|
|
1174
|
-
}
|
|
1175
|
-
sessions[ctx[CONTEXT_ID]].count++;
|
|
1176
|
-
return sessions[ctx[CONTEXT_ID]].session;
|
|
1177
|
-
}
|
|
1178
|
-
return wrap.wrapSchema({
|
|
1179
|
-
schema,
|
|
1180
|
-
batch: true,
|
|
1181
|
-
executor(input) {
|
|
1182
|
-
if (input.operationType === 'subscription') {
|
|
1183
|
-
return subscription({
|
|
1184
|
-
schema,
|
|
1185
|
-
document: input.document,
|
|
1186
|
-
variableValues: input.variables,
|
|
1187
|
-
contextValue: input.context,
|
|
1188
|
-
rootValue: input.rootValue,
|
|
1189
|
-
operationName: input.operationName,
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
|
-
// Create an execution context
|
|
1193
|
-
const { context, destroy } = getSession(input.context);
|
|
1194
|
-
// It's important to wrap the executeFn within a promise
|
|
1195
|
-
// so we can easily control the end of execution (with finally)
|
|
1196
|
-
return Promise.resolve()
|
|
1197
|
-
.then(() => graphql.execute({
|
|
1198
|
-
schema,
|
|
1199
|
-
document: input.document,
|
|
1200
|
-
contextValue: context,
|
|
1201
|
-
variableValues: input.variables,
|
|
1202
|
-
rootValue: input.rootValue,
|
|
1203
|
-
operationName: input.operationName,
|
|
1204
|
-
}))
|
|
1205
|
-
.finally(destroy);
|
|
1206
1165
|
},
|
|
1207
|
-
|
|
1166
|
+
async stop() { },
|
|
1167
|
+
};
|
|
1208
1168
|
};
|
|
1209
|
-
return createApolloSchema;
|
|
1210
1169
|
}
|
|
1211
1170
|
|
|
1212
1171
|
function operationControllerCreator(options) {
|
|
@@ -1231,7 +1190,6 @@ function operationControllerCreator(options) {
|
|
|
1231
1190
|
*
|
|
1232
1191
|
* ```typescript
|
|
1233
1192
|
* import { createApplication } from 'graphql-modules';
|
|
1234
|
-
* import { createHook, executionAsyncId } from 'async_hooks';
|
|
1235
1193
|
* import { usersModule } from './users';
|
|
1236
1194
|
* import { postsModule } from './posts';
|
|
1237
1195
|
* import { commentsModule } from './comments';
|
|
@@ -1241,17 +1199,13 @@ function operationControllerCreator(options) {
|
|
|
1241
1199
|
* usersModule,
|
|
1242
1200
|
* postsModule,
|
|
1243
1201
|
* commentsModule
|
|
1244
|
-
* ]
|
|
1245
|
-
* executionContext: { createHook, executionAsyncId },
|
|
1202
|
+
* ]
|
|
1246
1203
|
* })
|
|
1247
1204
|
* ```
|
|
1248
1205
|
*/
|
|
1249
1206
|
function createApplication(applicationConfig) {
|
|
1250
1207
|
function applicationFactory(cfg) {
|
|
1251
1208
|
const config = cfg || applicationConfig;
|
|
1252
|
-
if (config.executionContext) {
|
|
1253
|
-
enableExecutionContext(config.executionContext);
|
|
1254
|
-
}
|
|
1255
1209
|
const providers = config.providers && typeof config.providers === 'function'
|
|
1256
1210
|
? config.providers()
|
|
1257
1211
|
: config.providers;
|
|
@@ -1308,12 +1262,9 @@ function createApplication(applicationConfig) {
|
|
|
1308
1262
|
});
|
|
1309
1263
|
const createSubscription = subscriptionCreator({ contextBuilder });
|
|
1310
1264
|
const createExecution = executionCreator({ contextBuilder });
|
|
1311
|
-
const
|
|
1312
|
-
createSubscription,
|
|
1313
|
-
contextBuilder,
|
|
1265
|
+
const createApolloGateway = apolloGatewayCreator({
|
|
1314
1266
|
schema: schema$1,
|
|
1315
|
-
|
|
1316
|
-
const createApolloExecutor = apolloExecutorCreator({
|
|
1267
|
+
typeDefs,
|
|
1317
1268
|
createExecution,
|
|
1318
1269
|
});
|
|
1319
1270
|
instantiateSingletonProviders({
|
|
@@ -1328,8 +1279,7 @@ function createApplication(applicationConfig) {
|
|
|
1328
1279
|
createOperationController,
|
|
1329
1280
|
createSubscription,
|
|
1330
1281
|
createExecution,
|
|
1331
|
-
|
|
1332
|
-
createApolloExecutor,
|
|
1282
|
+
createApolloGateway,
|
|
1333
1283
|
ɵfactory: applicationFactory,
|
|
1334
1284
|
ɵconfig: config,
|
|
1335
1285
|
};
|
|
@@ -2033,11 +1983,8 @@ function mockApplication(app) {
|
|
|
2033
1983
|
createExecution(options) {
|
|
2034
1984
|
return sharedFactory().createExecution(options);
|
|
2035
1985
|
},
|
|
2036
|
-
|
|
2037
|
-
return sharedFactory().
|
|
2038
|
-
},
|
|
2039
|
-
createApolloExecutor() {
|
|
2040
|
-
return sharedFactory().createApolloExecutor();
|
|
1986
|
+
createApolloGateway() {
|
|
1987
|
+
return sharedFactory().createApolloGateway();
|
|
2041
1988
|
},
|
|
2042
1989
|
get ɵfactory() {
|
|
2043
1990
|
return sharedFactory().ɵfactory;
|
|
@@ -2093,7 +2040,6 @@ function testModule(testedModule, config) {
|
|
|
2093
2040
|
modules,
|
|
2094
2041
|
providers: config === null || config === void 0 ? void 0 : config.providers,
|
|
2095
2042
|
middlewares: config === null || config === void 0 ? void 0 : config.middlewares,
|
|
2096
|
-
executionContext: false,
|
|
2097
2043
|
});
|
|
2098
2044
|
}
|
|
2099
2045
|
function transformModule(mod, config) {
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createHook, executionAsyncId, AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
import { GraphQLSchema, execute as execute$1, subscribe, print, concatAST, visit, Kind, GraphQLScalarType, defaultFieldResolver, parse } from 'graphql';
|
|
4
4
|
import { mergeDeepWith } from 'ramda';
|
|
5
5
|
|
|
6
6
|
const ERROR_ORIGINAL_ERROR = 'diOriginalError';
|
|
@@ -171,6 +171,85 @@ function isFactoryProvider(provider) {
|
|
|
171
171
|
return typeof provider.useFactory !== 'undefined';
|
|
172
172
|
}
|
|
173
173
|
|
|
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
|
+
|
|
174
253
|
function ensureReflect() {
|
|
175
254
|
if (!(Reflect && Reflect.getOwnMetadata)) {
|
|
176
255
|
throw 'reflect-metadata shim is required when using class decorators';
|
|
@@ -180,6 +259,7 @@ function Injectable(options) {
|
|
|
180
259
|
return (target) => {
|
|
181
260
|
var _a;
|
|
182
261
|
ensureReflect();
|
|
262
|
+
enableExecutionContext$1();
|
|
183
263
|
const params = (Reflect.getMetadata('design:paramtypes', target) || []).map((param) => (isType(param) ? param : null));
|
|
184
264
|
const existingMeta = readInjectableMetadata(target);
|
|
185
265
|
const meta = {
|
|
@@ -766,11 +846,6 @@ function share(factory) {
|
|
|
766
846
|
return cached;
|
|
767
847
|
};
|
|
768
848
|
}
|
|
769
|
-
function uniqueId(isNotUsed) {
|
|
770
|
-
let id;
|
|
771
|
-
while (!isNotUsed((id = Math.random().toString(16).substr(2)))) { }
|
|
772
|
-
return id;
|
|
773
|
-
}
|
|
774
849
|
function isNotSchema(obj) {
|
|
775
850
|
return obj instanceof GraphQLSchema === false;
|
|
776
851
|
}
|
|
@@ -851,77 +926,6 @@ function duplicatedGlobalTokenError(provider, modules) {
|
|
|
851
926
|
*/
|
|
852
927
|
const CONTEXT = new InjectionToken('context');
|
|
853
928
|
|
|
854
|
-
const executionContextStore = new Map();
|
|
855
|
-
const executionContextDependencyStore = new Map();
|
|
856
|
-
let executionAsyncId = () => 0;
|
|
857
|
-
function destroyContextAndItsChildren(id) {
|
|
858
|
-
if (executionContextStore.has(id)) {
|
|
859
|
-
executionContextStore.delete(id);
|
|
860
|
-
}
|
|
861
|
-
const deps = executionContextDependencyStore.get(id);
|
|
862
|
-
if (deps) {
|
|
863
|
-
for (const dep of deps) {
|
|
864
|
-
destroyContextAndItsChildren(dep);
|
|
865
|
-
}
|
|
866
|
-
executionContextDependencyStore.delete(id);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
let executionContextEnabled = false;
|
|
870
|
-
const executionContext = {
|
|
871
|
-
create(picker) {
|
|
872
|
-
if (!executionContextEnabled) {
|
|
873
|
-
return function destroyContextNoop() {
|
|
874
|
-
// noop
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
const id = executionAsyncId();
|
|
878
|
-
executionContextStore.set(id, picker);
|
|
879
|
-
return function destroyContext() {
|
|
880
|
-
destroyContextAndItsChildren(id);
|
|
881
|
-
};
|
|
882
|
-
},
|
|
883
|
-
getModuleContext(moduleId) {
|
|
884
|
-
assertExecutionContext();
|
|
885
|
-
const picker = executionContextStore.get(executionAsyncId());
|
|
886
|
-
return picker.getModuleContext(moduleId);
|
|
887
|
-
},
|
|
888
|
-
getApplicationContext() {
|
|
889
|
-
assertExecutionContext();
|
|
890
|
-
const picker = executionContextStore.get(executionAsyncId());
|
|
891
|
-
return picker.getApplicationContext();
|
|
892
|
-
},
|
|
893
|
-
};
|
|
894
|
-
function enableExecutionContext(config) {
|
|
895
|
-
if (!executionContextEnabled) {
|
|
896
|
-
config.createHook({
|
|
897
|
-
init(asyncId, _, triggerAsyncId) {
|
|
898
|
-
var _a;
|
|
899
|
-
// Store same context data for child async resources
|
|
900
|
-
const ctx = executionContextStore.get(triggerAsyncId);
|
|
901
|
-
if (ctx) {
|
|
902
|
-
const dependencies = (_a = executionContextDependencyStore.get(triggerAsyncId)) !== null && _a !== void 0 ? _a : executionContextDependencyStore
|
|
903
|
-
.set(triggerAsyncId, new Set())
|
|
904
|
-
.get(triggerAsyncId);
|
|
905
|
-
dependencies.add(asyncId);
|
|
906
|
-
executionContextStore.set(asyncId, ctx);
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
destroy(asyncId) {
|
|
910
|
-
if (executionContextStore.has(asyncId)) {
|
|
911
|
-
executionContextStore.delete(asyncId);
|
|
912
|
-
}
|
|
913
|
-
},
|
|
914
|
-
});
|
|
915
|
-
executionAsyncId = config.executionAsyncId;
|
|
916
|
-
executionContextEnabled = true;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
function assertExecutionContext() {
|
|
920
|
-
if (!executionContextEnabled) {
|
|
921
|
-
throw new Error('Execution Context is not enabled. Please set `executionContext` option in `createApplication`');
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
929
|
function createContextBuilder({ appInjector, modulesMap, appLevelOperationProviders, singletonGlobalProvidersMap, operationGlobalProvidersMap, }) {
|
|
926
930
|
// This is very critical. It creates an execution context.
|
|
927
931
|
// It has to run on every operation.
|
|
@@ -949,10 +953,10 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
949
953
|
return modulesMap.get(moduleId).injector;
|
|
950
954
|
},
|
|
951
955
|
});
|
|
952
|
-
appInjector.setExecutionContextGetter(executionContext.getApplicationContext);
|
|
956
|
+
appInjector.setExecutionContextGetter(executionContext$2.getApplicationContext);
|
|
953
957
|
function createModuleExecutionContextGetter(moduleId) {
|
|
954
958
|
return function moduleExecutionContextGetter() {
|
|
955
|
-
return executionContext.getModuleContext(moduleId);
|
|
959
|
+
return executionContext$2.getModuleContext(moduleId);
|
|
956
960
|
};
|
|
957
961
|
}
|
|
958
962
|
modulesMap.forEach((mod, moduleId) => {
|
|
@@ -966,7 +970,7 @@ function createContextBuilder({ appInjector, modulesMap, appLevelOperationProvid
|
|
|
966
970
|
return getModuleContext(moduleId, context);
|
|
967
971
|
},
|
|
968
972
|
};
|
|
969
|
-
const destroyExecutionContext = executionContext.create(executionContextPicker);
|
|
973
|
+
const destroyExecutionContext = executionContext$2.create(executionContextPicker);
|
|
970
974
|
// As the name of the Injector says, it's an Operation scoped Injector
|
|
971
975
|
// Application level
|
|
972
976
|
// Operation scoped - means it's created and destroyed on every GraphQL Operation
|
|
@@ -1132,78 +1136,33 @@ function subscriptionCreator({ contextBuilder, }) {
|
|
|
1132
1136
|
return createSubscription;
|
|
1133
1137
|
}
|
|
1134
1138
|
|
|
1135
|
-
|
|
1136
|
-
function
|
|
1137
|
-
return function createApolloExecutor(options) {
|
|
1139
|
+
function apolloGatewayCreator({ schema, typeDefs, createExecution, }) {
|
|
1140
|
+
return function createApolloGateway(options) {
|
|
1138
1141
|
const executor = createExecution(options);
|
|
1139
|
-
return
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
const { context, ɵdestroy: destroy } = contextBuilder(ctx);
|
|
1158
|
-
sessions[ctx[CONTEXT_ID]] = {
|
|
1159
|
-
count: 0,
|
|
1160
|
-
session: {
|
|
1161
|
-
context,
|
|
1162
|
-
destroy() {
|
|
1163
|
-
if (--sessions[ctx[CONTEXT_ID]].count === 0) {
|
|
1164
|
-
destroy();
|
|
1165
|
-
delete sessions[ctx[CONTEXT_ID]];
|
|
1166
|
-
delete ctx[CONTEXT_ID];
|
|
1167
|
-
}
|
|
1168
|
-
},
|
|
1142
|
+
return {
|
|
1143
|
+
onSchemaLoadOrUpdate(callback) {
|
|
1144
|
+
callback({
|
|
1145
|
+
apiSchema: schema,
|
|
1146
|
+
coreSupergraphSdl: print(concatAST(typeDefs)),
|
|
1147
|
+
});
|
|
1148
|
+
return () => { };
|
|
1149
|
+
},
|
|
1150
|
+
async load() {
|
|
1151
|
+
return {
|
|
1152
|
+
async executor(requestContext) {
|
|
1153
|
+
return executor({
|
|
1154
|
+
schema: requestContext.schema,
|
|
1155
|
+
document: requestContext.document,
|
|
1156
|
+
operationName: requestContext.operationName,
|
|
1157
|
+
variableValues: requestContext.request.variables,
|
|
1158
|
+
contextValue: requestContext.context,
|
|
1159
|
+
});
|
|
1169
1160
|
},
|
|
1170
1161
|
};
|
|
1171
|
-
}
|
|
1172
|
-
sessions[ctx[CONTEXT_ID]].count++;
|
|
1173
|
-
return sessions[ctx[CONTEXT_ID]].session;
|
|
1174
|
-
}
|
|
1175
|
-
return wrapSchema({
|
|
1176
|
-
schema,
|
|
1177
|
-
batch: true,
|
|
1178
|
-
executor(input) {
|
|
1179
|
-
if (input.operationType === 'subscription') {
|
|
1180
|
-
return subscription({
|
|
1181
|
-
schema,
|
|
1182
|
-
document: input.document,
|
|
1183
|
-
variableValues: input.variables,
|
|
1184
|
-
contextValue: input.context,
|
|
1185
|
-
rootValue: input.rootValue,
|
|
1186
|
-
operationName: input.operationName,
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
// Create an execution context
|
|
1190
|
-
const { context, destroy } = getSession(input.context);
|
|
1191
|
-
// It's important to wrap the executeFn within a promise
|
|
1192
|
-
// so we can easily control the end of execution (with finally)
|
|
1193
|
-
return Promise.resolve()
|
|
1194
|
-
.then(() => execute$1({
|
|
1195
|
-
schema,
|
|
1196
|
-
document: input.document,
|
|
1197
|
-
contextValue: context,
|
|
1198
|
-
variableValues: input.variables,
|
|
1199
|
-
rootValue: input.rootValue,
|
|
1200
|
-
operationName: input.operationName,
|
|
1201
|
-
}))
|
|
1202
|
-
.finally(destroy);
|
|
1203
1162
|
},
|
|
1204
|
-
|
|
1163
|
+
async stop() { },
|
|
1164
|
+
};
|
|
1205
1165
|
};
|
|
1206
|
-
return createApolloSchema;
|
|
1207
1166
|
}
|
|
1208
1167
|
|
|
1209
1168
|
function operationControllerCreator(options) {
|
|
@@ -1228,7 +1187,6 @@ function operationControllerCreator(options) {
|
|
|
1228
1187
|
*
|
|
1229
1188
|
* ```typescript
|
|
1230
1189
|
* import { createApplication } from 'graphql-modules';
|
|
1231
|
-
* import { createHook, executionAsyncId } from 'async_hooks';
|
|
1232
1190
|
* import { usersModule } from './users';
|
|
1233
1191
|
* import { postsModule } from './posts';
|
|
1234
1192
|
* import { commentsModule } from './comments';
|
|
@@ -1238,17 +1196,13 @@ function operationControllerCreator(options) {
|
|
|
1238
1196
|
* usersModule,
|
|
1239
1197
|
* postsModule,
|
|
1240
1198
|
* commentsModule
|
|
1241
|
-
* ]
|
|
1242
|
-
* executionContext: { createHook, executionAsyncId },
|
|
1199
|
+
* ]
|
|
1243
1200
|
* })
|
|
1244
1201
|
* ```
|
|
1245
1202
|
*/
|
|
1246
1203
|
function createApplication(applicationConfig) {
|
|
1247
1204
|
function applicationFactory(cfg) {
|
|
1248
1205
|
const config = cfg || applicationConfig;
|
|
1249
|
-
if (config.executionContext) {
|
|
1250
|
-
enableExecutionContext(config.executionContext);
|
|
1251
|
-
}
|
|
1252
1206
|
const providers = config.providers && typeof config.providers === 'function'
|
|
1253
1207
|
? config.providers()
|
|
1254
1208
|
: config.providers;
|
|
@@ -1305,12 +1259,9 @@ function createApplication(applicationConfig) {
|
|
|
1305
1259
|
});
|
|
1306
1260
|
const createSubscription = subscriptionCreator({ contextBuilder });
|
|
1307
1261
|
const createExecution = executionCreator({ contextBuilder });
|
|
1308
|
-
const
|
|
1309
|
-
createSubscription,
|
|
1310
|
-
contextBuilder,
|
|
1262
|
+
const createApolloGateway = apolloGatewayCreator({
|
|
1311
1263
|
schema,
|
|
1312
|
-
|
|
1313
|
-
const createApolloExecutor = apolloExecutorCreator({
|
|
1264
|
+
typeDefs,
|
|
1314
1265
|
createExecution,
|
|
1315
1266
|
});
|
|
1316
1267
|
instantiateSingletonProviders({
|
|
@@ -1325,8 +1276,7 @@ function createApplication(applicationConfig) {
|
|
|
1325
1276
|
createOperationController,
|
|
1326
1277
|
createSubscription,
|
|
1327
1278
|
createExecution,
|
|
1328
|
-
|
|
1329
|
-
createApolloExecutor,
|
|
1279
|
+
createApolloGateway,
|
|
1330
1280
|
ɵfactory: applicationFactory,
|
|
1331
1281
|
ɵconfig: config,
|
|
1332
1282
|
};
|
|
@@ -2030,11 +1980,8 @@ function mockApplication(app) {
|
|
|
2030
1980
|
createExecution(options) {
|
|
2031
1981
|
return sharedFactory().createExecution(options);
|
|
2032
1982
|
},
|
|
2033
|
-
|
|
2034
|
-
return sharedFactory().
|
|
2035
|
-
},
|
|
2036
|
-
createApolloExecutor() {
|
|
2037
|
-
return sharedFactory().createApolloExecutor();
|
|
1983
|
+
createApolloGateway() {
|
|
1984
|
+
return sharedFactory().createApolloGateway();
|
|
2038
1985
|
},
|
|
2039
1986
|
get ɵfactory() {
|
|
2040
1987
|
return sharedFactory().ɵfactory;
|
|
@@ -2090,7 +2037,6 @@ function testModule(testedModule, config) {
|
|
|
2090
2037
|
modules,
|
|
2091
2038
|
providers: config === null || config === void 0 ? void 0 : config.providers,
|
|
2092
2039
|
middlewares: config === null || config === void 0 ? void 0 : config.middlewares,
|
|
2093
|
-
executionContext: false,
|
|
2094
2040
|
});
|
|
2095
2041
|
}
|
|
2096
2042
|
function transformModule(mod, config) {
|
package/module/factory.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { ReflectiveInjector } from '../di';
|
|
|
3
3
|
import { ResolvedProvider } from './../di/resolution';
|
|
4
4
|
import { MiddlewareMap } from '../shared/middleware';
|
|
5
5
|
import { Single } from '../shared/types';
|
|
6
|
-
export
|
|
6
|
+
export type ResolvedModule = {
|
|
7
7
|
injector: ReflectiveInjector;
|
|
8
8
|
singletonProviders: Array<ResolvedProvider>;
|
|
9
9
|
operationProviders: Array<ResolvedProvider>;
|
|
10
10
|
resolvers?: Single<Resolvers>;
|
|
11
11
|
} & Omit<Module, 'factory'>;
|
|
12
|
-
export
|
|
12
|
+
export type ModuleFactory = (app: {
|
|
13
13
|
injector: ReflectiveInjector;
|
|
14
14
|
middlewares: MiddlewareMap;
|
|
15
15
|
}) => ResolvedModule;
|
package/module/metadata.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
2
|
import { ModuleConfig } from './types';
|
|
3
3
|
import { ID } from '../shared/types';
|
|
4
|
-
export
|
|
4
|
+
export type Registry = Record<string, string[]>;
|
|
5
5
|
export interface ModuleMetadata {
|
|
6
6
|
id: ID;
|
|
7
7
|
typeDefs: DocumentNode[];
|
package/module/types.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { ModuleMetadata } from './metadata';
|
|
|
5
5
|
import { Provider } from '../di';
|
|
6
6
|
import { MiddlewareMap } from '../shared/middleware';
|
|
7
7
|
import { ResolvedProvider } from '../di/resolution';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type TypeDefs = Plural<DocumentNode>;
|
|
9
|
+
export type Resolvers = Plural<Record<string, any>>;
|
|
10
10
|
/**
|
|
11
11
|
* @api
|
|
12
12
|
* Module's configuration object. Represents the first argument of `createModule` function.
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-modules",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-20231018162945-f59bbaea",
|
|
4
4
|
"description": "Create reusable, maintainable, testable and extendable GraphQL modules",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/schema": "^
|
|
11
|
-
"@graphql-tools/wrap": "^9.0.0",
|
|
10
|
+
"@graphql-tools/schema": "^10.0.0",
|
|
12
11
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
13
|
-
"ramda": "^0.
|
|
12
|
+
"ramda": "^0.29.0"
|
|
14
13
|
},
|
|
15
14
|
"keywords": [
|
|
16
15
|
"graphql",
|
package/shared/middleware.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLResolveInfo } from 'graphql';
|
|
2
2
|
import { ModuleMetadata } from './../module/metadata';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type Next<T = any> = () => Promise<T>;
|
|
4
|
+
export type Middleware<TContext = MiddlewareContext> = (context: TContext, next: Next) => Promise<any>;
|
|
5
5
|
export declare function compose<TContext>(middleware: Array<Middleware<TContext>>): (context: TContext, next: Next) => Promise<any>;
|
|
6
6
|
export interface MiddlewareContext {
|
|
7
7
|
root: any;
|
|
@@ -11,7 +11,7 @@ export interface MiddlewareContext {
|
|
|
11
11
|
context: GraphQLModules.ModuleContext;
|
|
12
12
|
info: GraphQLResolveInfo;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
14
|
+
export type MiddlewareMap = {
|
|
15
15
|
[type: string]: {
|
|
16
16
|
[field: string]: Middleware[];
|
|
17
17
|
};
|
package/shared/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { GraphQLFieldResolver, GraphQLTypeResolver } from 'graphql';
|
|
2
2
|
import { Injector } from '../di';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
3
|
+
export type ID = string;
|
|
4
|
+
export type Nil = undefined | null;
|
|
5
|
+
export type Maybe<T> = T | Nil;
|
|
6
|
+
export type Plural<T> = T | T[];
|
|
7
|
+
export type Single<T> = T extends Array<infer R> ? R : T;
|
|
8
|
+
export type ValueOrPromise<T> = T | Promise<T>;
|
|
9
|
+
export type ResolveFn<TContext = GraphQLModules.Context> = GraphQLFieldResolver<any, TContext, Record<string, any>>;
|
|
10
|
+
export type ResolveTypeFn<TContext = GraphQLModules.Context> = GraphQLTypeResolver<any, TContext>;
|
|
11
11
|
declare global {
|
|
12
12
|
namespace GraphQLModules {
|
|
13
13
|
type ModuleContext = {
|
package/testing/test-module.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ApplicationConfig } from '../application/types';
|
|
2
2
|
import { MockedModule, Module, ModuleConfig } from '../module/types';
|
|
3
|
-
|
|
3
|
+
type TestModuleConfig = {
|
|
4
4
|
replaceExtensions?: boolean;
|
|
5
5
|
inheritTypeDefs?: Module[];
|
|
6
6
|
} & Partial<Pick<ApplicationConfig, 'providers' | 'modules' | 'middlewares' | 'schemaBuilder'>> & Partial<Pick<ModuleConfig, 'typeDefs' | 'resolvers'>>;
|
|
7
|
-
|
|
7
|
+
type MockModuleConfig = Partial<Pick<ModuleConfig, 'providers'>>;
|
|
8
8
|
export declare function mockModule(testedModule: Module, overrideConfig: MockModuleConfig): MockedModule;
|
|
9
9
|
export declare function testModule(testedModule: Module, config?: TestModuleConfig): import("../application/types").Application;
|
|
10
10
|
export {};
|