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.
- package/cjs/application/apollo.js +81 -0
- package/cjs/application/application.js +149 -0
- package/cjs/application/context.js +144 -0
- package/cjs/application/di.js +48 -0
- package/cjs/application/execution.js +42 -0
- package/cjs/application/operation-controller.js +16 -0
- package/cjs/application/subscription.js +54 -0
- package/cjs/application/tokens.js +20 -0
- package/cjs/application/types.js +0 -0
- package/cjs/async-context.browser.mjs +7 -0
- package/cjs/async-context.node.cjs +14 -0
- package/cjs/di/decorators.js +78 -0
- package/cjs/di/errors.js +87 -0
- package/cjs/di/forward-ref.js +26 -0
- package/cjs/di/index.js +19 -0
- package/cjs/di/injector.js +173 -0
- package/cjs/di/metadata.js +22 -0
- package/cjs/di/providers.js +60 -0
- package/cjs/di/registry.js +44 -0
- package/cjs/di/resolution.js +166 -0
- package/cjs/di/utils.js +44 -0
- package/cjs/index.js +31 -0
- package/cjs/module/factory.js +71 -0
- package/cjs/module/metadata.js +110 -0
- package/cjs/module/module.js +27 -0
- package/cjs/module/resolvers.js +341 -0
- package/cjs/module/tokens.js +21 -0
- package/cjs/module/type-defs.js +24 -0
- package/cjs/module/types.js +0 -0
- package/cjs/package.json +9 -0
- package/cjs/shared/di.js +0 -0
- package/cjs/shared/errors.js +82 -0
- package/cjs/shared/gql.js +12 -0
- package/cjs/shared/middleware.js +109 -0
- package/cjs/shared/types.js +0 -0
- package/cjs/shared/utils.js +115 -0
- package/cjs/testing/di.js +9 -0
- package/cjs/testing/graphql.js +10 -0
- package/cjs/testing/index.js +17 -0
- package/cjs/testing/test-application.js +65 -0
- package/cjs/testing/test-injector.js +22 -0
- package/cjs/testing/test-module.js +270 -0
- package/esm/application/apollo.js +77 -0
- package/esm/application/application.js +146 -0
- package/esm/application/context.js +140 -0
- package/esm/application/di.js +42 -0
- package/esm/application/execution.js +39 -0
- package/esm/application/operation-controller.js +13 -0
- package/esm/application/subscription.js +51 -0
- package/esm/application/tokens.js +17 -0
- package/esm/application/types.js +0 -0
- package/esm/async-context.browser.mjs +7 -0
- package/esm/async-context.node.cjs +14 -0
- package/esm/di/decorators.js +72 -0
- package/esm/di/errors.js +79 -0
- package/esm/di/forward-ref.js +22 -0
- package/esm/di/index.js +4 -0
- package/esm/di/injector.js +168 -0
- package/esm/di/metadata.js +17 -0
- package/esm/di/providers.js +50 -0
- package/esm/di/registry.js +40 -0
- package/esm/di/resolution.js +159 -0
- package/esm/di/utils.js +36 -0
- package/esm/index.js +16 -0
- package/esm/module/factory.js +68 -0
- package/esm/module/metadata.js +107 -0
- package/esm/module/module.js +24 -0
- package/esm/module/resolvers.js +337 -0
- package/esm/module/tokens.js +18 -0
- package/esm/module/type-defs.js +21 -0
- package/esm/module/types.js +0 -0
- package/esm/shared/di.js +0 -0
- package/esm/shared/errors.js +69 -0
- package/esm/shared/gql.js +9 -0
- package/esm/shared/middleware.js +103 -0
- package/esm/shared/types.js +0 -0
- package/esm/shared/utils.js +101 -0
- package/esm/testing/di.js +6 -0
- package/esm/testing/graphql.js +7 -0
- package/esm/testing/index.js +14 -0
- package/esm/testing/test-application.js +62 -0
- package/esm/testing/test-injector.js +18 -0
- package/esm/testing/test-module.js +266 -0
- package/package.json +29 -9
- package/typings/application/apollo.d.ts +22 -0
- package/typings/application/application.d.ts +32 -0
- package/typings/application/context.d.ts +24 -0
- package/typings/application/di.d.ts +22 -0
- package/typings/application/execution.d.ts +8 -0
- package/typings/application/operation-controller.d.ts +5 -0
- package/typings/application/subscription.d.ts +8 -0
- package/typings/application/tokens.d.ts +17 -0
- package/typings/application/types.d.ts +130 -0
- package/typings/di/decorators.d.ts +11 -0
- package/typings/di/errors.d.ts +16 -0
- package/typings/di/forward-ref.d.ts +7 -0
- package/typings/di/index.d.ts +5 -0
- package/typings/di/injector.d.ts +50 -0
- package/typings/di/metadata.d.ts +12 -0
- package/typings/di/providers.d.ts +44 -0
- package/typings/di/registry.d.ts +11 -0
- package/typings/di/resolution.d.ts +63 -0
- package/typings/di/utils.d.ts +8 -0
- package/typings/index.d.ts +13 -0
- package/typings/module/factory.d.ts +16 -0
- package/typings/module/metadata.d.ts +12 -0
- package/typings/module/module.d.ts +22 -0
- package/typings/module/resolvers.d.ts +13 -0
- package/typings/module/tokens.d.ts +18 -0
- package/typings/module/type-defs.d.ts +7 -0
- package/typings/module/types.d.ts +51 -0
- package/typings/shared/di.d.ts +3 -0
- package/typings/shared/errors.d.ts +36 -0
- package/typings/shared/gql.d.ts +2 -0
- package/typings/shared/middleware.d.ts +21 -0
- package/typings/shared/types.d.ts +22 -0
- package/typings/shared/utils.d.ts +12 -0
- package/typings/testing/di.d.ts +2 -0
- package/typings/testing/graphql.d.ts +14 -0
- package/typings/testing/index.d.ts +14 -0
- package/typings/testing/test-application.d.ts +2 -0
- package/typings/testing/test-injector.d.ts +4 -0
- package/typings/testing/test-module.d.ts +10 -0
- package/LICENSE.md +0 -21
- package/index.js +0 -2359
- package/index.mjs +0 -2344
- /package/{application/apollo.d.ts → typings/application/apollo.d.cts} +0 -0
- /package/{application/application.d.ts → typings/application/application.d.cts} +0 -0
- /package/{application/context.d.ts → typings/application/context.d.cts} +0 -0
- /package/{application/di.d.ts → typings/application/di.d.cts} +0 -0
- /package/{application/execution.d.ts → typings/application/execution.d.cts} +0 -0
- /package/{application/operation-controller.d.ts → typings/application/operation-controller.d.cts} +0 -0
- /package/{application/subscription.d.ts → typings/application/subscription.d.cts} +0 -0
- /package/{application/tokens.d.ts → typings/application/tokens.d.cts} +0 -0
- /package/{application/types.d.ts → typings/application/types.d.cts} +0 -0
- /package/{di/decorators.d.ts → typings/di/decorators.d.cts} +0 -0
- /package/{di/errors.d.ts → typings/di/errors.d.cts} +0 -0
- /package/{di/forward-ref.d.ts → typings/di/forward-ref.d.cts} +0 -0
- /package/{di/index.d.ts → typings/di/index.d.cts} +0 -0
- /package/{di/injector.d.ts → typings/di/injector.d.cts} +0 -0
- /package/{di/metadata.d.ts → typings/di/metadata.d.cts} +0 -0
- /package/{di/providers.d.ts → typings/di/providers.d.cts} +0 -0
- /package/{di/registry.d.ts → typings/di/registry.d.cts} +0 -0
- /package/{di/resolution.d.ts → typings/di/resolution.d.cts} +0 -0
- /package/{di/utils.d.ts → typings/di/utils.d.cts} +0 -0
- /package/{index.d.ts → typings/index.d.cts} +0 -0
- /package/{module/factory.d.ts → typings/module/factory.d.cts} +0 -0
- /package/{module/metadata.d.ts → typings/module/metadata.d.cts} +0 -0
- /package/{module/module.d.ts → typings/module/module.d.cts} +0 -0
- /package/{module/resolvers.d.ts → typings/module/resolvers.d.cts} +0 -0
- /package/{module/tokens.d.ts → typings/module/tokens.d.cts} +0 -0
- /package/{module/type-defs.d.ts → typings/module/type-defs.d.cts} +0 -0
- /package/{module/types.d.ts → typings/module/types.d.cts} +0 -0
- /package/{shared/di.d.ts → typings/shared/di.d.cts} +0 -0
- /package/{shared/errors.d.ts → typings/shared/errors.d.cts} +0 -0
- /package/{shared/gql.d.ts → typings/shared/gql.d.cts} +0 -0
- /package/{shared/middleware.d.ts → typings/shared/middleware.d.cts} +0 -0
- /package/{shared/types.d.ts → typings/shared/types.d.cts} +0 -0
- /package/{shared/utils.d.ts → typings/shared/utils.d.cts} +0 -0
- /package/{testing/di.d.ts → typings/testing/di.d.cts} +0 -0
- /package/{testing/graphql.d.ts → typings/testing/graphql.d.cts} +0 -0
- /package/{testing/index.d.ts → typings/testing/index.d.cts} +0 -0
- /package/{testing/test-application.d.ts → typings/testing/test-application.d.cts} +0 -0
- /package/{testing/test-injector.d.ts → typings/testing/test-injector.d.cts} +0 -0
- /package/{testing/test-module.d.ts → typings/testing/test-module.d.cts} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NonDocumentNodeError = exports.ResolverInvalidError = exports.ResolverDuplicatedError = exports.ExtraMiddlewareError = exports.ExtraResolverError = exports.ModuleDuplicatedError = exports.ModuleNonUniqueIdError = void 0;
|
|
4
|
+
exports.useLocation = useLocation;
|
|
5
|
+
exports.ExtendableBuiltin = ExtendableBuiltin;
|
|
6
|
+
exports.composeMessage = composeMessage;
|
|
7
|
+
class ModuleNonUniqueIdError extends ExtendableBuiltin(Error) {
|
|
8
|
+
constructor(message, ...rest) {
|
|
9
|
+
super(composeMessage(message, ...rest));
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
this.message = composeMessage(message, ...rest);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ModuleNonUniqueIdError = ModuleNonUniqueIdError;
|
|
15
|
+
class ModuleDuplicatedError extends ExtendableBuiltin(Error) {
|
|
16
|
+
constructor(message, ...rest) {
|
|
17
|
+
super(composeMessage(message, ...rest));
|
|
18
|
+
this.name = this.constructor.name;
|
|
19
|
+
this.message = composeMessage(message, ...rest);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ModuleDuplicatedError = ModuleDuplicatedError;
|
|
23
|
+
class ExtraResolverError extends ExtendableBuiltin(Error) {
|
|
24
|
+
constructor(message, ...rest) {
|
|
25
|
+
super(composeMessage(message, ...rest));
|
|
26
|
+
this.name = this.constructor.name;
|
|
27
|
+
this.message = composeMessage(message, ...rest);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ExtraResolverError = ExtraResolverError;
|
|
31
|
+
class ExtraMiddlewareError extends ExtendableBuiltin(Error) {
|
|
32
|
+
constructor(message, ...rest) {
|
|
33
|
+
super(composeMessage(message, ...rest));
|
|
34
|
+
this.name = this.constructor.name;
|
|
35
|
+
this.message = composeMessage(message, ...rest);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ExtraMiddlewareError = ExtraMiddlewareError;
|
|
39
|
+
class ResolverDuplicatedError extends ExtendableBuiltin(Error) {
|
|
40
|
+
constructor(message, ...rest) {
|
|
41
|
+
super(composeMessage(message, ...rest));
|
|
42
|
+
this.name = this.constructor.name;
|
|
43
|
+
this.message = composeMessage(message, ...rest);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ResolverDuplicatedError = ResolverDuplicatedError;
|
|
47
|
+
class ResolverInvalidError extends ExtendableBuiltin(Error) {
|
|
48
|
+
constructor(message, ...rest) {
|
|
49
|
+
super(composeMessage(message, ...rest));
|
|
50
|
+
this.name = this.constructor.name;
|
|
51
|
+
this.message = composeMessage(message, ...rest);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ResolverInvalidError = ResolverInvalidError;
|
|
55
|
+
class NonDocumentNodeError extends ExtendableBuiltin(Error) {
|
|
56
|
+
constructor(message, ...rest) {
|
|
57
|
+
super(composeMessage(message, ...rest));
|
|
58
|
+
this.name = this.constructor.name;
|
|
59
|
+
this.message = composeMessage(message, ...rest);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.NonDocumentNodeError = NonDocumentNodeError;
|
|
63
|
+
// helpers
|
|
64
|
+
function useLocation({ dirname, id }) {
|
|
65
|
+
return dirname
|
|
66
|
+
? `Module "${id}" located at ${dirname}`
|
|
67
|
+
: [
|
|
68
|
+
`Module "${id}"`,
|
|
69
|
+
`Hint: pass __dirname to "dirname" option of your modules to get more insightful errors`,
|
|
70
|
+
].join('\n');
|
|
71
|
+
}
|
|
72
|
+
function ExtendableBuiltin(cls) {
|
|
73
|
+
function ExtendableBuiltin() {
|
|
74
|
+
cls.apply(this, arguments);
|
|
75
|
+
}
|
|
76
|
+
ExtendableBuiltin.prototype = Object.create(cls.prototype);
|
|
77
|
+
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
78
|
+
return ExtendableBuiltin;
|
|
79
|
+
}
|
|
80
|
+
function composeMessage(...lines) {
|
|
81
|
+
return lines.join('\n');
|
|
82
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gql = gql;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function gql(literals) {
|
|
6
|
+
const result = typeof literals === 'string' ? literals : literals[0];
|
|
7
|
+
const parsed = (0, graphql_1.parse)(result);
|
|
8
|
+
if (!parsed || parsed.kind !== graphql_1.Kind.DOCUMENT) {
|
|
9
|
+
throw new Error('Not a valid GraphQL document.');
|
|
10
|
+
}
|
|
11
|
+
return parsed;
|
|
12
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compose = compose;
|
|
4
|
+
exports.createMiddleware = createMiddleware;
|
|
5
|
+
exports.mergeMiddlewareMaps = mergeMiddlewareMaps;
|
|
6
|
+
exports.validateMiddlewareMap = validateMiddlewareMap;
|
|
7
|
+
const ramda_1 = require("ramda");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
function compose(middleware) {
|
|
11
|
+
if (!Array.isArray(middleware)) {
|
|
12
|
+
throw new TypeError('Middleware stack must be an array!');
|
|
13
|
+
}
|
|
14
|
+
for (const fn of middleware) {
|
|
15
|
+
if (typeof fn !== 'function') {
|
|
16
|
+
throw new TypeError('Middleware must be composed of functions!');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return function composed(context, next) {
|
|
20
|
+
// last called middleware
|
|
21
|
+
let index = -1;
|
|
22
|
+
function dispatch(i) {
|
|
23
|
+
if (i <= index) {
|
|
24
|
+
return Promise.reject(new Error('next() called multiple times'));
|
|
25
|
+
}
|
|
26
|
+
index = i;
|
|
27
|
+
const fn = i === middleware.length ? next : middleware[i];
|
|
28
|
+
if (!fn) {
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return Promise.reject(err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return dispatch(0);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createMiddleware(path, middlewareMap) {
|
|
42
|
+
const middlewares = middlewareMap ? pickMiddlewares(path, middlewareMap) : [];
|
|
43
|
+
return compose(middlewares);
|
|
44
|
+
}
|
|
45
|
+
function mergeMiddlewareMaps(app, mod) {
|
|
46
|
+
const merge = (left, right) => {
|
|
47
|
+
return (0, ramda_1.mergeDeepWith)((l, r) => {
|
|
48
|
+
if (Array.isArray(l)) {
|
|
49
|
+
return l.concat(r || []);
|
|
50
|
+
}
|
|
51
|
+
return merge(l, r);
|
|
52
|
+
}, left, right);
|
|
53
|
+
};
|
|
54
|
+
return merge(app, mod);
|
|
55
|
+
}
|
|
56
|
+
function pickMiddlewares(path, middlewareMap) {
|
|
57
|
+
var _a;
|
|
58
|
+
const middlewares = [];
|
|
59
|
+
const [type, field] = path;
|
|
60
|
+
if ((_a = middlewareMap['*']) === null || _a === void 0 ? void 0 : _a['*']) {
|
|
61
|
+
middlewares.push(...middlewareMap['*']['*']);
|
|
62
|
+
}
|
|
63
|
+
const typeMap = middlewareMap[type];
|
|
64
|
+
if (typeMap) {
|
|
65
|
+
if (typeMap['*']) {
|
|
66
|
+
middlewares.push(...typeMap['*']);
|
|
67
|
+
}
|
|
68
|
+
if (field && typeMap[field]) {
|
|
69
|
+
middlewares.push(...typeMap[field]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return middlewares.filter(utils_1.isDefined);
|
|
73
|
+
}
|
|
74
|
+
function validateMiddlewareMap(middlewareMap, metadata) {
|
|
75
|
+
const exists = checkExistence(metadata);
|
|
76
|
+
for (const typeName in middlewareMap.types) {
|
|
77
|
+
if (middlewareMap.types.hasOwnProperty(typeName)) {
|
|
78
|
+
const typeMiddlewareMap = middlewareMap[typeName];
|
|
79
|
+
if (!exists.type(typeName)) {
|
|
80
|
+
throw new errors_1.ExtraMiddlewareError(`Cannot apply a middleware to non existing "${typeName}" type`, (0, errors_1.useLocation)({ dirname: metadata.dirname, id: metadata.id }));
|
|
81
|
+
}
|
|
82
|
+
for (const fieldName in typeMiddlewareMap[typeName]) {
|
|
83
|
+
if (typeMiddlewareMap[typeName].hasOwnProperty(fieldName)) {
|
|
84
|
+
if (!exists.field(typeName, fieldName)) {
|
|
85
|
+
throw new errors_1.ExtraMiddlewareError(`Cannot apply a middleware to non existing "${typeName}.${fieldName}" type.field`, (0, errors_1.useLocation)({ dirname: metadata.dirname, id: metadata.id }));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Helps to make sure a middleware has a corresponding type/field definition.
|
|
94
|
+
* We don't want to pass a module-level middlewares that are not related to the module.
|
|
95
|
+
* Not because it's dangerous but to prevent unused middlewares.
|
|
96
|
+
*/
|
|
97
|
+
function checkExistence(metadata) {
|
|
98
|
+
return {
|
|
99
|
+
type(name) {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
return (0, utils_1.isDefined)(((_a = metadata.implements) === null || _a === void 0 ? void 0 : _a[name]) || ((_b = metadata.extends) === null || _b === void 0 ? void 0 : _b[name]));
|
|
102
|
+
},
|
|
103
|
+
field(type, name) {
|
|
104
|
+
var _a, _b, _c, _d;
|
|
105
|
+
return (0, utils_1.isDefined)(((_b = (_a = metadata.implements) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.includes(name)) ||
|
|
106
|
+
((_d = (_c = metadata.extends) === null || _c === void 0 ? void 0 : _c[type]) === null || _d === void 0 ? void 0 : _d.includes(name)));
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flatten = flatten;
|
|
4
|
+
exports.isDefined = isDefined;
|
|
5
|
+
exports.isNil = isNil;
|
|
6
|
+
exports.isObject = isObject;
|
|
7
|
+
exports.isPrimitive = isPrimitive;
|
|
8
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
9
|
+
exports.tapAsyncIterator = tapAsyncIterator;
|
|
10
|
+
exports.once = once;
|
|
11
|
+
exports.share = share;
|
|
12
|
+
exports.uniqueId = uniqueId;
|
|
13
|
+
exports.isNotSchema = isNotSchema;
|
|
14
|
+
exports.merge = merge;
|
|
15
|
+
const graphql_1 = require("graphql");
|
|
16
|
+
function flatten(arr) {
|
|
17
|
+
return Array.prototype.concat(...arr);
|
|
18
|
+
}
|
|
19
|
+
function isDefined(val) {
|
|
20
|
+
return !isNil(val);
|
|
21
|
+
}
|
|
22
|
+
function isNil(val) {
|
|
23
|
+
return val === null || typeof val === 'undefined';
|
|
24
|
+
}
|
|
25
|
+
function isObject(val) {
|
|
26
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
27
|
+
}
|
|
28
|
+
function isPrimitive(val) {
|
|
29
|
+
return ['number', 'string', 'boolean', 'symbol', 'bigint'].includes(typeof val);
|
|
30
|
+
}
|
|
31
|
+
function isAsyncIterable(obj) {
|
|
32
|
+
return obj && typeof obj[Symbol.asyncIterator] === 'function';
|
|
33
|
+
}
|
|
34
|
+
function tapAsyncIterator(iterable, doneCallback) {
|
|
35
|
+
const iteratorMethod = iterable[Symbol.asyncIterator];
|
|
36
|
+
const iterator = iteratorMethod.call(iterable);
|
|
37
|
+
function mapResult(result) {
|
|
38
|
+
if (result.done) {
|
|
39
|
+
doneCallback();
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
async next() {
|
|
45
|
+
try {
|
|
46
|
+
let result = await iterator.next();
|
|
47
|
+
return mapResult(result);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
doneCallback();
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async return(value) {
|
|
55
|
+
try {
|
|
56
|
+
const result = await iterator.return(value);
|
|
57
|
+
return mapResult(result);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
doneCallback();
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
throw(error) {
|
|
65
|
+
doneCallback();
|
|
66
|
+
return iterator.throw(error);
|
|
67
|
+
},
|
|
68
|
+
[Symbol.asyncIterator]() {
|
|
69
|
+
return this;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function once(cb) {
|
|
74
|
+
let called = false;
|
|
75
|
+
return () => {
|
|
76
|
+
if (!called) {
|
|
77
|
+
called = true;
|
|
78
|
+
cb();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function share(factory) {
|
|
83
|
+
let cached = null;
|
|
84
|
+
return (arg) => {
|
|
85
|
+
if (!cached) {
|
|
86
|
+
cached = factory(arg);
|
|
87
|
+
}
|
|
88
|
+
return cached;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function uniqueId(isNotUsed) {
|
|
92
|
+
let id;
|
|
93
|
+
while (!isNotUsed((id = Math.random().toString(16).substr(2)))) { }
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
function isNotSchema(obj) {
|
|
97
|
+
return obj instanceof graphql_1.GraphQLSchema === false;
|
|
98
|
+
}
|
|
99
|
+
function merge(source, target) {
|
|
100
|
+
const result = {
|
|
101
|
+
...source,
|
|
102
|
+
...target,
|
|
103
|
+
};
|
|
104
|
+
function attachSymbols(obj) {
|
|
105
|
+
const symbols = Object.getOwnPropertySymbols(obj);
|
|
106
|
+
for (const symbol of symbols) {
|
|
107
|
+
result[symbol] = obj[symbol];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (source) {
|
|
111
|
+
attachSymbols(source);
|
|
112
|
+
}
|
|
113
|
+
attachSymbols(target);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = execute;
|
|
4
|
+
function execute(app, inputs, options) {
|
|
5
|
+
const executor = app.createExecution(options);
|
|
6
|
+
return executor({
|
|
7
|
+
schema: app.schema,
|
|
8
|
+
...inputs,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testkit = void 0;
|
|
4
|
+
const test_application_1 = require("./test-application");
|
|
5
|
+
const test_module_1 = require("./test-module");
|
|
6
|
+
const test_injector_1 = require("./test-injector");
|
|
7
|
+
const graphql_1 = require("./graphql");
|
|
8
|
+
const di_1 = require("./di");
|
|
9
|
+
exports.testkit = {
|
|
10
|
+
mockApplication: test_application_1.mockApplication,
|
|
11
|
+
mockModule: test_module_1.mockModule,
|
|
12
|
+
testModule: test_module_1.testModule,
|
|
13
|
+
testInjector: test_injector_1.testInjector,
|
|
14
|
+
readProviderOptions: test_injector_1.readProviderOptions,
|
|
15
|
+
provideEmpty: di_1.provideEmpty,
|
|
16
|
+
execute: graphql_1.execute,
|
|
17
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockApplication = mockApplication;
|
|
4
|
+
const utils_1 = require("../shared/utils");
|
|
5
|
+
function mockApplication(app) {
|
|
6
|
+
function mockedFactory(newConfig) {
|
|
7
|
+
const sharedFactory = (0, utils_1.share)(() => app.ɵfactory(newConfig));
|
|
8
|
+
return {
|
|
9
|
+
get typeDefs() {
|
|
10
|
+
return sharedFactory().typeDefs;
|
|
11
|
+
},
|
|
12
|
+
get resolvers() {
|
|
13
|
+
return sharedFactory().resolvers;
|
|
14
|
+
},
|
|
15
|
+
get schema() {
|
|
16
|
+
return sharedFactory().schema;
|
|
17
|
+
},
|
|
18
|
+
get injector() {
|
|
19
|
+
return sharedFactory().injector;
|
|
20
|
+
},
|
|
21
|
+
createOperationController(options) {
|
|
22
|
+
return sharedFactory().createOperationController(options);
|
|
23
|
+
},
|
|
24
|
+
createSubscription(options) {
|
|
25
|
+
return sharedFactory().createSubscription(options);
|
|
26
|
+
},
|
|
27
|
+
createExecution(options) {
|
|
28
|
+
return sharedFactory().createExecution(options);
|
|
29
|
+
},
|
|
30
|
+
createSchemaForApollo() {
|
|
31
|
+
return sharedFactory().createSchemaForApollo();
|
|
32
|
+
},
|
|
33
|
+
createApolloExecutor() {
|
|
34
|
+
return sharedFactory().createApolloExecutor();
|
|
35
|
+
},
|
|
36
|
+
get ɵfactory() {
|
|
37
|
+
return sharedFactory().ɵfactory;
|
|
38
|
+
},
|
|
39
|
+
get ɵconfig() {
|
|
40
|
+
return sharedFactory().ɵconfig;
|
|
41
|
+
},
|
|
42
|
+
replaceModule(newModule) {
|
|
43
|
+
const config = sharedFactory().ɵconfig;
|
|
44
|
+
return mockedFactory({
|
|
45
|
+
...config,
|
|
46
|
+
modules: config.modules.map((mod) => mod.id === newModule.ɵoriginalModule.id ? newModule : mod),
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
addProviders(newProviders) {
|
|
50
|
+
const config = sharedFactory().ɵconfig;
|
|
51
|
+
const existingProviders = typeof config.providers === 'function'
|
|
52
|
+
? config.providers()
|
|
53
|
+
: config.providers;
|
|
54
|
+
const providers = Array.isArray(existingProviders)
|
|
55
|
+
? existingProviders.concat(newProviders)
|
|
56
|
+
: newProviders;
|
|
57
|
+
return mockedFactory({
|
|
58
|
+
...config,
|
|
59
|
+
providers,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return mockedFactory();
|
|
65
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testInjector = testInjector;
|
|
4
|
+
exports.readProviderOptions = readProviderOptions;
|
|
5
|
+
const injector_1 = require("../di/injector");
|
|
6
|
+
const tokens_1 = require("../application/tokens");
|
|
7
|
+
const metadata_1 = require("../di/metadata");
|
|
8
|
+
function testInjector(providers) {
|
|
9
|
+
const resolvedProviders = injector_1.ReflectiveInjector.resolve([
|
|
10
|
+
{ provide: tokens_1.CONTEXT, useValue: {} },
|
|
11
|
+
...providers,
|
|
12
|
+
]);
|
|
13
|
+
const injector = injector_1.ReflectiveInjector.createFromResolved({
|
|
14
|
+
name: 'test',
|
|
15
|
+
providers: resolvedProviders,
|
|
16
|
+
});
|
|
17
|
+
injector.instantiateAll();
|
|
18
|
+
return injector;
|
|
19
|
+
}
|
|
20
|
+
function readProviderOptions(provider) {
|
|
21
|
+
return (0, metadata_1.readInjectableMetadata)(provider, true).options;
|
|
22
|
+
}
|