graphql-modules 3.1.2-alpha-20260121024117-e03d9c26de1cfd3971986f82b995963e1cc77056 → 3.1.2-alpha-20260121024633-8af430e29a180a1d00c50c4bf74d342b3518267c

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 (161) 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/di/decorators.js +78 -0
  11. package/cjs/di/errors.js +87 -0
  12. package/cjs/di/forward-ref.js +26 -0
  13. package/cjs/di/index.js +19 -0
  14. package/cjs/di/injector.js +173 -0
  15. package/cjs/di/metadata.js +22 -0
  16. package/cjs/di/providers.js +60 -0
  17. package/cjs/di/registry.js +44 -0
  18. package/cjs/di/resolution.js +166 -0
  19. package/cjs/di/utils.js +44 -0
  20. package/cjs/index.js +31 -0
  21. package/cjs/module/factory.js +71 -0
  22. package/cjs/module/metadata.js +110 -0
  23. package/cjs/module/module.js +27 -0
  24. package/cjs/module/resolvers.js +341 -0
  25. package/cjs/module/tokens.js +21 -0
  26. package/cjs/module/type-defs.js +24 -0
  27. package/cjs/module/types.js +0 -0
  28. package/cjs/package.json +1 -0
  29. package/cjs/shared/di.js +0 -0
  30. package/cjs/shared/errors.js +82 -0
  31. package/cjs/shared/gql.js +12 -0
  32. package/cjs/shared/middleware.js +109 -0
  33. package/cjs/shared/types.js +0 -0
  34. package/cjs/shared/utils.js +115 -0
  35. package/cjs/testing/di.js +9 -0
  36. package/cjs/testing/graphql.js +10 -0
  37. package/cjs/testing/index.js +17 -0
  38. package/cjs/testing/test-application.js +65 -0
  39. package/cjs/testing/test-injector.js +22 -0
  40. package/cjs/testing/test-module.js +270 -0
  41. package/esm/application/apollo.js +77 -0
  42. package/esm/application/application.js +146 -0
  43. package/esm/application/context.js +140 -0
  44. package/esm/application/di.js +42 -0
  45. package/esm/application/execution.js +39 -0
  46. package/esm/application/operation-controller.js +13 -0
  47. package/esm/application/subscription.js +51 -0
  48. package/esm/application/tokens.js +17 -0
  49. package/esm/application/types.js +0 -0
  50. package/esm/di/decorators.js +72 -0
  51. package/esm/di/errors.js +79 -0
  52. package/esm/di/forward-ref.js +22 -0
  53. package/esm/di/index.js +4 -0
  54. package/esm/di/injector.js +168 -0
  55. package/esm/di/metadata.js +17 -0
  56. package/esm/di/providers.js +50 -0
  57. package/esm/di/registry.js +40 -0
  58. package/esm/di/resolution.js +159 -0
  59. package/esm/di/utils.js +36 -0
  60. package/esm/index.js +16 -0
  61. package/esm/module/factory.js +68 -0
  62. package/esm/module/metadata.js +107 -0
  63. package/esm/module/module.js +24 -0
  64. package/esm/module/resolvers.js +337 -0
  65. package/esm/module/tokens.js +18 -0
  66. package/esm/module/type-defs.js +21 -0
  67. package/esm/module/types.js +0 -0
  68. package/esm/shared/di.js +0 -0
  69. package/esm/shared/errors.js +69 -0
  70. package/esm/shared/gql.js +9 -0
  71. package/esm/shared/middleware.js +103 -0
  72. package/esm/shared/types.js +0 -0
  73. package/esm/shared/utils.js +101 -0
  74. package/esm/testing/di.js +6 -0
  75. package/esm/testing/graphql.js +7 -0
  76. package/esm/testing/index.js +14 -0
  77. package/esm/testing/test-application.js +62 -0
  78. package/esm/testing/test-injector.js +18 -0
  79. package/esm/testing/test-module.js +266 -0
  80. package/package.json +30 -10
  81. package/typings/application/apollo.d.ts +22 -0
  82. package/typings/application/application.d.ts +32 -0
  83. package/typings/application/context.d.ts +24 -0
  84. package/typings/application/di.d.ts +22 -0
  85. package/typings/application/execution.d.ts +8 -0
  86. package/typings/application/operation-controller.d.ts +5 -0
  87. package/typings/application/subscription.d.ts +8 -0
  88. package/typings/application/tokens.d.ts +17 -0
  89. package/typings/application/types.d.ts +130 -0
  90. package/typings/di/decorators.d.ts +11 -0
  91. package/typings/di/errors.d.ts +16 -0
  92. package/typings/di/forward-ref.d.ts +7 -0
  93. package/typings/di/index.d.ts +5 -0
  94. package/typings/di/injector.d.ts +50 -0
  95. package/typings/di/metadata.d.ts +12 -0
  96. package/typings/di/providers.d.ts +44 -0
  97. package/typings/di/registry.d.ts +11 -0
  98. package/typings/di/resolution.d.ts +63 -0
  99. package/typings/di/utils.d.ts +8 -0
  100. package/typings/index.d.ts +13 -0
  101. package/typings/module/factory.d.ts +16 -0
  102. package/typings/module/metadata.d.ts +12 -0
  103. package/typings/module/module.d.ts +22 -0
  104. package/typings/module/resolvers.d.ts +13 -0
  105. package/typings/module/tokens.d.ts +18 -0
  106. package/typings/module/type-defs.d.ts +7 -0
  107. package/typings/module/types.d.ts +51 -0
  108. package/typings/shared/di.d.ts +3 -0
  109. package/typings/shared/errors.d.ts +36 -0
  110. package/typings/shared/gql.d.ts +2 -0
  111. package/typings/shared/middleware.d.ts +21 -0
  112. package/typings/shared/types.d.ts +22 -0
  113. package/typings/shared/utils.d.ts +12 -0
  114. package/typings/testing/di.d.ts +2 -0
  115. package/typings/testing/graphql.d.ts +14 -0
  116. package/typings/testing/index.d.ts +14 -0
  117. package/typings/testing/test-application.d.ts +2 -0
  118. package/typings/testing/test-injector.d.ts +4 -0
  119. package/typings/testing/test-module.d.ts +10 -0
  120. package/LICENSE.md +0 -21
  121. package/index.js +0 -2359
  122. package/index.mjs +0 -2344
  123. /package/{application/apollo.d.ts → typings/application/apollo.d.cts} +0 -0
  124. /package/{application/application.d.ts → typings/application/application.d.cts} +0 -0
  125. /package/{application/context.d.ts → typings/application/context.d.cts} +0 -0
  126. /package/{application/di.d.ts → typings/application/di.d.cts} +0 -0
  127. /package/{application/execution.d.ts → typings/application/execution.d.cts} +0 -0
  128. /package/{application/operation-controller.d.ts → typings/application/operation-controller.d.cts} +0 -0
  129. /package/{application/subscription.d.ts → typings/application/subscription.d.cts} +0 -0
  130. /package/{application/tokens.d.ts → typings/application/tokens.d.cts} +0 -0
  131. /package/{application/types.d.ts → typings/application/types.d.cts} +0 -0
  132. /package/{di/decorators.d.ts → typings/di/decorators.d.cts} +0 -0
  133. /package/{di/errors.d.ts → typings/di/errors.d.cts} +0 -0
  134. /package/{di/forward-ref.d.ts → typings/di/forward-ref.d.cts} +0 -0
  135. /package/{di/index.d.ts → typings/di/index.d.cts} +0 -0
  136. /package/{di/injector.d.ts → typings/di/injector.d.cts} +0 -0
  137. /package/{di/metadata.d.ts → typings/di/metadata.d.cts} +0 -0
  138. /package/{di/providers.d.ts → typings/di/providers.d.cts} +0 -0
  139. /package/{di/registry.d.ts → typings/di/registry.d.cts} +0 -0
  140. /package/{di/resolution.d.ts → typings/di/resolution.d.cts} +0 -0
  141. /package/{di/utils.d.ts → typings/di/utils.d.cts} +0 -0
  142. /package/{index.d.ts → typings/index.d.cts} +0 -0
  143. /package/{module/factory.d.ts → typings/module/factory.d.cts} +0 -0
  144. /package/{module/metadata.d.ts → typings/module/metadata.d.cts} +0 -0
  145. /package/{module/module.d.ts → typings/module/module.d.cts} +0 -0
  146. /package/{module/resolvers.d.ts → typings/module/resolvers.d.cts} +0 -0
  147. /package/{module/tokens.d.ts → typings/module/tokens.d.cts} +0 -0
  148. /package/{module/type-defs.d.ts → typings/module/type-defs.d.cts} +0 -0
  149. /package/{module/types.d.ts → typings/module/types.d.cts} +0 -0
  150. /package/{shared/di.d.ts → typings/shared/di.d.cts} +0 -0
  151. /package/{shared/errors.d.ts → typings/shared/errors.d.cts} +0 -0
  152. /package/{shared/gql.d.ts → typings/shared/gql.d.cts} +0 -0
  153. /package/{shared/middleware.d.ts → typings/shared/middleware.d.cts} +0 -0
  154. /package/{shared/types.d.ts → typings/shared/types.d.cts} +0 -0
  155. /package/{shared/utils.d.ts → typings/shared/utils.d.cts} +0 -0
  156. /package/{testing/di.d.ts → typings/testing/di.d.cts} +0 -0
  157. /package/{testing/graphql.d.ts → typings/testing/graphql.d.cts} +0 -0
  158. /package/{testing/index.d.ts → typings/testing/index.d.cts} +0 -0
  159. /package/{testing/test-application.d.ts → typings/testing/test-application.d.cts} +0 -0
  160. /package/{testing/test-injector.d.ts → typings/testing/test-injector.d.cts} +0 -0
  161. /package/{testing/test-module.d.ts → typings/testing/test-module.d.cts} +0 -0
