graphql-modules 3.1.2-alpha-20260121024117-e03d9c26de1cfd3971986f82b995963e1cc77056 → 3.1.2-alpha-20260121025807-95ab4fb1994c3cf68c88a7cf234efd8f99f92ed1

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.
Files changed (165) hide show
  1. package/cjs/application/apollo.js +81 -0
  2. package/cjs/application/application.js +149 -0
  3. package/cjs/application/context.js +144 -0
  4. package/cjs/application/di.js +48 -0
  5. package/cjs/application/execution.js +42 -0
  6. package/cjs/application/operation-controller.js +16 -0
  7. package/cjs/application/subscription.js +54 -0
  8. package/cjs/application/tokens.js +20 -0
  9. package/cjs/application/types.js +0 -0
  10. package/cjs/async-context.browser.mjs +7 -0
  11. package/cjs/async-context.node.cjs +14 -0
  12. package/cjs/di/decorators.js +78 -0
  13. package/cjs/di/errors.js +87 -0
  14. package/cjs/di/forward-ref.js +26 -0
  15. package/cjs/di/index.js +19 -0
  16. package/cjs/di/injector.js +173 -0
  17. package/cjs/di/metadata.js +22 -0
  18. package/cjs/di/providers.js +60 -0
  19. package/cjs/di/registry.js +44 -0
  20. package/cjs/di/resolution.js +166 -0
  21. package/cjs/di/utils.js +44 -0
  22. package/cjs/index.js +31 -0
  23. package/cjs/module/factory.js +71 -0
  24. package/cjs/module/metadata.js +110 -0
  25. package/cjs/module/module.js +27 -0
  26. package/cjs/module/resolvers.js +341 -0
  27. package/cjs/module/tokens.js +21 -0
  28. package/cjs/module/type-defs.js +24 -0
  29. package/cjs/module/types.js +0 -0
  30. package/cjs/package.json +9 -0
  31. package/cjs/shared/di.js +0 -0
  32. package/cjs/shared/errors.js +82 -0
  33. package/cjs/shared/gql.js +12 -0
  34. package/cjs/shared/middleware.js +109 -0
  35. package/cjs/shared/types.js +0 -0
  36. package/cjs/shared/utils.js +115 -0
  37. package/cjs/testing/di.js +9 -0
  38. package/cjs/testing/graphql.js +10 -0
  39. package/cjs/testing/index.js +17 -0
  40. package/cjs/testing/test-application.js +65 -0
  41. package/cjs/testing/test-injector.js +22 -0
  42. package/cjs/testing/test-module.js +270 -0
  43. package/esm/application/apollo.js +77 -0
  44. package/esm/application/application.js +146 -0
  45. package/esm/application/context.js +140 -0
  46. package/esm/application/di.js +42 -0
  47. package/esm/application/execution.js +39 -0
  48. package/esm/application/operation-controller.js +13 -0
  49. package/esm/application/subscription.js +51 -0
  50. package/esm/application/tokens.js +17 -0
  51. package/esm/application/types.js +0 -0
  52. package/esm/async-context.browser.mjs +7 -0
  53. package/esm/async-context.node.cjs +14 -0
  54. package/esm/di/decorators.js +72 -0
  55. package/esm/di/errors.js +79 -0
  56. package/esm/di/forward-ref.js +22 -0
  57. package/esm/di/index.js +4 -0
  58. package/esm/di/injector.js +168 -0
  59. package/esm/di/metadata.js +17 -0
  60. package/esm/di/providers.js +50 -0
  61. package/esm/di/registry.js +40 -0
  62. package/esm/di/resolution.js +159 -0
  63. package/esm/di/utils.js +36 -0
  64. package/esm/index.js +16 -0
  65. package/esm/module/factory.js +68 -0
  66. package/esm/module/metadata.js +107 -0
  67. package/esm/module/module.js +24 -0
  68. package/esm/module/resolvers.js +337 -0
  69. package/esm/module/tokens.js +18 -0
  70. package/esm/module/type-defs.js +21 -0
  71. package/esm/module/types.js +0 -0
  72. package/esm/shared/di.js +0 -0
  73. package/esm/shared/errors.js +69 -0
  74. package/esm/shared/gql.js +9 -0
  75. package/esm/shared/middleware.js +103 -0
  76. package/esm/shared/types.js +0 -0
  77. package/esm/shared/utils.js +101 -0
  78. package/esm/testing/di.js +6 -0
  79. package/esm/testing/graphql.js +7 -0
  80. package/esm/testing/index.js +14 -0
  81. package/esm/testing/test-application.js +62 -0
  82. package/esm/testing/test-injector.js +18 -0
  83. package/esm/testing/test-module.js +266 -0
  84. package/package.json +29 -9
  85. package/typings/application/apollo.d.ts +22 -0
  86. package/typings/application/application.d.ts +32 -0
  87. package/typings/application/context.d.ts +24 -0
  88. package/typings/application/di.d.ts +22 -0
  89. package/typings/application/execution.d.ts +8 -0
  90. package/typings/application/operation-controller.d.ts +5 -0
  91. package/typings/application/subscription.d.ts +8 -0
  92. package/typings/application/tokens.d.ts +17 -0
  93. package/typings/application/types.d.ts +130 -0
  94. package/typings/di/decorators.d.ts +11 -0
  95. package/typings/di/errors.d.ts +16 -0
  96. package/typings/di/forward-ref.d.ts +7 -0
  97. package/typings/di/index.d.ts +5 -0
  98. package/typings/di/injector.d.ts +50 -0
  99. package/typings/di/metadata.d.ts +12 -0
  100. package/typings/di/providers.d.ts +44 -0
  101. package/typings/di/registry.d.ts +11 -0
  102. package/typings/di/resolution.d.ts +63 -0
  103. package/typings/di/utils.d.ts +8 -0
  104. package/typings/index.d.ts +13 -0
  105. package/typings/module/factory.d.ts +16 -0
  106. package/typings/module/metadata.d.ts +12 -0
  107. package/typings/module/module.d.ts +22 -0
  108. package/typings/module/resolvers.d.ts +13 -0
  109. package/typings/module/tokens.d.ts +18 -0
  110. package/typings/module/type-defs.d.ts +7 -0
  111. package/typings/module/types.d.ts +51 -0
  112. package/typings/shared/di.d.ts +3 -0
  113. package/typings/shared/errors.d.ts +36 -0
  114. package/typings/shared/gql.d.ts +2 -0
  115. package/typings/shared/middleware.d.ts +21 -0
  116. package/typings/shared/types.d.ts +22 -0
  117. package/typings/shared/utils.d.ts +12 -0
  118. package/typings/testing/di.d.ts +2 -0
  119. package/typings/testing/graphql.d.ts +14 -0
  120. package/typings/testing/index.d.ts +14 -0
  121. package/typings/testing/test-application.d.ts +2 -0
  122. package/typings/testing/test-injector.d.ts +4 -0
  123. package/typings/testing/test-module.d.ts +10 -0
  124. package/LICENSE.md +0 -21
  125. package/index.js +0 -2359
  126. package/index.mjs +0 -2344
  127. /package/{application/apollo.d.ts → typings/application/apollo.d.cts} +0 -0
  128. /package/{application/application.d.ts → typings/application/application.d.cts} +0 -0
  129. /package/{application/context.d.ts → typings/application/context.d.cts} +0 -0
  130. /package/{application/di.d.ts → typings/application/di.d.cts} +0 -0
  131. /package/{application/execution.d.ts → typings/application/execution.d.cts} +0 -0
  132. /package/{application/operation-controller.d.ts → typings/application/operation-controller.d.cts} +0 -0
  133. /package/{application/subscription.d.ts → typings/application/subscription.d.cts} +0 -0
  134. /package/{application/tokens.d.ts → typings/application/tokens.d.cts} +0 -0
  135. /package/{application/types.d.ts → typings/application/types.d.cts} +0 -0
  136. /package/{di/decorators.d.ts → typings/di/decorators.d.cts} +0 -0
  137. /package/{di/errors.d.ts → typings/di/errors.d.cts} +0 -0
  138. /package/{di/forward-ref.d.ts → typings/di/forward-ref.d.cts} +0 -0
  139. /package/{di/index.d.ts → typings/di/index.d.cts} +0 -0
  140. /package/{di/injector.d.ts → typings/di/injector.d.cts} +0 -0
  141. /package/{di/metadata.d.ts → typings/di/metadata.d.cts} +0 -0
  142. /package/{di/providers.d.ts → typings/di/providers.d.cts} +0 -0
  143. /package/{di/registry.d.ts → typings/di/registry.d.cts} +0 -0
  144. /package/{di/resolution.d.ts → typings/di/resolution.d.cts} +0 -0
  145. /package/{di/utils.d.ts → typings/di/utils.d.cts} +0 -0
  146. /package/{index.d.ts → typings/index.d.cts} +0 -0
  147. /package/{module/factory.d.ts → typings/module/factory.d.cts} +0 -0
  148. /package/{module/metadata.d.ts → typings/module/metadata.d.cts} +0 -0
  149. /package/{module/module.d.ts → typings/module/module.d.cts} +0 -0
  150. /package/{module/resolvers.d.ts → typings/module/resolvers.d.cts} +0 -0
  151. /package/{module/tokens.d.ts → typings/module/tokens.d.cts} +0 -0
  152. /package/{module/type-defs.d.ts → typings/module/type-defs.d.cts} +0 -0
  153. /package/{module/types.d.ts → typings/module/types.d.cts} +0 -0
  154. /package/{shared/di.d.ts → typings/shared/di.d.cts} +0 -0
  155. /package/{shared/errors.d.ts → typings/shared/errors.d.cts} +0 -0
  156. /package/{shared/gql.d.ts → typings/shared/gql.d.cts} +0 -0
  157. /package/{shared/middleware.d.ts → typings/shared/middleware.d.cts} +0 -0
  158. /package/{shared/types.d.ts → typings/shared/types.d.cts} +0 -0
  159. /package/{shared/utils.d.ts → typings/shared/utils.d.cts} +0 -0
  160. /package/{testing/di.d.ts → typings/testing/di.d.cts} +0 -0
  161. /package/{testing/graphql.d.ts → typings/testing/graphql.d.cts} +0 -0
  162. /package/{testing/index.d.ts → typings/testing/index.d.cts} +0 -0
  163. /package/{testing/test-application.d.ts → typings/testing/test-application.d.cts} +0 -0
  164. /package/{testing/test-injector.d.ts → typings/testing/test-injector.d.cts} +0 -0
  165. /package/{testing/test-module.d.ts → typings/testing/test-module.d.cts} +0 -0
