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,14 @@
1
+ import { mockApplication } from './test-application';
2
+ import { testModule, mockModule } from './test-module';
3
+ import { testInjector, readProviderOptions } from './test-injector';
4
+ import { execute } from './graphql';
5
+ import { provideEmpty } from './di';
6
+ export const testkit = {
7
+ mockApplication,
8
+ mockModule,
9
+ testModule,
10
+ testInjector,
11
+ readProviderOptions,
12
+ provideEmpty,
13
+ execute,
14
+ };
@@ -0,0 +1,62 @@
1
+ import { share } from '../shared/utils';
2
+ export function mockApplication(app) {
3
+ function mockedFactory(newConfig) {
4
+ const sharedFactory = share(() => app.ɵfactory(newConfig));
5
+ return {
6
+ get typeDefs() {
7
+ return sharedFactory().typeDefs;
8
+ },
9
+ get resolvers() {
10
+ return sharedFactory().resolvers;
11
+ },
12
+ get schema() {
13
+ return sharedFactory().schema;
14
+ },
15
+ get injector() {
16
+ return sharedFactory().injector;
17
+ },
18
+ createOperationController(options) {
19
+ return sharedFactory().createOperationController(options);
20
+ },
21
+ createSubscription(options) {
22
+ return sharedFactory().createSubscription(options);
23
+ },
24
+ createExecution(options) {
25
+ return sharedFactory().createExecution(options);
26
+ },
27
+ createSchemaForApollo() {
28
+ return sharedFactory().createSchemaForApollo();
29
+ },
30
+ createApolloExecutor() {
31
+ return sharedFactory().createApolloExecutor();
32
+ },
33
+ get ɵfactory() {
34
+ return sharedFactory().ɵfactory;
35
+ },
36
+ get ɵconfig() {
37
+ return sharedFactory().ɵconfig;
38
+ },
39
+ replaceModule(newModule) {
40
+ const config = sharedFactory().ɵconfig;
41
+ return mockedFactory({
42
+ ...config,
43
+ modules: config.modules.map((mod) => mod.id === newModule.ɵoriginalModule.id ? newModule : mod),
44
+ });
45
+ },
46
+ addProviders(newProviders) {
47
+ const config = sharedFactory().ɵconfig;
48
+ const existingProviders = typeof config.providers === 'function'
49
+ ? config.providers()
50
+ : config.providers;
51
+ const providers = Array.isArray(existingProviders)
52
+ ? existingProviders.concat(newProviders)
53
+ : newProviders;
54
+ return mockedFactory({
55
+ ...config,
56
+ providers,
57
+ });
58
+ },
59
+ };
60
+ }
61
+ return mockedFactory();
62
+ }
@@ -0,0 +1,18 @@
1
+ import { ReflectiveInjector } from '../di/injector';
2
+ import { CONTEXT } from '../application/tokens';
3
+ import { readInjectableMetadata } from '../di/metadata';
4
+ export function testInjector(providers) {
5
+ const resolvedProviders = ReflectiveInjector.resolve([
6
+ { provide: CONTEXT, useValue: {} },
7
+ ...providers,
8
+ ]);
9
+ const injector = ReflectiveInjector.createFromResolved({
10
+ name: 'test',
11
+ providers: resolvedProviders,
12
+ });
13
+ injector.instantiateAll();
14
+ return injector;
15
+ }
16
+ export function readProviderOptions(provider) {
17
+ return readInjectableMetadata(provider, true).options;
18
+ }
@@ -0,0 +1,266 @@
1
+ import { visit, Kind, concatAST, } from 'graphql';
2
+ import { moduleFactory } from '../module/factory';
3
+ import { createApplication } from '../application/application';
4
+ import { createModule } from '../module/module';
5
+ export function mockModule(testedModule, overrideConfig) {
6
+ const sourceProviders = typeof testedModule.config.providers === 'function'
7
+ ? testedModule.config.providers()
8
+ : testedModule.config.providers;
9
+ const overrideProviders = typeof overrideConfig.providers === 'function'
10
+ ? overrideConfig.providers()
11
+ : overrideConfig.providers;
12
+ const newModule = createModule({
13
+ ...testedModule.config,
14
+ providers: [...(sourceProviders || []), ...(overrideProviders || [])],
15
+ });
16
+ newModule['ɵoriginalModule'] = testedModule;
17
+ return newModule;
18
+ }
19
+ export function testModule(testedModule, config) {
20
+ var _a;
21
+ const mod = transformModule(testedModule, config);
22
+ const modules = [mod].concat((_a = config === null || config === void 0 ? void 0 : config.modules) !== null && _a !== void 0 ? _a : []);
23
+ return createApplication({
24
+ ...(config || {}),
25
+ modules,
26
+ providers: config === null || config === void 0 ? void 0 : config.providers,
27
+ middlewares: config === null || config === void 0 ? void 0 : config.middlewares,
28
+ });
29
+ }
30
+ function transformModule(mod, config) {
31
+ const transforms = [];
32
+ if (config === null || config === void 0 ? void 0 : config.replaceExtensions) {
33
+ transforms.push((m) => moduleFactory({
34
+ ...m.config,
35
+ typeDefs: replaceExtensions(m.typeDefs),
36
+ }));
37
+ }
38
+ if (config === null || config === void 0 ? void 0 : config.typeDefs) {
39
+ transforms.push((m) => moduleFactory({
40
+ ...m.config,
41
+ typeDefs: m.typeDefs.concat(config.typeDefs),
42
+ }));
43
+ }
44
+ if (config === null || config === void 0 ? void 0 : config.inheritTypeDefs) {
45
+ transforms.push((m) => moduleFactory({
46
+ ...m.config,
47
+ typeDefs: inheritTypeDefs(m.typeDefs, config.inheritTypeDefs),
48
+ }));
49
+ }
50
+ if (config === null || config === void 0 ? void 0 : config.resolvers) {
51
+ transforms.push((m) => {
52
+ const resolvers = m.config.resolvers
53
+ ? Array.isArray(m.config.resolvers)
54
+ ? m.config.resolvers
55
+ : [m.config.resolvers]
56
+ : [];
57
+ return moduleFactory({
58
+ ...m.config,
59
+ resolvers: resolvers.concat(config.resolvers),
60
+ });
61
+ });
62
+ }
63
+ if (config === null || config === void 0 ? void 0 : config.providers) {
64
+ transforms.push((m) => {
65
+ const sourceProviders = typeof m.config.providers === 'function'
66
+ ? m.config.providers()
67
+ : m.config.providers;
68
+ const overrideProviders = typeof config.providers === 'function'
69
+ ? config.providers()
70
+ : config.providers;
71
+ return moduleFactory({
72
+ ...m.config,
73
+ providers: [...(sourceProviders || []), ...(overrideProviders || [])],
74
+ });
75
+ });
76
+ }
77
+ if (transforms) {
78
+ return transforms.reduce((m, transform) => transform(m), mod);
79
+ }
80
+ return mod;
81
+ }
82
+ function inheritTypeDefs(originalTypeDefs, modules) {
83
+ const original = concatAST(originalTypeDefs);
84
+ const typeDefs = treeshakeTypesDefs(original, modules.reduce((typeDefs, externalMod) => typeDefs.concat(externalMod.typeDefs), []));
85
+ return typeDefs;
86
+ }
87
+ function replaceExtensions(typeDefs) {
88
+ const types = [];
89
+ const extensions = [];
90
+ // List all object types
91
+ typeDefs.forEach((doc) => {
92
+ visit(doc, {
93
+ ObjectTypeDefinition(node) {
94
+ types.push(node.name.value);
95
+ },
96
+ });
97
+ });
98
+ // turn object type extensions into object types
99
+ return typeDefs.map((doc) => {
100
+ return visit(doc, {
101
+ ObjectTypeExtension(node) {
102
+ // only if object type doesn't exist
103
+ if (extensions.includes(node.name.value) ||
104
+ types.includes(node.name.value)) {
105
+ return node;
106
+ }
107
+ return {
108
+ ...node,
109
+ kind: Kind.OBJECT_TYPE_DEFINITION,
110
+ };
111
+ },
112
+ });
113
+ });
114
+ }
115
+ function treeshakeTypesDefs(originalSource, sources) {
116
+ const namedTypes = originalSource.definitions.filter(isNamedTypeDefinition);
117
+ const typesToVisit = namedTypes.map((def) => def.name.value);
118
+ const rootFields = namedTypes.reduce((acc, node) => {
119
+ const typeName = node.name.value;
120
+ if (isRootType(typeName) && hasFields(node)) {
121
+ if (!acc[typeName]) {
122
+ acc[typeName] = [];
123
+ }
124
+ node.fields.forEach((field) => {
125
+ acc[typeName].push(field.name.value);
126
+ });
127
+ }
128
+ return acc;
129
+ }, {});
130
+ const schema = concatAST([originalSource].concat(sources));
131
+ const involvedTypes = new Set(visitTypes(schema, typesToVisit, rootFields));
132
+ return {
133
+ kind: Kind.DOCUMENT,
134
+ definitions: schema.definitions.filter((def) => {
135
+ var _a, _b;
136
+ if (isNamedTypeDefinition(def)) {
137
+ const typeName = def.name.value;
138
+ if (!involvedTypes.has(def.name.value)) {
139
+ return false;
140
+ }
141
+ if ((_a = rootFields[typeName]) === null || _a === void 0 ? void 0 : _a.length) {
142
+ const rootType = def;
143
+ if ((_b = rootType.fields) === null || _b === void 0 ? void 0 : _b.every((field) => !rootFields[typeName].includes(field.name.value))) {
144
+ return false;
145
+ }
146
+ }
147
+ }
148
+ return true;
149
+ }),
150
+ };
151
+ }
152
+ function isNamedTypeDefinition(def) {
153
+ return (!!def &&
154
+ def.kind !== Kind.SCHEMA_DEFINITION &&
155
+ def.kind !== Kind.SCHEMA_EXTENSION);
156
+ }
157
+ function visitTypes(schema, types, rootFields) {
158
+ const visitedTypes = [];
159
+ const scalars = schema.definitions
160
+ .filter((def) => def.kind === Kind.SCALAR_TYPE_DEFINITION ||
161
+ def.kind === Kind.SCALAR_TYPE_EXTENSION)
162
+ .map((def) => def.name.value);
163
+ for (const typeName of types) {
164
+ collectType(typeName);
165
+ }
166
+ return visitedTypes;
167
+ function collectField(field, parentTypeName) {
168
+ var _a;
169
+ if (parentTypeName &&
170
+ isRootType(parentTypeName) &&
171
+ ((_a = rootFields[parentTypeName]) === null || _a === void 0 ? void 0 : _a.length) &&
172
+ !rootFields[parentTypeName].includes(field.name.value)) {
173
+ return;
174
+ }
175
+ collectType(resolveType(field.type));
176
+ if (field.arguments) {
177
+ field.arguments.forEach((arg) => {
178
+ collectType(resolveType(arg.type));
179
+ });
180
+ }
181
+ if (field.directives) {
182
+ field.directives.forEach((directive) => {
183
+ collectType(directive.name.value);
184
+ });
185
+ }
186
+ }
187
+ function collectType(typeName) {
188
+ if (visitedTypes.includes(typeName)) {
189
+ return;
190
+ }
191
+ if (isScalar(typeName)) {
192
+ visitedTypes.push(typeName);
193
+ return;
194
+ }
195
+ const types = findTypes(typeName);
196
+ visitedTypes.push(typeName);
197
+ types.forEach((type) => {
198
+ if (hasFields(type)) {
199
+ type.fields.forEach((field) => {
200
+ collectField(field, typeName);
201
+ });
202
+ }
203
+ if (hasTypes(type)) {
204
+ type.types.forEach((t) => {
205
+ collectType(resolveType(t));
206
+ });
207
+ }
208
+ if (hasInterfaces(type)) {
209
+ type.interfaces.forEach((i) => {
210
+ collectType(resolveType(i));
211
+ });
212
+ }
213
+ });
214
+ }
215
+ function resolveType(type) {
216
+ if (type.kind === 'ListType') {
217
+ return resolveType(type.type);
218
+ }
219
+ if (type.kind === 'NonNullType') {
220
+ return resolveType(type.type);
221
+ }
222
+ return type.name.value;
223
+ }
224
+ function isScalar(name) {
225
+ return scalars
226
+ .concat(['String', 'Boolean', 'Int', 'ID', 'Float'])
227
+ .includes(name);
228
+ }
229
+ function findTypes(typeName) {
230
+ const types = schema.definitions.filter((def) => isNamedTypeDefinition(def) && def.name.value === typeName);
231
+ if (!types.length) {
232
+ throw new Error(`Missing type "${typeName}"`);
233
+ }
234
+ return types;
235
+ }
236
+ }
237
+ function hasInterfaces(def) {
238
+ return (hasPropValue(def, 'interfaces') &&
239
+ [
240
+ Kind.OBJECT_TYPE_DEFINITION,
241
+ Kind.OBJECT_TYPE_EXTENSION,
242
+ Kind.INTERFACE_TYPE_DEFINITION,
243
+ Kind.INTERFACE_TYPE_EXTENSION,
244
+ ].includes(def.kind));
245
+ }
246
+ function hasTypes(def) {
247
+ return ([Kind.UNION_TYPE_DEFINITION, Kind.UNION_TYPE_EXTENSION].includes(def.kind) && hasPropValue(def, 'types'));
248
+ }
249
+ function hasFields(def) {
250
+ return ([
251
+ Kind.OBJECT_TYPE_DEFINITION,
252
+ Kind.OBJECT_TYPE_EXTENSION,
253
+ Kind.INTERFACE_TYPE_DEFINITION,
254
+ Kind.INTERFACE_TYPE_EXTENSION,
255
+ Kind.INPUT_OBJECT_TYPE_DEFINITION,
256
+ Kind.INPUT_OBJECT_TYPE_EXTENSION,
257
+ ].includes(def.kind) && hasPropValue(def, 'fields'));
258
+ }
259
+ function hasPropValue(obj, prop) {
260
+ return Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop];
261
+ }
262
+ function isRootType(typeName) {
263
+ return (typeName === 'Query' ||
264
+ typeName === 'Mutation' ||
265
+ typeName === 'Subscription');
266
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-modules",
3
- "version": "3.1.2-alpha-20260121024117-e03d9c26de1cfd3971986f82b995963e1cc77056",
3
+ "version": "3.1.2-alpha-20260121025807-95ab4fb1994c3cf68c88a7cf234efd8f99f92ed1",
4
4
  "description": "Create reusable, maintainable, testable and extendable GraphQL modules",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -21,20 +21,40 @@
21
21
  ],