@@ -0,0 +1,32 @@
1
+ import { ResolvedModule } from '../module/factory';
2
+ import { ID } from '../shared/types';
3
+ import { ApplicationConfig, Application } from './types';
4
+ export type ModulesMap = Map<ID, ResolvedModule>;
5
+ /**
6
+ * @internal
7
+ */
8
+ export interface InternalAppContext {
9
+ ɵgetModuleContext(moduleId: ID, context: GraphQLModules.GlobalContext): GraphQLModules.ModuleContext;
10
+ }
11
+ /**
12
+ * @api
13
+ * Creates Application out of Modules. Accepts `ApplicationConfig`.
14
+ *
15
+ * @example
16
+ *
17
+ * ```typescript
18
+ * import { createApplication } from 'graphql-modules';
19
+ * import { usersModule } from './users';
20
+ * import { postsModule } from './posts';
21
+ * import { commentsModule } from './comments';
22
+ *
23
+ * const app = createApplication({
24
+ * modules: [
25
+ * usersModule,
26
+ * postsModule,
27
+ * commentsModule
28
+ * ]
29
+ * })
30
+ * ```
31
+ */
32
+ export declare function createApplication(applicationConfig: ApplicationConfig): Application;
@@ -0,0 +1,24 @@
1
+ import { Injector, ReflectiveInjector } from '../di';
2
+ import { ResolvedProvider } from '../di/resolution';
3
+ import type { InternalAppContext, ModulesMap } from './application';
4
+ export type ExecutionContextBuilder<TContext extends {
5
+ [key: string]: any;
6
+ } = {}> = (context: TContext) => ExecutionContextEnv & {
7
+ runWithContext<TReturn = any>(cb: (env: ExecutionContextEnv) => TReturn): TReturn;
8
+ };
9
+ export type ExecutionContextEnv = {
10
+ context: InternalAppContext;
11
+ ɵdestroy(): void;
12
+ ɵinjector: Injector;
13
+ };
14
+ export declare function createContextBuilder({ appInjector, modulesMap, appLevelOperationProviders, singletonGlobalProvidersMap, operationGlobalProvidersMap, }: {
15
+ appInjector: ReflectiveInjector;
16
+ appLevelOperationProviders: ResolvedProvider[];
17
+ singletonGlobalProvidersMap: {
18
+ [key: string]: string;
19
+ };
20
+ operationGlobalProvidersMap: {
21
+ [key: string]: string;
22
+ };
23
+ modulesMap: ModulesMap;
24
+ }): ExecutionContextBuilder<GraphQLModules.GlobalContext>;
@@ -0,0 +1,22 @@
1
+ import { ModulesMap } from './application';
2
+ import { ResolvedModule } from '../module/factory';
3
+ import { ReflectiveInjector, Scope } from '../di';
4
+ import { ResolvedProvider } from '../di/resolution';
5
+ export declare function instantiateSingletonProviders({ appInjector, modulesMap, }: {
6
+ appInjector: ReflectiveInjector;
7
+ modulesMap: ModulesMap;
8
+ }): void;
9
+ export declare function createGlobalProvidersMap({ modules, scope, }: {
10
+ modules: ResolvedModule[];
11
+ scope: Scope;
12
+ }): {
13
+ [key: string]: string;
14
+ };
15
+ export declare function attachGlobalProvidersMap({ injector, globalProvidersMap, moduleInjectorGetter, }: {
16
+ injector: ReflectiveInjector;
17
+ globalProvidersMap: {
18
+ [key: string]: string;
19
+ };
20
+ moduleInjectorGetter: (moduleId: string) => ReflectiveInjector;
21
+ }): void;
22
+ export declare function duplicatedGlobalTokenError(provider: ResolvedProvider, modules: [string, string]): Error;
@@ -0,0 +1,8 @@
1
+ import { execute } from 'graphql';
2
+ import { ExecutionContextBuilder } from './context';
3
+ export declare function executionCreator({ contextBuilder, }: {
4
+ contextBuilder: ExecutionContextBuilder;
5
+ }): (options?: {
6
+ execute?: typeof execute;
7
+ controller?: import("./types").OperationController;
8
+ }) => typeof execute;
@@ -0,0 +1,5 @@
1
+ import type { Application } from './types';
2
+ import type { ExecutionContextBuilder } from './context';
3
+ export declare function operationControllerCreator(options: {
4
+ contextBuilder: ExecutionContextBuilder<GraphQLModules.GlobalContext>;
5
+ }): Application['createOperationController'];
@@ -0,0 +1,8 @@
1
+ import { subscribe } from 'graphql';
2
+ import { ExecutionContextBuilder } from './context';
3
+ export declare function subscriptionCreator({ contextBuilder, }: {
4
+ contextBuilder: ExecutionContextBuilder;
5
+ }): (options?: {
6
+ subscribe?: typeof subscribe;
7
+ controller?: import("./types").OperationController;
8
+ }) => typeof subscribe;
@@ -0,0 +1,17 @@
1
+ import { InjectionToken } from '../di';
2
+ /**
3
+ * @api
4
+ * `CONTEXT` is an InjectionToken representing the provided `GraphQLModules.GlobalContext`
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import { CONTEXT, Inject, Injectable } from 'graphql-modules';
10
+ *
11
+ * (A)Injectable()
12
+ * export class Data {
13
+ * constructor((A)Inject(CONTEXT) private context: GraphQLModules.GlobalContext) {}
14
+ * }
15
+ * ```
16
+ */
17
+ export declare const CONTEXT: InjectionToken<any>;
@@ -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
+ }