@@ -0,0 +1,130 @@
1
+ import { execute, subscribe, DocumentNode, GraphQLSchema, ExecutionResult } from 'graphql';
2
+ import type { Provider, Injector } from '../di';
3
+ import type { Resolvers, Module, MockedModule } from '../module/types';
4
+ import type { MiddlewareMap } from '../shared/middleware';
5
+ import type { ApolloRequestContext } from './apollo';
6
+ import type { Single } from '../shared/types';
7
+ import type { InternalAppContext } from './application';
8
+ type Execution = typeof execute;
9
+ type Subscription = typeof subscribe;
10
+ export type ApolloExecutor = (requestContext: ApolloRequestContext) => Promise<ExecutionResult>;
11
+ export interface MockedApplication extends Application {
12
+ replaceModule(mockedModule: MockedModule): MockedApplication;
13
+ addProviders(providers: ApplicationConfig['providers']): MockedApplication;
14
+ }
15
+ /**
16
+ * @api
17
+ * A return type of `createApplication` function.
18
+ */
19
+ export interface Application {
20
+ /**
21
+ * A list of type definitions defined by modules.
22
+ */
23
+ readonly typeDefs: DocumentNode[];
24
+ /**
25
+ * An object with resolve functions defined by modules.
26
+ */
27
+ readonly resolvers?: Single<Resolvers>;
28
+ /**
29
+ * Ready to use GraphQLSchema object combined from modules.
30
+ */
31
+ readonly schema: GraphQLSchema;
32
+ /**
33
+ * The application (Singleton) injector.
34
+ */
35
+ readonly injector: Injector;
36
+ /**
37
+ * Take over control of GraphQL Operation
38
+ */
39
+ createOperationController(input: {
40
+ context: any;
41
+ autoDestroy?: boolean;
42
+ }): OperationController;
43
+ /**
44
+ * Creates a `subscribe` function that runs the subscription phase of GraphQL.
45
+ * Important when using GraphQL Subscriptions.
46
+ */
47
+ createSubscription(options?: {
48
+ subscribe?: typeof subscribe;
49
+ controller?: OperationController;
50
+ }): Subscription;
51
+ /**
52
+ * Creates a `execute` function that runs the execution phase of GraphQL.
53
+ * Important when using GraphQL Queries and Mutations.
54
+ */
55
+ createExecution(options?: {
56
+ execute?: typeof execute;
57
+ controller?: OperationController;
58
+ }): Execution;
59
+ /**
60
+ * @deprecated Use `createApolloExecutor`, `createExecution` and `createSubscription` methods instead.
61
+ */
62
+ createSchemaForApollo(): GraphQLSchema;
63
+ /**
64
+ * Experimental
65
+ */
66
+ createApolloExecutor(options?: {
67
+ controller?: OperationController;
68
+ }): ApolloExecutor;
69
+ /**
70
+ * @internal
71
+ */
72
+ ɵfactory(config?: ApplicationConfig | undefined): Application;
73
+ /**
74
+ * @internal
75
+ */
76
+ ɵconfig: ApplicationConfig;
77
+ }
78
+ export interface OperationController {
79
+ /**
80
+ * Destroys
81
+ */
82
+ destroy(): void;
83
+ /**
84
+ * @internal
85
+ */
86
+ ɵdestroy(): void;
87
+ context: InternalAppContext;
88
+ /**
89
+ * Operation Injector (application)
90
+ */
91
+ injector: Injector;
92
+ }
93
+ /**
94
+ * @api
95
+ * Application's configuration object. Represents the first argument of `createApplication` function.
96
+ */
97
+ export interface ApplicationConfig {
98
+ /**
99
+ * A list of GraphQL Modules
100
+ */
101
+ modules: Module[];
102
+ /**
103
+ * A list of Providers - read the ["Providers and Tokens"](./di/providers) chapter.
104
+ */
105
+ providers?: Provider[] | (() => Provider[]);
106
+ /**
107
+ * A map of middlewares - read the ["Middlewares"](./advanced/middlewares) chapter.
108
+ */
109
+ middlewares?: MiddlewareMap;
110
+ /**
111
+ * Creates a GraphQLSchema object out of typeDefs and resolvers
112
+ *
113
+ * @example
114
+ *
115
+ * ```typescript
116
+ * import { createApplication } from 'graphql-modules';
117
+ * import { makeExecutableSchema } from '@graphql-tools/schema';
118
+ *
119
+ * const app = createApplication({
120
+ * modules: [],
121
+ * schemaBuilder: makeExecutableSchema
122
+ * })
123
+ * ```
124
+ */
125
+ schemaBuilder?(input: {
126
+ typeDefs: DocumentNode[];
127
+ resolvers: Record<string, any>[];
128
+ }): GraphQLSchema;
129
+ }
130
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Type, ProviderOptions, InjectionToken } from './providers';
2
+ import { Injector } from './injector';
3
+ export declare function Injectable(options?: ProviderOptions): ClassDecorator;
4
+ type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
5
+ export declare function Optional(): ParameterDecorator;
6
+ export declare function Inject(type: Type<any> | InjectionToken<any>): ParameterDecorator;
7
+ export type ExecutionContext = {
8
+ injector: Injector;
9
+ } & GraphQLModules.ModuleContext;
10
+ export declare function ExecutionContext(): PropertyDecorator;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ import { InjectableParamMetadata } from './metadata';
2
+ import { Type, InjectionToken } from './providers';
3
+ import { ReflectiveInjector } from './injector';
4
+ import { Key } from './registry';
5
+ export declare function invalidProviderError(provider: any): Error;
6
+ export declare function noInjectableError(type: Type<any>): Error;
7
+ export declare function noAnnotationError(typeOrFunc: Type<any> | InjectionToken<any> | Function, params: InjectableParamMetadata[]): Error;
8
+ export declare function cyclicDependencyError(injector: ReflectiveInjector, key: Key): InjectionError;
9
+ export declare function noProviderError(injector: ReflectiveInjector, key: Key): InjectionError;
10
+ export declare function instantiationError(injector: ReflectiveInjector, originalException: any, key: Key): InjectionError;
11
+ export interface InjectionError extends Error {
12
+ keys: Key[];
13
+ injectors: ReflectiveInjector[];
14
+ constructResolvingMessage: (this: InjectionError) => string;
15
+ addKey(key: Key): void;
16
+ }
@@ -0,0 +1,7 @@
1
+ import { Type } from './providers';
2
+ export type ForwardRefFn<T> = () => T;
3
+ /**
4
+ * Useful in "circular dependencies of modules" situation
5
+ */
6
+ export declare function forwardRef<T>(forwardRefFn: ForwardRefFn<T>): Type<any>;
7
+ export declare function resolveForwardRef(type: any): any;
@@ -0,0 +1,5 @@
1
+ export { Injectable, Optional, Inject, ExecutionContext } from './decorators';
2
+ export { forwardRef } from './forward-ref';
3
+ export { InjectionToken, Type, Provider, AbstractType, ValueProvider, ClassProvider, Factory, FactoryProvider, TypeProvider, ProviderOptions, Scope, onlySingletonProviders, onlyOperationProviders, } from './providers';
4
+ export { Injector, ReflectiveInjector } from './injector';
5
+ export { InjectionError } from './errors';
@@ -0,0 +1,50 @@
1
+ import { Type, InjectionToken, Provider, AbstractType } from './providers';
2
+ import { ResolvedProvider, GlobalProviderMap } from './resolution';
3
+ import { Key } from './registry';
4
+ import { ExecutionContext } from './decorators';
5
+ type ExecutionContextGetter = () => ExecutionContext | never;
6
+ export declare abstract class Injector {
7
+ abstract get<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: any): T;
8
+ }
9
+ export declare class ReflectiveInjector implements Injector {
10
+ displayName: string;
11
+ _constructionCounter: number;
12
+ _providers: ResolvedProvider[];
13
+ _globalProvidersMap: GlobalProviderMap;
14
+ private _executionContextGetter;
15
+ private _fallbackParent;
16
+ private _parent;
17
+ private _keyIds;
18
+ private _objs;
19
+ constructor({ name, providers, parent, fallbackParent, globalProvidersMap, }: {
20
+ name: string;
21
+ proxy?: boolean;
22
+ providers: ResolvedProvider[];
23
+ parent?: Injector | null;
24
+ fallbackParent?: Injector | null;
25
+ globalProvidersMap?: GlobalProviderMap;
26
+ });
27
+ static createFromResolved({ name, providers, parent, fallbackParent, globalProvidersMap, }: {
28
+ name: string;
29
+ providers: ResolvedProvider[];
30
+ parent?: Injector;
31
+ fallbackParent?: Injector;
32
+ globalProvidersMap?: GlobalProviderMap;
33
+ }): ReflectiveInjector;
34
+ static resolve(providers: Provider[]): ResolvedProvider[];
35
+ get parent(): Injector | null;
36
+ get fallbackParent(): Injector | null;
37
+ get(token: any, notFoundValue?: any): any;
38
+ setExecutionContextGetter(getter: ExecutionContextGetter): void;
39
+ private _getByKey;
40
+ _isObjectDefinedByKeyId(keyId: number): boolean;
41
+ _getObjByKeyId(keyId: number): any;
42
+ _throwOrNull(key: Key, notFoundValue: any): any;
43
+ instantiateAll(): void;
44
+ private _instantiateProvider;
45
+ private _getByDependency;
46
+ private _new;
47
+ private _getMaxNumberOfObjects;
48
+ toString(): string;
49
+ }
50
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Type, ProviderOptions, InjectionToken } from './providers';
2
+ export declare const INJECTABLE: unique symbol;
3
+ export interface InjectableParamMetadata {
4
+ type: Type<any> | InjectionToken<any>;
5
+ optional: boolean;
6
+ }
7
+ export interface InjectableMetadata {
8
+ params: InjectableParamMetadata[];
9
+ options?: ProviderOptions;
10
+ }
11
+ export declare function readInjectableMetadata(type: Type<any>, throwOnMissing?: boolean): InjectableMetadata;
12
+ export declare function ensureInjectableMetadata(type: Type<any>): void;
@@ -0,0 +1,44 @@
1
+ export declare const Type: FunctionConstructor;
2
+ export declare class InjectionToken<T> {
3
+ private _desc;
4
+ constructor(_desc: string);
5
+ toString(): string;
6
+ }
7
+ export declare function isToken(v: any): v is InjectionToken<any>;
8
+ export declare function isType(v: any): v is Type<any>;
9
+ export interface AbstractType<T> extends Function {
10
+ prototype: T;
11
+ }
12
+ export interface Type<T> extends Function {
13
+ new (...args: any[]): T;
14
+ }
15
+ export interface ValueProvider<T> extends BaseProvider<T> {
16
+ useValue: T;
17
+ }
18
+ export interface ClassProvider<T> extends BaseProvider<T> {
19
+ useClass: Type<T>;
20
+ }
21
+ export type Factory<T> = (...args: any[]) => T;
22
+ export interface FactoryProvider<T> extends BaseProvider<T> {
23
+ useFactory: Factory<T>;
24
+ deps?: any[];
25
+ }
26
+ export interface BaseProvider<T> extends ProviderOptions {
27
+ provide: Type<T> | InjectionToken<T> | AbstractType<T>;
28
+ }
29
+ export interface TypeProvider<T> extends Type<T> {
30
+ }
31
+ export type Provider<T = any> = TypeProvider<T> | ValueProvider<T> | ClassProvider<T> | FactoryProvider<T>;
32
+ export interface ProviderOptions {
33
+ scope?: Scope;
34
+ executionContextIn?: Array<string | symbol>;
35
+ global?: boolean;
36
+ }
37
+ export declare enum Scope {
38
+ Singleton = 0,
39
+ Operation = 1
40
+ }
41
+ export declare function onlySingletonProviders(providers?: Provider[]): Provider[];
42
+ export declare function onlyOperationProviders(providers?: Provider[]): Provider[];
43
+ export declare function isClassProvider(provider: any): provider is ClassProvider<any>;
44
+ export declare function isFactoryProvider(provider: any): provider is FactoryProvider<any>;
@@ -0,0 +1,11 @@
1
+ import { Type } from './providers';
2
+ export declare class Key {
3
+ token: Type<any>;
4
+ id: number;
5
+ constructor(token: Type<any>, id: number);
6
+ /**
7
+ * Returns a stringified token.
8
+ */
9
+ get displayName(): string;
10
+ static get(token: Object): Key;
11
+ }
@@ -0,0 +1,63 @@
1
+ import { Provider, ValueProvider, ClassProvider, FactoryProvider } from './providers';
2
+ import { Key } from './registry';
3
+ import { ReflectiveInjector } from './injector';
4
+ export type NormalizedProvider<T = any> = ValueProvider<T> | ClassProvider<T> | FactoryProvider<T>;
5
+ export type GlobalProviderMap = {
6
+ has(key: Key['id']): boolean;
7
+ get(key: Key['id']): ReflectiveInjector;
8
+ };
9
+ export declare class ResolvedProvider {
10
+ key: Key;
11
+ factory: ResolvedFactory;
12
+ constructor(key: Key, factory: ResolvedFactory);
13
+ }
14
+ export declare class ResolvedFactory {
15
+ /**
16
+ * Factory function which can return an instance of an object represented by a key.
17
+ */
18
+ factory: Function;
19
+ /**
20
+ * Arguments (dependencies) to the `factory` function.
21
+ */
22
+ dependencies: Dependency[];
23
+ /**
24
+ * Methods invoked within ExecutionContext.
25
+ */
26
+ executionContextIn: Array<string | symbol>;
27
+ /**
28
+ * Has onDestroy hook
29
+ */
30
+ hasOnDestroyHook: boolean;
31
+ /**
32
+ * Is Global
33
+ */
34
+ isGlobal: boolean;
35
+ constructor(
36
+ /**
37
+ * Factory function which can return an instance of an object represented by a key.
38
+ */
39
+ factory: Function,
40
+ /**
41
+ * Arguments (dependencies) to the `factory` function.
42
+ */
43
+ dependencies: Dependency[],
44
+ /**
45
+ * Methods invoked within ExecutionContext.
46
+ */
47
+ executionContextIn: Array<string | symbol>,
48
+ /**
49
+ * Has onDestroy hook
50
+ */
51
+ hasOnDestroyHook: boolean,
52
+ /**
53
+ * Is Global
54
+ */
55
+ isGlobal: boolean);
56
+ }
57
+ export declare class Dependency {
58
+ key: Key;
59
+ optional: boolean;
60
+ constructor(key: Key, optional: boolean);
61
+ static fromKey(key: Key): Dependency;
62
+ }
63
+ export declare function resolveProviders(providers: Provider[]): ResolvedProvider[];
@@ -0,0 +1,8 @@
1
+ export declare const ERROR_TYPE = "diType";
2
+ export declare const ERROR_ORIGINAL_ERROR = "diOriginalError";
3
+ export declare const ERROR_LOGGER = "diErrorLogger";
4
+ export declare function getType(error: Error): Function;
5
+ export declare function getOriginalError(error: Error): Error;
6
+ export declare function getErrorLogger(error: Error): (console: Console, ...values: any[]) => void;
7
+ export declare function wrappedError(message: string, originalError: any): Error;
8
+ export declare function stringify(token: any): string;
@@ -0,0 +1,13 @@
1
+ export { createApplication } from './application/application';
2
+ export * from './application/tokens';
3
+ export * from './application/types';
4
+ export { createModule } from './module/module';
5
+ export * from './module/types';
6
+ export * from './module/metadata';
7
+ export * from './module/tokens';
8
+ export { Injector, Inject, Injectable, Optional, ExecutionContext, Provider, ProviderOptions, FactoryProvider, ClassProvider, ValueProvider, TypeProvider, forwardRef, InjectionToken, Scope, } from './di';
9
+ export { Middleware, MiddlewareContext } from './shared/middleware';
10
+ import './shared/types';
11
+ export { gql } from './shared/gql';
12
+ export * from './shared/di';
13
+ export * from './testing';
@@ -0,0 +1,16 @@
1
+ import { Module, ModuleConfig, Resolvers } from './types';
2
+ import { ReflectiveInjector } from '../di';
3
+ import { ResolvedProvider } from './../di/resolution';
4
+ import { MiddlewareMap } from '../shared/middleware';
5
+ import { Single } from '../shared/types';
6
+ export type ResolvedModule = {
7
+ injector: ReflectiveInjector;
8
+ singletonProviders: Array<ResolvedProvider>;
9
+ operationProviders: Array<ResolvedProvider>;
10
+ resolvers?: Single<Resolvers>;
11
+ } & Omit<Module, 'factory'>;
12
+ export type ModuleFactory = (app: {
13
+ injector: ReflectiveInjector;
14
+ middlewares: MiddlewareMap;
15
+ }) => ResolvedModule;
16
+ export declare function moduleFactory(config: ModuleConfig): Module;
@@ -0,0 +1,12 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { ModuleConfig } from './types';
3
+ import { ID } from '../shared/types';
4
+ export type Registry = Record<string, string[]>;
5
+ export interface ModuleMetadata {
6
+ id: ID;
7
+ typeDefs: DocumentNode[];
8
+ implements?: Registry;
9
+ extends?: Registry;
10
+ dirname?: string;
11
+ }
12
+ export declare function metadataFactory(typeDefs: DocumentNode[], config: ModuleConfig): ModuleMetadata;
@@ -0,0 +1,22 @@
1
+ import { ModuleConfig } from './types';
2
+ /**
3
+ * @api
4
+ * Creates a Module, an element used by Application. Accepts `ModuleConfig`.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { createModule, gql } from 'graphql-modules';
10
+ *
11
+ * export const usersModule = createModule({
12
+ * id: 'users',
13
+ * typeDefs: gql`
14
+ * // GraphQL SDL
15
+ * `,
16
+ * resolvers: {
17
+ * // ...
18
+ * }
19
+ * });
20
+ * ```
21
+ */
22
+ export declare function createModule(config: ModuleConfig): import("./types").Module;
@@ -0,0 +1,13 @@
1
+ import { GraphQLFieldExtensions } from 'graphql';
2
+ import { ModuleConfig } from './types';
3
+ import { ModuleMetadata } from './metadata';
4
+ import { ResolveFn, ID } from './../shared/types';
5
+ import { MiddlewareMap } from '../shared/middleware';
6
+ interface ResolverMetadata {
7
+ moduleId: ID;
8
+ }
9
+ export declare function createResolvers(config: ModuleConfig, metadata: ModuleMetadata, app: {
10
+ middlewareMap: MiddlewareMap;
11
+ }): Record<string, any>;
12
+ export declare function readResolverMetadata(resolver: ResolveFn | GraphQLFieldExtensions<any, any, any>): ResolverMetadata;
13
+ export {};
@@ -0,0 +1,18 @@
1
+ import { InjectionToken } from '../di';
2
+ /**
3
+ * @api
4
+ * `MODULE_ID` is an InjectionToken representing module's ID
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { MODULE_ID, Inject, Injectable } from 'graphql-modules';
9
+ *
10
+ * (A)Injectable()
11
+ * export class Data {
12
+ * constructor((A)Inject(MODULE_ID) moduleId: string) {
13
+ * console.log(`Data used in ${moduleId} module`)
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ export declare const MODULE_ID: InjectionToken<string>;
@@ -0,0 +1,7 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { ModuleConfig } from './types';
3
+ /**
4
+ * Create a list of DocumentNode objects based on Module's config.
5
+ * Add a location, so we get richer errors.
6
+ */
7
+ export declare function createTypeDefs(config: ModuleConfig): DocumentNode[];
@@ -0,0 +1,51 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { ModuleFactory } from './factory';
3
+ import { ID, Plural } from '../shared/types';
4
+ import { ModuleMetadata } from './metadata';
5
+ import { Provider } from '../di';
6
+ import { MiddlewareMap } from '../shared/middleware';
7
+ export type TypeDefs = Plural<DocumentNode>;
8
+ export type Resolvers = Plural<Record<string, any>>;
9
+ /**
10
+ * @api
11
+ * Module's configuration object. Represents the first argument of `createModule` function.
12
+ */
13
+ export interface ModuleConfig {
14
+ /**
15
+ * Unique identifier of a module
16
+ */
17
+ id: ID;
18
+ /**
19
+ * Pass `__dirname` variable as a value to get better error messages.
20
+ */
21
+ dirname?: string;
22
+ /**
23
+ * An object or a list of GraphQL type definitions (SDL).
24
+ */
25
+ typeDefs: TypeDefs;
26
+ /**
27
+ * An object or a list of GraphQL resolve functions.
28
+ */
29
+ resolvers?: Resolvers;
30
+ /**
31
+ * A map of middlewares - read the ["Middlewares"](./advanced/middlewares) chapter.
32
+ */
33
+ middlewares?: MiddlewareMap;
34
+ /**
35
+ * A list of Providers - read the ["Providers and Tokens"](./di/providers) chapter.
36
+ */
37
+ providers?: Provider[] | (() => Provider[]);
38
+ }
39
+ export interface Module {
40
+ id: ID;
41
+ typeDefs: DocumentNode[];
42
+ metadata: ModuleMetadata;
43
+ factory: ModuleFactory;
44
+ config: ModuleConfig;
45
+ }
46
+ export interface MockedModule extends Module {
47
+ /**
48
+ * @internal
49
+ */
50
+ ɵoriginalModule: Module;
51
+ }
@@ -0,0 +1,3 @@
1
+ export interface OnDestroy {
2
+ onDestroy(): void;
3
+ }
@@ -0,0 +1,36 @@
1
+ import { ID } from './types';
2
+ declare const ModuleNonUniqueIdError_base: ErrorConstructor;
3
+ export declare class ModuleNonUniqueIdError extends ModuleNonUniqueIdError_base {
4
+ constructor(message: string, ...rest: string[]);
5
+ }
6
+ declare const ModuleDuplicatedError_base: ErrorConstructor;
7
+ export declare class ModuleDuplicatedError extends ModuleDuplicatedError_base {
8
+ constructor(message: string, ...rest: string[]);
9
+ }
10
+ declare const ExtraResolverError_base: ErrorConstructor;
11
+ export declare class ExtraResolverError extends ExtraResolverError_base {
12
+ constructor(message: string, ...rest: string[]);
13
+ }
14
+ declare const ExtraMiddlewareError_base: ErrorConstructor;
15
+ export declare class ExtraMiddlewareError extends ExtraMiddlewareError_base {
16
+ constructor(message: string, ...rest: string[]);
17
+ }
18
+ declare const ResolverDuplicatedError_base: ErrorConstructor;
19
+ export declare class ResolverDuplicatedError extends ResolverDuplicatedError_base {
20
+ constructor(message: string, ...rest: string[]);
21
+ }
22
+ declare const ResolverInvalidError_base: ErrorConstructor;
23
+ export declare class ResolverInvalidError extends ResolverInvalidError_base {
24
+ constructor(message: string, ...rest: string[]);
25
+ }
26
+ declare const NonDocumentNodeError_base: ErrorConstructor;
27
+ export declare class NonDocumentNodeError extends NonDocumentNodeError_base {
28
+ constructor(message: string, ...rest: string[]);
29
+ }
30
+ export declare function useLocation({ dirname, id }: {
31
+ id: ID;
32
+ dirname?: string;
33
+ }): string;
34
+ export declare function ExtendableBuiltin<T extends Function>(cls: T): T;
35
+ export declare function composeMessage(...lines: string[]): string;
36
+ export {};
@@ -0,0 +1,2 @@
1
+ import { DocumentNode } from 'graphql';
2
+ export declare function gql(literals: ReadonlyArray<string> | Readonly<string>): DocumentNode;
@@ -0,0 +1,21 @@
1
+ import { GraphQLResolveInfo } from 'graphql';
2
+ import { ModuleMetadata } from './../module/metadata';
3
+ export type Next<T = any> = () => Promise<T>;
4
+ export type Middleware<TContext = MiddlewareContext> = (context: TContext, next: Next) => Promise<any>;
5
+ export declare function compose<TContext>(middleware: Array<Middleware<TContext>>): (context: TContext, next: Next) => Promise<any>;
6
+ export interface MiddlewareContext {
7
+ root: any;
8
+ args: {
9
+ [argName: string]: any;
10
+ };
11
+ context: GraphQLModules.ModuleContext;
12
+ info: GraphQLResolveInfo;
13
+ }
14
+ export type MiddlewareMap = {
15
+ [type: string]: {
16
+ [field: string]: Middleware[];
17
+ };
18
+ };
19
+ export declare function createMiddleware(path: string[], middlewareMap?: MiddlewareMap): (context: MiddlewareContext, next: Next) => Promise<any>;
20
+ export declare function mergeMiddlewareMaps(app: MiddlewareMap, mod: MiddlewareMap): MiddlewareMap;
21
+ export declare function validateMiddlewareMap(middlewareMap: MiddlewareMap, metadata: ModuleMetadata): void;
@@ -0,0 +1,22 @@
1
+ import { GraphQLFieldResolver, GraphQLTypeResolver } from 'graphql';
2
+ import { Injector } from '../di';
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
+ declare global {
12
+ namespace GraphQLModules {
13
+ type ModuleContext = {
14
+ injector: Injector;
15
+ moduleId: ID;
16
+ } & GlobalContext;
17
+ type AppContext = Omit<ModuleContext, 'moduleId'>;
18
+ type Context = ModuleContext;
19
+ interface GlobalContext {
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ export declare function flatten<T>(arr: T[]): T extends (infer A)[] ? A[] : T[];
2
+ export declare function isDefined<T>(val: T | null | undefined): val is T;
3
+ export declare function isNil<T>(val: T | null | undefined): val is null | undefined;
4
+ export declare function isObject(val: any): boolean;
5
+ export declare function isPrimitive(val: any): val is number | string | boolean | symbol | bigint;
6
+ export declare function isAsyncIterable(obj: any): obj is AsyncIterableIterator<any>;
7
+ export declare function tapAsyncIterator<T, TAsyncIterableIterator extends AsyncIterableIterator<T>>(iterable: TAsyncIterableIterator, doneCallback: () => void): TAsyncIterableIterator;
8
+ export declare function once(cb: () => void): () => void;
9
+ export declare function share<T, A>(factory: (arg?: A) => T): (arg?: A) => T;
10
+ export declare function uniqueId(isNotUsed: (id: string) => boolean): string;
11
+ export declare function isNotSchema<T>(obj: any): obj is T;
12
+ export declare function merge<S extends object, T extends object>(source: S, target: T): S & T;
@@ -0,0 +1,2 @@
1
+ import { ValueProvider } from './../di/providers';
2
+ export declare function provideEmpty<T = any>(token: ValueProvider<T>['provide']): ValueProvider<T>;
@@ -0,0 +1,14 @@
1
+ import type { DocumentNode, ExecutionArgs, ExecutionResult } from 'graphql';
2
+ import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
+ import type { Application, OperationController } from '../application/types';
4
+ import type { ValueOrPromise } from '../shared/types';
5
+ export declare function execute<TResult = {
6
+ [key: string]: any;
7
+ }, TVariables = {
8
+ [key: string]: any;
9
+ }>(app: Application, inputs: Omit<ExecutionArgs, 'schema'> & {
10
+ document: DocumentNode | TypedDocumentNode<TResult, TVariables>;
11
+ variableValues?: TVariables;
12
+ }, options?: {
13
+ controller?: OperationController;
14
+ }): ValueOrPromise<ExecutionResult<TResult>>;