22
22
  "author": "Kamil Kisiela",
23
23
  "license": "MIT",
24
- "main": "index.js",
25
- "module": "index.mjs",
26
- "typings": "index.d.ts",
24
+ "main": "cjs/index.js",
25
+ "module": "esm/index.js",
26
+ "typings": "typings/index.d.ts",
27
27
  "typescript": {
28
- "definition": "index.d.ts"
28
+ "definition": "typings/index.d.ts"
29
29
  },
30
30
  "exports": {
31
31
  ".": {
32
- "require": "./index.js",
33
- "import": "./index.mjs"
32
+ "require": {
33
+ "types": "./typings/index.d.cts",
34
+ "default": "./cjs/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./typings/index.d.ts",
38
+ "default": "./esm/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./typings/index.d.ts",
42
+ "default": "./esm/index.js"
43
+ }
34
44
  },
35
45
  "./*": {
36
- "require": "./*.js",
37
- "import": "./*.mjs"
46
+ "require": {
47
+ "types": "./typings/*.d.cts",
48
+ "default": "./cjs/*.js"
49
+ },
50
+ "import": {
51
+ "types": "./typings/*.d.ts",
52
+ "default": "./esm/*.js"
53
+ },
54
+ "default": {
55
+ "types": "./typings/*.d.ts",
56
+ "default": "./esm/*.js"
57
+ }
38
58
  },
39
59
  "./package.json": "./package.json"
40
60
  },
@@ -0,0 +1,22 @@
1
+ import { DocumentNode, GraphQLSchema } from 'graphql';
2
+ import { ExecutionContextBuilder } from './context';
3
+ import { Application } from './types';
4
+ export interface ApolloRequestContext {
5
+ document: DocumentNode;
6
+ operationName?: string | null;
7
+ context?: any;
8
+ schema: GraphQLSchema;
9
+ request: {
10
+ variables?: {
11
+ [name: string]: any;
12
+ } | null;
13
+ };
14
+ }
15
+ export declare function apolloExecutorCreator({ createExecution, }: {
16
+ createExecution: Application['createExecution'];
17
+ }): Application['createApolloExecutor'];
18
+ export declare function apolloSchemaCreator({ createSubscription, contextBuilder, schema, }: {
19
+ createSubscription: Application['createSubscription'];
20
+ contextBuilder: ExecutionContextBuilder;
21
+ schema: GraphQLSchema;
22
+ }): () => GraphQLSchema;
@@ -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>;