@webiny/handler-graphql 0.0.0-unstable.7f63ea0744 → 0.0.0-unstable.81ae05e56b
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/README.md +9 -5
- package/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +19 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +4 -9
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.d.ts +1 -1
- package/builtInTypes/DateScalar.js +10 -13
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.d.ts +1 -1
- package/builtInTypes/DateTimeScalar.js +10 -13
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.d.ts +1 -1
- package/builtInTypes/DateTimeZScalar.js +10 -16
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +93 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -1
- package/builtInTypes/JsonScalar.js +3 -8
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +48 -8
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +14 -21
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +40 -18
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.d.ts +1 -1
- package/builtInTypes/TimeScalar.js +11 -17
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.d.ts +10 -9
- package/builtInTypes/index.js +11 -103
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +43 -34
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -2
- package/createGraphQLSchema.js +78 -45
- package/createGraphQLSchema.js.map +1 -1
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +26 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +5 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +6 -11
- package/debugPlugins.js.map +1 -1
- package/errors.js +4 -10
- package/errors.js.map +1 -1
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +4 -0
- package/exports/api/graphql.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +64 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +29 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +5 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +1 -0
- package/features/GraphQLSchemaBuilder/feature.js +10 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +11 -0
- package/graphql/abstractions.core.js +10 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +4 -0
- package/graphql/abstractions.js.map +1 -0
- package/graphql/abstractions.public.d.ts +18 -0
- package/graphql/abstractions.public.js +11 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +10 -5
- package/index.js +12 -46
- package/index.js.map +1 -1
- package/interceptConsole.js +8 -13
- package/interceptConsole.js.map +1 -1
- package/package.json +23 -26
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +16 -14
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +2 -15
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +15 -13
- package/processRequestBody.js.map +1 -1
- package/responses.d.ts +11 -1
- package/responses.js +17 -28
- package/responses.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +2 -4
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +19 -0
- package/utils/resolve.js.map +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains abstraction for use by third party developers.
|
|
3
|
+
*/
|
|
4
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
5
|
+
|
|
6
|
+
/** Define custom GraphQL schema extensions. */
|
|
7
|
+
|
|
8
|
+
/** Define custom GraphQL schema extensions. */
|
|
9
|
+
export const GraphQLSchemaFactory = createAbstraction("GraphQLSchemaFactory");
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=abstractions.public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","GraphQLSchemaFactory"],"sources":["abstractions.public.ts"],"sourcesContent":["/**\n * This file contains abstraction for use by third party developers.\n */\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n Resolvers as IResolvers,\n TypeDefs as ITypeDefs,\n ResolverDecorators as IResolverDecorators\n} from \"~/types.js\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\nexport interface IGraphQLSchema {\n typeDefs?: ITypeDefs;\n resolvers?: IResolvers<any>;\n resolverDecorators?: IResolverDecorators;\n}\n\n/** Define custom GraphQL schema extensions. */\nexport interface IGraphQLSchemaFactory {\n execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;\n}\n\n/** Define custom GraphQL schema extensions. */\nexport const GraphQLSchemaFactory =\n createAbstraction<IGraphQLSchemaFactory>(\"GraphQLSchemaFactory\");\n\nexport namespace GraphQLSchemaFactory {\n export type Interface = IGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAcvD;;AAKA;AACA,OAAO,MAAMC,oBAAoB,GAC7BD,iBAAiB,CAAwB,sBAAsB,CAAC","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./responses.js";
|
|
5
|
+
export * from "./utils/index.js";
|
|
6
|
+
export * from "./plugins/index.js";
|
|
7
|
+
export * from "./processRequestBody.js";
|
|
8
|
+
export * from "./createResolverDecorator.js";
|
|
9
|
+
export * from "./ResolverDecoration.js";
|
|
10
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
6
11
|
export default _default;
|
package/index.js
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import createGraphQLHandler from "./createGraphQLHandler.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./responses.js";
|
|
4
|
+
export * from "./utils/index.js";
|
|
5
|
+
export * from "./plugins/index.js";
|
|
6
|
+
export * from "./processRequestBody.js";
|
|
7
|
+
export * from "./createResolverDecorator.js";
|
|
8
|
+
export * from "./ResolverDecoration.js";
|
|
9
|
+
export default (options = {}) => {
|
|
10
|
+
return createGraphQLHandler(options);
|
|
11
|
+
};
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {};
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
|
|
10
|
-
var _errors = require("./errors");
|
|
11
|
-
Object.keys(_errors).forEach(function (key) {
|
|
12
|
-
if (key === "default" || key === "__esModule") return;
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
14
|
-
if (key in exports && exports[key] === _errors[key]) return;
|
|
15
|
-
Object.defineProperty(exports, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () {
|
|
18
|
-
return _errors[key];
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
var _responses = require("./responses");
|
|
23
|
-
Object.keys(_responses).forEach(function (key) {
|
|
24
|
-
if (key === "default" || key === "__esModule") return;
|
|
25
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
26
|
-
if (key in exports && exports[key] === _responses[key]) return;
|
|
27
|
-
Object.defineProperty(exports, key, {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () {
|
|
30
|
-
return _responses[key];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
var _plugins = require("./plugins");
|
|
35
|
-
Object.keys(_plugins).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
38
|
-
if (key in exports && exports[key] === _plugins[key]) return;
|
|
39
|
-
Object.defineProperty(exports, key, {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () {
|
|
42
|
-
return _plugins[key];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
|
|
47
|
-
exports.default = _default;
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createGraphQLHandler","options"],"sources":["index.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { HandlerGraphQLOptions } from \"./types.js\";\nimport createGraphQLHandler from \"./createGraphQLHandler.js\";\n\nexport * from \"./errors.js\";\nexport * from \"./responses.js\";\nexport * from \"./utils/index.js\";\nexport * from \"./plugins/index.js\";\nexport * from \"./processRequestBody.js\";\nexport * from \"./createResolverDecorator.js\";\nexport * from \"./ResolverDecoration.js\";\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n return createGraphQLHandler(options);\n};\n"],"mappings":"AAEA,OAAOA,oBAAoB;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,eAAe,CAACC,OAA8B,GAAG,CAAC,CAAC,KAAe;EAC9D,OAAOD,oBAAoB,CAACC,OAAO,CAAC;AACxC,CAAC","ignoreList":[]}
|
package/interceptConsole.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.interceptConsole = void 0;
|
|
7
1
|
const consoleMethods = ["assert", "debug", "dir", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "table", "warn"];
|
|
8
2
|
const originalMethods = {};
|
|
9
3
|
const skipOriginal = ["table"];
|
|
10
4
|
const restoreOriginalMethods = () => {
|
|
11
5
|
for (const method of consoleMethods) {
|
|
12
|
-
// @ts-
|
|
6
|
+
// @ts-expect-error
|
|
13
7
|
console[method] = originalMethods[method];
|
|
14
8
|
}
|
|
15
9
|
};
|
|
16
|
-
const interceptConsole = callback => {
|
|
17
|
-
// @ts-
|
|
10
|
+
export const interceptConsole = callback => {
|
|
11
|
+
// @ts-expect-error
|
|
18
12
|
if (console["__WEBINY__"] === true) {
|
|
19
13
|
restoreOriginalMethods();
|
|
20
14
|
}
|
|
21
15
|
|
|
22
|
-
// @ts-
|
|
16
|
+
// @ts-expect-error
|
|
23
17
|
console["__WEBINY__"] = true;
|
|
24
18
|
for (const method of consoleMethods) {
|
|
25
|
-
// @ts-
|
|
19
|
+
// @ts-expect-error
|
|
26
20
|
originalMethods[method] = console[method];
|
|
27
|
-
// @ts-
|
|
21
|
+
// @ts-expect-error
|
|
28
22
|
console[method] = (...args) => {
|
|
29
23
|
callback(method, args);
|
|
30
24
|
if (skipOriginal.includes(method)) {
|
|
@@ -34,4 +28,5 @@ const interceptConsole = callback => {
|
|
|
34
28
|
};
|
|
35
29
|
}
|
|
36
30
|
};
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=interceptConsole.js.map
|
package/interceptConsole.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-
|
|
1
|
+
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-expect-error\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-expect-error\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-expect-error\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-expect-error\n originalMethods[method] = console[method];\n // @ts-expect-error\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":"AAAA,MAAMA,cAAc,GAAG,CACnB,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,CACT;AAED,MAAMC,eAAoC,GAAG,CAAC,CAAC;AAC/C,MAAMC,YAAsB,GAAG,CAAC,OAAO,CAAC;AAExC,MAAMC,sBAAsB,GAAGA,CAAA,KAAM;EACjC,KAAK,MAAMC,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAK,OAAO,CAACD,MAAM,CAAC,GAAGH,eAAe,CAACG,MAAM,CAAC;EAC7C;AACJ,CAAC;AAMD,OAAO,MAAME,gBAAgB,GAAIC,QAAkC,IAAK;EACpE;EACA,IAAIF,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;IAChCF,sBAAsB,CAAC,CAAC;EAC5B;;EAEA;EACAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;EAE5B,KAAK,MAAMD,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAC,eAAe,CAACG,MAAM,CAAC,GAAGC,OAAO,CAACD,MAAM,CAAC;IACzC;IACAC,OAAO,CAACD,MAAM,CAAC,GAAG,CAAC,GAAGI,IAAI,KAAK;MAC3BD,QAAQ,CAACH,MAAM,EAAEI,IAAI,CAAC;MACtB,IAAIN,YAAY,CAACO,QAAQ,CAACL,MAAM,CAAC,EAAE;QAC/B;MACJ;MACAH,eAAe,CAACG,MAAM,CAAC,CAAC,GAAGI,IAAI,CAAC;IACpC,CAAC;EACL;AACJ,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.81ae05e56b",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
@@ -14,37 +15,33 @@
|
|
|
14
15
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
16
|
],
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@graphql-tools/
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
18
|
+
"@graphql-tools/merge": "9.1.7",
|
|
19
|
+
"@graphql-tools/resolvers-composition": "7.0.28",
|
|
20
|
+
"@graphql-tools/schema": "10.0.31",
|
|
21
|
+
"@graphql-tools/utils": "11.0.0",
|
|
22
|
+
"@webiny/api": "0.0.0-unstable.81ae05e56b",
|
|
23
|
+
"@webiny/di": "0.2.3",
|
|
24
|
+
"@webiny/error": "0.0.0-unstable.81ae05e56b",
|
|
25
|
+
"@webiny/feature": "0.0.0-unstable.81ae05e56b",
|
|
26
|
+
"@webiny/handler": "0.0.0-unstable.81ae05e56b",
|
|
27
|
+
"@webiny/plugins": "0.0.0-unstable.81ae05e56b",
|
|
28
|
+
"@webiny/utils": "0.0.0-unstable.81ae05e56b",
|
|
23
29
|
"boolean": "3.2.0",
|
|
24
|
-
"graphql": "
|
|
25
|
-
"graphql-scalars": "1.
|
|
26
|
-
"graphql-tag": "2.12.6"
|
|
30
|
+
"graphql": "16.13.1",
|
|
31
|
+
"graphql-scalars": "1.25.0",
|
|
32
|
+
"graphql-tag": "2.12.6",
|
|
33
|
+
"zod": "4.3.6"
|
|
27
34
|
},
|
|
28
35
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"@webiny/project-utils": "^0.0.0-unstable.7f63ea0744",
|
|
35
|
-
"jest": "^28.1.0",
|
|
36
|
-
"jest-mock-console": "^1.0.0",
|
|
37
|
-
"rimraf": "^3.0.2",
|
|
38
|
-
"ttypescript": "^1.5.15",
|
|
39
|
-
"typescript": "4.7.4"
|
|
36
|
+
"@webiny/build-tools": "0.0.0-unstable.81ae05e56b",
|
|
37
|
+
"@webiny/handler-aws": "0.0.0-unstable.81ae05e56b",
|
|
38
|
+
"rimraf": "6.1.3",
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
|
+
"vitest": "4.1.0"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public",
|
|
43
44
|
"directory": "dist"
|
|
44
45
|
},
|
|
45
|
-
"
|
|
46
|
-
"build": "yarn webiny run build",
|
|
47
|
-
"watch": "yarn webiny run watch"
|
|
48
|
-
},
|
|
49
|
-
"gitHead": "7f63ea0744c9e31977e5dabb95538d22b4db585c"
|
|
46
|
+
"gitHead": "81ae05e56bcc774d1e077ca615a0005e736aa5a6"
|
|
50
47
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import type { Context } from "@webiny/api/types.js";
|
|
1
2
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import { GraphQLSchemaDefinition, Resolvers,
|
|
3
|
-
|
|
3
|
+
import type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from "../types.js";
|
|
4
|
+
export interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
5
|
+
schema: GraphQLSchemaDefinition<TContext>;
|
|
6
|
+
isApplicable: (context: TContext) => boolean;
|
|
7
|
+
}
|
|
4
8
|
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
5
|
-
typeDefs?:
|
|
9
|
+
typeDefs?: TypeDefs;
|
|
6
10
|
resolvers?: Resolvers<TContext>;
|
|
11
|
+
resolverDecorators?: ResolverDecorators;
|
|
12
|
+
isApplicable?: (context: TContext) => boolean;
|
|
7
13
|
}
|
|
8
|
-
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
14
|
+
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin implements IGraphQLSchemaPlugin<TContext> {
|
|
9
15
|
static readonly type: string;
|
|
10
|
-
|
|
16
|
+
protected config: GraphQLSchemaPluginConfig<TContext>;
|
|
11
17
|
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
12
18
|
get schema(): GraphQLSchemaDefinition<TContext>;
|
|
19
|
+
isApplicable(context: TContext): boolean;
|
|
13
20
|
}
|
|
21
|
+
export declare const createGraphQLSchemaPlugin: <T = Context>(config: GraphQLSchemaPluginConfig<T>) => GraphQLSchemaPlugin<T>;
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.GraphQLSchemaPlugin = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _plugins = require("@webiny/plugins");
|
|
10
|
-
class GraphQLSchemaPlugin extends _plugins.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export class GraphQLSchemaPlugin extends Plugin {
|
|
3
|
+
static type = "graphql-schema";
|
|
11
4
|
constructor(config) {
|
|
12
5
|
super();
|
|
13
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
14
6
|
this.config = config;
|
|
15
7
|
}
|
|
16
8
|
get schema() {
|
|
17
9
|
return {
|
|
18
10
|
typeDefs: this.config.typeDefs || "",
|
|
19
|
-
resolvers: this.config.resolvers
|
|
11
|
+
resolvers: this.config.resolvers,
|
|
12
|
+
resolverDecorators: this.config.resolverDecorators
|
|
20
13
|
};
|
|
21
14
|
}
|
|
15
|
+
isApplicable(context) {
|
|
16
|
+
if (this.config.isApplicable) {
|
|
17
|
+
return this.config.isApplicable(context);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
export const createGraphQLSchemaPlugin = config => {
|
|
23
|
+
return new GraphQLSchemaPlugin(config);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=GraphQLSchemaPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GraphQLSchemaPlugin","
|
|
1
|
+
{"version":3,"names":["Plugin","GraphQLSchemaPlugin","type","constructor","config","schema","typeDefs","resolvers","resolverDecorators","isApplicable","context","createGraphQLSchemaPlugin"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from \"~/types.js\";\n\nexport interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {\n schema: GraphQLSchemaDefinition<TContext>;\n isApplicable: (context: TContext) => boolean;\n}\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\n isApplicable?: (context: TContext) => boolean;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context>\n extends Plugin\n implements IGraphQLSchemaPlugin<TContext>\n{\n public static override readonly type: string = \"graphql-schema\";\n protected config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers,\n resolverDecorators: this.config.resolverDecorators\n };\n }\n\n isApplicable(context: TContext): boolean {\n if (this.config.isApplicable) {\n return this.config.isApplicable(context);\n }\n return true;\n }\n}\n\nexport const createGraphQLSchemaPlugin = <T = Context>(config: GraphQLSchemaPluginConfig<T>) => {\n return new GraphQLSchemaPlugin<T>(config);\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,iBAAiB;AAexC,OAAO,MAAMC,mBAAmB,SACpBD,MAAM,CAElB;EACI,OAAgCE,IAAI,GAAW,gBAAgB;EAG/DC,WAAWA,CAACC,MAA2C,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,IAAIC,MAAMA,CAAA,EAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,IAAI,CAACF,MAAM,CAACE,QAAQ,IAAI,EAAE;MACpCC,SAAS,EAAE,IAAI,CAACH,MAAM,CAACG,SAAS;MAChCC,kBAAkB,EAAE,IAAI,CAACJ,MAAM,CAACI;IACpC,CAAC;EACL;EAEAC,YAAYA,CAACC,OAAiB,EAAW;IACrC,IAAI,IAAI,CAACN,MAAM,CAACK,YAAY,EAAE;MAC1B,OAAO,IAAI,CAACL,MAAM,CAACK,YAAY,CAACC,OAAO,CAAC;IAC5C;IACA,OAAO,IAAI;EACf;AACJ;AAEA,OAAO,MAAMC,yBAAyB,GAAiBP,MAAoC,IAAK;EAC5F,OAAO,IAAIH,mBAAmB,CAAIG,MAAM,CAAC;AAC7C,CAAC","ignoreList":[]}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./GraphQLSchemaPlugin";
|
|
1
|
+
export * from "./GraphQLSchemaPlugin.js";
|
package/plugins/index.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./GraphQLSchemaPlugin.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _GraphQLSchemaPlugin = require("./GraphQLSchemaPlugin");
|
|
7
|
-
Object.keys(_GraphQLSchemaPlugin).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _GraphQLSchemaPlugin[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _GraphQLSchemaPlugin[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
package/processRequestBody.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
-
import { GraphQLRequestBody } from "./types";
|
|
3
|
-
import { Context } from "@webiny/api/types";
|
|
4
|
-
declare const
|
|
5
|
-
export default _default;
|
|
1
|
+
import type { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
+
import type { GraphQLRequestBody } from "./types.js";
|
|
3
|
+
import type { Context } from "@webiny/api/types.js";
|
|
4
|
+
export declare const processRequestBody: <TData = Record<string, any>, TExtensions = Record<string, any>>(requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult<TData, TExtensions>[] | ExecutionResult<TData, TExtensions>>;
|
package/processRequestBody.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _graphql = require("graphql");
|
|
8
|
-
const processRequestBody = async (body, schema, context) => {
|
|
1
|
+
import { graphql } from "graphql";
|
|
2
|
+
const executeGraphQl = async (body, schema, context) => {
|
|
9
3
|
const {
|
|
10
4
|
query,
|
|
11
5
|
variables,
|
|
@@ -16,7 +10,14 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
16
10
|
schema,
|
|
17
11
|
context
|
|
18
12
|
}));
|
|
19
|
-
const result = await
|
|
13
|
+
const result = await graphql({
|
|
14
|
+
schema,
|
|
15
|
+
source: query,
|
|
16
|
+
rootValue: {},
|
|
17
|
+
contextValue: context,
|
|
18
|
+
variableValues: variables,
|
|
19
|
+
operationName
|
|
20
|
+
});
|
|
20
21
|
context.plugins.byType("graphql-after-query").forEach(pl => {
|
|
21
22
|
pl.apply({
|
|
22
23
|
result,
|
|
@@ -27,15 +28,16 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
27
28
|
});
|
|
28
29
|
return result;
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
export const processRequestBody = async (requestBody, schema, context) => {
|
|
31
32
|
if (Array.isArray(requestBody)) {
|
|
32
33
|
const results = [];
|
|
33
34
|
for (const body of requestBody) {
|
|
34
|
-
const result = await
|
|
35
|
+
const result = await executeGraphQl(body, schema, context);
|
|
35
36
|
results.push(result);
|
|
36
37
|
}
|
|
37
38
|
return results;
|
|
38
39
|
}
|
|
39
|
-
return await
|
|
40
|
+
return await executeGraphQl(requestBody, schema, context);
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=processRequestBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["graphql","executeGraphQl","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","source","rootValue","contextValue","variableValues","processRequestBody","requestBody","Array","isArray","results","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema } from \"graphql\";\nimport { graphql } from \"graphql\";\nimport type {\n GraphQLAfterQueryPlugin,\n GraphQLBeforeQueryPlugin,\n GraphQLRequestBody\n} from \"~/types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\n\nconst executeGraphQl = async <TData = Record<string, any>, TExtensions = Record<string, any>>(\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>> => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql({\n schema,\n source: query,\n rootValue: {},\n contextValue: context,\n variableValues: variables,\n operationName\n });\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result as ExecutionResult<TData, TExtensions>;\n};\n\nexport const processRequestBody = async <\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n>(\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>[] | ExecutionResult<TData, TExtensions>> => {\n if (Array.isArray(requestBody)) {\n const results: ExecutionResult<TData, TExtensions>[] = [];\n for (const body of requestBody) {\n const result = await executeGraphQl<TData, TExtensions>(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await executeGraphQl<TData, TExtensions>(requestBody, schema, context);\n};\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,SAAS;A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CAAC","ignoreList":[]}
|
package/responses.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export interface IMeta {
|
|
2
|
+
hasMoreItems: boolean;
|
|
3
|
+
totalCount: number;
|
|
4
|
+
cursor?: string | null;
|
|
5
|
+
}
|
|
1
6
|
export interface ErrorResponseParams {
|
|
2
7
|
message: string;
|
|
3
8
|
code?: string;
|
|
4
9
|
data?: any;
|
|
5
10
|
stack?: string | null;
|
|
6
11
|
}
|
|
12
|
+
/** GraphQL error response helper. */
|
|
7
13
|
export declare class ErrorResponse {
|
|
8
14
|
readonly data: null;
|
|
9
15
|
readonly error: {
|
|
@@ -14,9 +20,11 @@ export declare class ErrorResponse {
|
|
|
14
20
|
};
|
|
15
21
|
constructor(params: ErrorResponseParams);
|
|
16
22
|
}
|
|
23
|
+
/** GraphQL not-found response helper. */
|
|
17
24
|
export declare class NotFoundResponse extends ErrorResponse {
|
|
18
25
|
constructor(message: string);
|
|
19
26
|
}
|
|
27
|
+
/** GraphQL list error response helper. */
|
|
20
28
|
export declare class ListErrorResponse {
|
|
21
29
|
readonly data: null;
|
|
22
30
|
readonly meta: null;
|
|
@@ -28,12 +36,14 @@ export declare class ListErrorResponse {
|
|
|
28
36
|
};
|
|
29
37
|
constructor(params: ErrorResponseParams);
|
|
30
38
|
}
|
|
39
|
+
/** GraphQL response helper. */
|
|
31
40
|
export declare class Response<T = any> {
|
|
32
41
|
readonly data: T;
|
|
33
42
|
readonly error: null;
|
|
34
43
|
constructor(data: T);
|
|
35
44
|
}
|
|
36
|
-
|
|
45
|
+
/** GraphQL list response helper. */
|
|
46
|
+
export declare class ListResponse<T, M = IMeta> {
|
|
37
47
|
readonly data: Array<T>;
|
|
38
48
|
readonly meta: M;
|
|
39
49
|
readonly error: null;
|
package/responses.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.Response = exports.NotFoundResponse = exports.ListResponse = exports.ListErrorResponse = exports.ErrorResponse = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
1
|
const defaultParams = {
|
|
10
2
|
code: "",
|
|
11
3
|
message: "",
|
|
12
4
|
data: null,
|
|
13
5
|
stack: null
|
|
14
6
|
};
|
|
15
|
-
|
|
7
|
+
|
|
8
|
+
/** GraphQL error response helper. */
|
|
9
|
+
export class ErrorResponse {
|
|
16
10
|
constructor(params) {
|
|
17
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
18
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
19
11
|
this.data = null;
|
|
20
12
|
const debug = process.env.DEBUG === "true";
|
|
21
13
|
|
|
@@ -32,8 +24,9 @@ class ErrorResponse {
|
|
|
32
24
|
};
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
|
|
28
|
+
/** GraphQL not-found response helper. */
|
|
29
|
+
export class NotFoundResponse extends ErrorResponse {
|
|
37
30
|
constructor(message) {
|
|
38
31
|
super({
|
|
39
32
|
code: "NOT_FOUND",
|
|
@@ -41,12 +34,10 @@ class NotFoundResponse extends ErrorResponse {
|
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
|
|
38
|
+
/** GraphQL list error response helper. */
|
|
39
|
+
export class ListErrorResponse {
|
|
46
40
|
constructor(params) {
|
|
47
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
48
|
-
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
49
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
50
41
|
this.meta = null;
|
|
51
42
|
this.data = null;
|
|
52
43
|
const debug = process.env.DEBUG === "true";
|
|
@@ -64,24 +55,22 @@ class ListErrorResponse {
|
|
|
64
55
|
};
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
|
|
59
|
+
/** GraphQL response helper. */
|
|
60
|
+
export class Response {
|
|
69
61
|
constructor(data) {
|
|
70
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
71
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
72
62
|
this.data = data;
|
|
73
63
|
this.error = null;
|
|
74
64
|
}
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
|
|
67
|
+
/** GraphQL list response helper. */
|
|
68
|
+
export class ListResponse {
|
|
78
69
|
constructor(data, meta) {
|
|
79
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
80
|
-
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
81
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
82
70
|
this.data = Array.isArray(data) ? data : [];
|
|
83
71
|
this.meta = meta || {};
|
|
84
72
|
this.error = null;
|
|
85
73
|
}
|
|
86
74
|
}
|
|
87
|
-
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=responses.js.map
|
package/responses.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface IMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor?: string | null;\n}\n\nexport interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\n/** GraphQL error response helper. */\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL not-found response helper. */\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\n/** GraphQL list error response helper. */\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL response helper. */\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\n/** GraphQL list response helper. */\nexport class ListResponse<T, M = IMeta> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":"AAaA,MAAMA,aAA4C,GAAG;EACjDC,IAAI,EAAE,EAAE;EACRC,OAAO,EAAE,EAAE;EACXC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE;AACX,CAAC;;AAED;AACA,OAAO,MAAMC,aAAa,CAAC;EASvBC,WAAWA,CAACC,MAA2B,EAAE;IACrC,IAAI,CAACJ,IAAI,GAAG,IAAI;IAEhB,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAG,CA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