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,159 @@
1
+ import { Type, isClassProvider, isFactoryProvider, } from './providers';
2
+ import { invalidProviderError, noAnnotationError } from './errors';
3
+ import { Key } from './registry';
4
+ import { resolveForwardRef } from './forward-ref';
5
+ import { readInjectableMetadata } from './metadata';
6
+ const _EMPTY_LIST = [];
7
+ export class ResolvedProvider {
8
+ constructor(key, factory) {
9
+ this.key = key;
10
+ this.factory = factory;
11
+ }
12
+ }
13
+ export class ResolvedFactory {
14
+ constructor(
15
+ /**
16
+ * Factory function which can return an instance of an object represented by a key.
17
+ */
18
+ factory,
19
+ /**
20
+ * Arguments (dependencies) to the `factory` function.
21
+ */
22
+ dependencies,
23
+ /**
24
+ * Methods invoked within ExecutionContext.
25
+ */
26
+ executionContextIn,
27
+ /**
28
+ * Has onDestroy hook
29
+ */
30
+ hasOnDestroyHook,
31
+ /**
32
+ * Is Global
33
+ */
34
+ isGlobal) {
35
+ this.factory = factory;
36
+ this.dependencies = dependencies;
37
+ this.executionContextIn = executionContextIn;
38
+ this.hasOnDestroyHook = hasOnDestroyHook;
39
+ this.isGlobal = isGlobal;
40
+ }
41
+ }
42
+ export class Dependency {
43
+ constructor(key, optional) {
44
+ this.key = key;
45
+ this.optional = optional;
46
+ }
47
+ static fromKey(key) {
48
+ return new Dependency(key, false);
49
+ }
50
+ }
51
+ export function resolveProviders(providers) {
52
+ const normalized = normalizeProviders(providers, []);
53
+ const resolved = normalized.map(resolveProvider);
54
+ const resolvedProviderMap = mergeResolvedProviders(resolved, new Map());
55
+ return Array.from(resolvedProviderMap.values());
56
+ }
57
+ function resolveProvider(provider) {
58
+ return new ResolvedProvider(Key.get(provider.provide), resolveFactory(provider));
59
+ }
60
+ function mergeResolvedProviders(providers, normalizedProvidersMap) {
61
+ for (let i = 0; i < providers.length; i++) {
62
+ const provider = providers[i];
63
+ normalizedProvidersMap.set(provider.key.id, provider);
64
+ }
65
+ return normalizedProvidersMap;
66
+ }
67
+ function normalizeProviders(providers, res) {
68
+ providers.forEach((token) => {
69
+ if (token instanceof Type) {
70
+ res.push({ provide: token, useClass: token });
71
+ }
72
+ else if (token &&
73
+ typeof token === 'object' &&
74
+ token.provide !== undefined) {
75
+ res.push(token);
76
+ }
77
+ else if (token instanceof Array) {
78
+ normalizeProviders(token, res);
79
+ }
80
+ else {
81
+ throw invalidProviderError(token);
82
+ }
83
+ });
84
+ return res;
85
+ }
86
+ function resolveFactory(provider) {
87
+ let factoryFn;
88
+ let resolvedDeps = _EMPTY_LIST;
89
+ let executionContextIn = _EMPTY_LIST;
90
+ let hasOnDestroyHook = false;
91
+ let isGlobal;
92
+ if (isClassProvider(provider)) {
93
+ const useClass = resolveForwardRef(provider.useClass);
94
+ factoryFn = makeFactory(useClass);
95
+ resolvedDeps = dependenciesFor(useClass);
96
+ executionContextIn = executionContextInFor(useClass);
97
+ isGlobal = globalFor(useClass);
98
+ hasOnDestroyHook = typeof useClass.prototype.onDestroy === 'function';
99
+ }
100
+ else if (isFactoryProvider(provider)) {
101
+ factoryFn = provider.useFactory;
102
+ resolvedDeps = constructDependencies(provider.useFactory, provider.deps || []);
103
+ isGlobal = provider.global;
104
+ if (provider.executionContextIn) {
105
+ executionContextIn = provider.executionContextIn;
106
+ }
107
+ }
108
+ else {
109
+ factoryFn = () => provider.useValue;
110
+ resolvedDeps = _EMPTY_LIST;
111
+ isGlobal = provider.global;
112
+ }
113
+ return new ResolvedFactory(factoryFn, resolvedDeps, executionContextIn, hasOnDestroyHook, isGlobal !== null && isGlobal !== void 0 ? isGlobal : false);
114
+ }
115
+ function dependenciesFor(type) {
116
+ const { params } = readInjectableMetadata(type, true);
117
+ if (!params) {
118
+ return [];
119
+ }
120
+ if (params.some((p) => p.type == null)) {
121
+ throw noAnnotationError(type, params);
122
+ }
123
+ return params.map((p) => extractToken(p, params));
124
+ }
125
+ function executionContextInFor(type) {
126
+ const { options } = readInjectableMetadata(type, true);
127
+ if ((options === null || options === void 0 ? void 0 : options.executionContextIn) &&
128
+ options.executionContextIn !== _EMPTY_LIST) {
129
+ return options === null || options === void 0 ? void 0 : options.executionContextIn;
130
+ }
131
+ return [];
132
+ }
133
+ function globalFor(type) {
134
+ var _a;
135
+ const { options } = readInjectableMetadata(type);
136
+ return (_a = options === null || options === void 0 ? void 0 : options.global) !== null && _a !== void 0 ? _a : false;
137
+ }
138
+ function constructDependencies(typeOrFunc, dependencies) {
139
+ if (!dependencies) {
140
+ return dependenciesFor(typeOrFunc);
141
+ }
142
+ else {
143
+ const params = dependencies.map((d) => ({ type: d, optional: false }));
144
+ return params.map((t) => extractToken(t, params));
145
+ }
146
+ }
147
+ function extractToken(param, params) {
148
+ const token = resolveForwardRef(param.type);
149
+ if (token) {
150
+ return createDependency(token, param.optional);
151
+ }
152
+ throw noAnnotationError(param.type, params);
153
+ }
154
+ function createDependency(token, optional) {
155
+ return new Dependency(Key.get(token), optional);
156
+ }
157
+ function makeFactory(t) {
158
+ return (...args) => new t(...args);
159
+ }
@@ -0,0 +1,36 @@
1
+ export const ERROR_TYPE = 'diType';
2
+ export const ERROR_ORIGINAL_ERROR = 'diOriginalError';
3
+ export const ERROR_LOGGER = 'diErrorLogger';
4
+ export function getType(error) {
5
+ return error[ERROR_TYPE];
6
+ }
7
+ export function getOriginalError(error) {
8
+ return error[ERROR_ORIGINAL_ERROR];
9
+ }
10
+ function defaultErrorLogger(console, ...values) {
11
+ // eslint-disable-next-line no-console
12
+ console.error(...values);
13
+ }
14
+ export function getErrorLogger(error) {
15
+ return error[ERROR_LOGGER] || defaultErrorLogger;
16
+ }
17
+ export function wrappedError(message, originalError) {
18
+ const msg = `${message} caused by: ${originalError instanceof Error ? originalError.message : originalError}`;
19
+ const error = Error(msg);
20
+ error[ERROR_ORIGINAL_ERROR] = originalError;
21
+ return error;
22
+ }
23
+ export function stringify(token) {
24
+ if (typeof token === 'string') {
25
+ return token;
26
+ }
27
+ if (token == null) {
28
+ return '' + token;
29
+ }
30
+ if (token.name) {
31
+ return `${token.name}`;
32
+ }
33
+ const res = token.toString();
34
+ const newLineIndex = res.indexOf('\n');
35
+ return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
36
+ }
package/esm/index.js ADDED
@@ -0,0 +1,16 @@
1
+ // application
2
+ export { createApplication } from './application/application';
3
+ export * from './application/tokens';
4
+ export * from './application/types';
5
+ // modules
6
+ export { createModule } from './module/module';
7
+ export * from './module/types';
8
+ export * from './module/metadata';
9
+ export * from './module/tokens';
10
+ // di
11
+ export { Injector, Inject, Injectable, Optional, ExecutionContext, forwardRef, InjectionToken, Scope, } from './di';
12
+ import './shared/types';
13
+ export { gql } from './shared/gql';
14
+ export * from './shared/di';
15
+ // testing
16
+ export * from './testing';
@@ -0,0 +1,68 @@
1
+ import { metadataFactory } from './metadata';
2
+ import { createResolvers } from './resolvers';
3
+ import { createTypeDefs } from './type-defs';
4
+ import { MODULE_ID } from './tokens';
5
+ import { ReflectiveInjector, onlySingletonProviders, onlyOperationProviders, } from '../di';
6
+ import { resolveProviders } from './../di/resolution';
7
+ function lazy(getter) {
8
+ let called = false;
9
+ let computedValue;
10
+ return {
11
+ get value() {
12
+ if (!called) {
13
+ called = true;
14
+ computedValue = getter();
15
+ }
16
+ return computedValue;
17
+ },
18
+ };
19
+ }
20
+ export function moduleFactory(config) {
21
+ const typeDefs = createTypeDefs(config);
22
+ const metadata = metadataFactory(typeDefs, config);
23
+ const providers = lazy(() => typeof config.providers === 'function'
24
+ ? config.providers()
25
+ : config.providers);
26
+ // Filter providers and keep them this way
27
+ // so we don't do this filtering multiple times.
28
+ // Providers don't change over time, so it's safe to do it.
29
+ const operationProviders = lazy(() => ReflectiveInjector.resolve(onlyOperationProviders(providers.value)));
30
+ const singletonProviders = lazy(() => ReflectiveInjector.resolve(onlySingletonProviders(providers.value)));
31
+ const mod = {
32
+ id: config.id,
33
+ config,
34
+ metadata,
35
+ typeDefs,
36
+ // Factory is called once on application creation,
37
+ // before we even handle GraphQL Operation
38
+ factory(app) {
39
+ const resolvedModule = mod;
40
+ resolvedModule.singletonProviders = singletonProviders.value;
41
+ resolvedModule.operationProviders = operationProviders.value;
42
+ // Create a module-level Singleton injector
43
+ const injector = ReflectiveInjector.createFromResolved({
44
+ name: `Module "${config.id}" (Singleton Scope)`,
45
+ providers: resolvedModule.singletonProviders.concat(resolveProviders([
46
+ {
47
+ // with module's id, useful in Logging and stuff
48
+ provide: MODULE_ID,
49
+ useValue: config.id,
50
+ },
51
+ ])),
52
+ parent: app.injector,
53
+ });
54
+ // We attach injector property to existing `mod` object
55
+ // because we want to keep references
56
+ // that are later on used in testing utils
57
+ resolvedModule.injector = injector;
58
+ // Create resolvers object based on module's config
59
+ // It involves wrapping a resolver with middlewares
60
+ // and other things like validation
61
+ resolvedModule.resolvers = createResolvers(config, metadata, {
62
+ middlewareMap: app.middlewares,
63
+ });
64
+ return resolvedModule;
65
+ },
66
+ };
67
+ return mod;
68
+ }
@@ -0,0 +1,107 @@
1
+ import { visit, Kind, } from 'graphql';
2
+ export function metadataFactory(typeDefs, config) {
3
+ const implemented = {};
4
+ const extended = {};
5
+ function collectObjectDefinition(node) {
6
+ if (!implemented[node.name.value]) {
7
+ implemented[node.name.value] = [];
8
+ }
9
+ if (node.fields && node.fields.length > 0) {
10
+ implemented[node.name.value].push(...node.fields.map((field) => field.name.value));
11
+ }
12
+ if (node.kind === Kind.OBJECT_TYPE_DEFINITION) {
13
+ implemented[node.name.value].push('__isTypeOf');
14
+ }
15
+ if (node.kind === Kind.OBJECT_TYPE_DEFINITION) {
16
+ implemented[node.name.value].push('__resolveReference');
17
+ implemented[node.name.value].push('__resolveObject');
18
+ }
19
+ if (node.kind === Kind.INTERFACE_TYPE_DEFINITION) {
20
+ implemented[node.name.value].push('__resolveType');
21
+ }
22
+ }
23
+ function collectObjectExtension(node) {
24
+ if (node.fields) {
25
+ if (!extended[node.name.value]) {
26
+ extended[node.name.value] = [];
27
+ }
28
+ node.fields.forEach((field) => {
29
+ extended[node.name.value].push(field.name.value);
30
+ });
31
+ }
32
+ }
33
+ for (const doc of typeDefs) {
34
+ visit(doc, {
35
+ // Object
36
+ ObjectTypeDefinition(node) {
37
+ collectObjectDefinition(node);
38
+ },
39
+ ObjectTypeExtension(node) {
40
+ collectObjectExtension(node);
41
+ },
42
+ // Interface
43
+ InterfaceTypeDefinition(node) {
44
+ collectObjectDefinition(node);
45
+ },
46
+ InterfaceTypeExtension(node) {
47
+ collectObjectExtension(node);
48
+ },
49
+ // Union
50
+ UnionTypeDefinition(node) {
51
+ if (!implemented[node.name.value]) {
52
+ implemented[node.name.value] = [];
53
+ }
54
+ if (node.types) {
55
+ implemented[node.name.value].push(...node.types.map((type) => type.name.value));
56
+ }
57
+ implemented[node.name.value].push('__resolveType');
58
+ },
59
+ UnionTypeExtension(node) {
60
+ if (node.types) {
61
+ if (!extended[node.name.value]) {
62
+ extended[node.name.value] = [];
63
+ }
64
+ extended[node.name.value].push(...node.types.map((type) => type.name.value));
65
+ }
66
+ },
67
+ // Input
68
+ InputObjectTypeDefinition(node) {
69
+ collectObjectDefinition(node);
70
+ },
71
+ InputObjectTypeExtension(node) {
72
+ collectObjectExtension(node);
73
+ },
74
+ // Enum
75
+ EnumTypeDefinition(node) {
76
+ if (node.values) {
77
+ if (!implemented[node.name.value]) {
78
+ implemented[node.name.value] = [];
79
+ }
80
+ implemented[node.name.value].push(...node.values.map((value) => value.name.value));
81
+ }
82
+ },
83
+ EnumTypeExtension(node) {
84
+ if (node.values) {
85
+ if (!extended[node.name.value]) {
86
+ extended[node.name.value] = [];
87
+ }
88
+ extended[node.name.value].push(...node.values.map((value) => value.name.value));
89
+ }
90
+ },
91
+ // Scalar
92
+ ScalarTypeDefinition(node) {
93
+ if (!implemented.__scalars) {
94
+ implemented.__scalars = [];
95
+ }
96
+ implemented.__scalars.push(node.name.value);
97
+ },
98
+ });
99
+ }
100
+ return {
101
+ id: config.id,
102
+ typeDefs,
103
+ implements: implemented,
104
+ extends: extended,
105
+ dirname: config.dirname,
106
+ };
107
+ }
@@ -0,0 +1,24 @@
1
+ import { moduleFactory } from './factory';
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 function createModule(config) {
23
+ return moduleFactory(config);
24
+ }