@webiny/handler-graphql 6.0.0-beta.0 → 6.0.0-rc.1
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 +2 -8
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.d.ts +1 -1
- package/builtInTypes/DateScalar.js +7 -10
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.d.ts +1 -1
- package/builtInTypes/DateTimeScalar.js +7 -10
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.d.ts +1 -1
- package/builtInTypes/DateTimeZScalar.js +8 -15
- 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 +2 -8
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +1 -1
- package/builtInTypes/LongScalar.js +8 -15
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +9 -16
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +8 -8
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.d.ts +1 -1
- package/builtInTypes/TimeScalar.js +9 -16
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.d.ts +10 -9
- package/builtInTypes/index.js +10 -104
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +25 -35
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -4
- package/createGraphQLSchema.js +68 -41
- 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 +4 -11
- package/debugPlugins.js.map +1 -1
- package/errors.js +2 -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 +19 -0
- package/graphql/abstractions.public.js +12 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +10 -6
- package/index.js +11 -59
- package/index.js.map +1 -1
- package/interceptConsole.js +1 -8
- package/interceptConsole.js.map +1 -1
- package/package.json +23 -26
- package/plugins/GraphQLSchemaPlugin.d.ts +7 -3
- package/plugins/GraphQLSchemaPlugin.js +11 -12
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +1 -16
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -4
- package/processRequestBody.js +10 -10
- package/processRequestBody.js.map +1 -1
- package/responses.js +5 -16
- package/responses.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +1 -5
- 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
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TimeScalar = void 0;
|
|
8
|
-
var _graphql = require("graphql");
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
10
3
|
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
11
4
|
const parseTime = value => {
|
|
12
|
-
if (!value || value.match(re) === null) {
|
|
13
|
-
throw new
|
|
5
|
+
if (typeof value !== "string" || !value || value.match(re) === null) {
|
|
6
|
+
throw new WebinyError("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
14
7
|
value
|
|
15
8
|
});
|
|
16
9
|
}
|
|
17
10
|
const parsed = value.split(":").map(Number);
|
|
18
11
|
if (parsed.length < 2) {
|
|
19
|
-
throw new
|
|
12
|
+
throw new WebinyError(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
|
|
20
13
|
value
|
|
21
14
|
});
|
|
22
15
|
}
|
|
23
16
|
const [hours, minutes, seconds = 0] = parsed;
|
|
24
17
|
if (hours >= 24) {
|
|
25
|
-
throw new
|
|
18
|
+
throw new WebinyError(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
|
|
26
19
|
value
|
|
27
20
|
});
|
|
28
21
|
} else if (minutes >= 60) {
|
|
29
|
-
throw new
|
|
22
|
+
throw new WebinyError(`There cannot be more than 59 minutes.`, "TIME_VALIDATION_ERROR", {
|
|
30
23
|
value
|
|
31
24
|
});
|
|
32
25
|
} else if (seconds >= 60) {
|
|
33
|
-
throw new
|
|
26
|
+
throw new WebinyError(`There cannot be more than 59 seconds.`, "TIME_VALIDATION_ERROR", {
|
|
34
27
|
value
|
|
35
28
|
});
|
|
36
29
|
}
|
|
@@ -48,7 +41,7 @@ const convertToTime = value => {
|
|
|
48
41
|
} = parseTime(value);
|
|
49
42
|
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
50
43
|
};
|
|
51
|
-
const TimeScalar =
|
|
44
|
+
export const TimeScalar = new GraphQLScalarType({
|
|
52
45
|
name: "Time",
|
|
53
46
|
description: "A custom type to support time-only input.",
|
|
54
47
|
// sending to client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","WebinyError","re","parseTime","value","match","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: unknown) => {\n if (typeof value !== \"string\" || !value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: unknown): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAe,IAAK;EACnC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACjE,MAAM,IAAID,WAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEG;IAAM,CAAC,CAAC;EAC/F;EACA,MAAME,MAAM,GAAGF,KAAK,CAACG,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAC3C,IAAIH,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;IACnB,MAA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@@ -1,9 +1,10 @@
|
|
|
1
|
-
export * from "./AnyScalar";
|
|
2
|
-
export * from "./DateScalar";
|
|
3
|
-
export * from "./DateTimeScalar";
|
|
4
|
-
export * from "./DateTimeZScalar";
|
|
5
|
-
export * from "./JsonScalar";
|
|
6
|
-
export * from "./LongScalar";
|
|
7
|
-
export * from "./NumberScalar";
|
|
8
|
-
export * from "./RefInputScalar";
|
|
9
|
-
export * from "./TimeScalar";
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
package/builtInTypes/index.js
CHANGED
|
@@ -1,106 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _AnyScalar[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _DateScalar = require("./DateScalar");
|
|
18
|
-
Object.keys(_DateScalar).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _DateScalar[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _DateScalar[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _DateTimeScalar = require("./DateTimeScalar");
|
|
29
|
-
Object.keys(_DateTimeScalar).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _DateTimeScalar[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _DateTimeScalar[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _DateTimeZScalar = require("./DateTimeZScalar");
|
|
40
|
-
Object.keys(_DateTimeZScalar).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _DateTimeZScalar[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _JsonScalar = require("./JsonScalar");
|
|
51
|
-
Object.keys(_JsonScalar).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _JsonScalar[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _JsonScalar[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _LongScalar = require("./LongScalar");
|
|
62
|
-
Object.keys(_LongScalar).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _LongScalar[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _LongScalar[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
var _NumberScalar = require("./NumberScalar");
|
|
73
|
-
Object.keys(_NumberScalar).forEach(function (key) {
|
|
74
|
-
if (key === "default" || key === "__esModule") return;
|
|
75
|
-
if (key in exports && exports[key] === _NumberScalar[key]) return;
|
|
76
|
-
Object.defineProperty(exports, key, {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _NumberScalar[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
var _RefInputScalar = require("./RefInputScalar");
|
|
84
|
-
Object.keys(_RefInputScalar).forEach(function (key) {
|
|
85
|
-
if (key === "default" || key === "__esModule") return;
|
|
86
|
-
if (key in exports && exports[key] === _RefInputScalar[key]) return;
|
|
87
|
-
Object.defineProperty(exports, key, {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return _RefInputScalar[key];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
var _TimeScalar = require("./TimeScalar");
|
|
95
|
-
Object.keys(_TimeScalar).forEach(function (key) {
|
|
96
|
-
if (key === "default" || key === "__esModule") return;
|
|
97
|
-
if (key in exports && exports[key] === _TimeScalar[key]) return;
|
|
98
|
-
Object.defineProperty(exports, key, {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: function () {
|
|
101
|
-
return _TimeScalar[key];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
|
105
11
|
|
|
106
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar.js\";\nexport * from \"./DateScalar.js\";\nexport * from \"./DateTimeScalar.js\";\nexport * from \"./DateTimeZScalar.js\";\nexport * from \"./JsonScalar.js\";\nexport * from \"./LongScalar.js\";\nexport * from \"./NumberScalar.js\";\nexport * from \"./RefInputScalar.js\";\nexport * from \"./TimeScalar.js\";\nexport * from \"./IconScalar.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HandlerGraphQLOptions } from "./types";
|
|
3
|
-
declare const _default: (options?: HandlerGraphQLOptions) =>
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types.js";
|
|
3
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
4
4
|
export default _default;
|
package/createGraphQLHandler.js
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
var _boolean = require("boolean");
|
|
9
|
-
var _handler = require("@webiny/handler");
|
|
10
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
12
|
-
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
13
|
-
var _processRequestBody = require("./processRequestBody");
|
|
1
|
+
import { boolean } from "boolean";
|
|
2
|
+
import { RoutePlugin } from "@webiny/handler";
|
|
3
|
+
import WebinyError from "@webiny/error";
|
|
4
|
+
import { createGraphQLSchema, getSchemaPlugins } from "./createGraphQLSchema.js";
|
|
5
|
+
import debugPlugins from "./debugPlugins.js";
|
|
6
|
+
import { processRequestBody } from "./processRequestBody.js";
|
|
7
|
+
import { createRequestBody } from "./createRequestBody.js";
|
|
14
8
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
15
9
|
|
|
16
10
|
const createCacheKey = context => {
|
|
17
|
-
const plugins =
|
|
11
|
+
const plugins = getSchemaPlugins(context);
|
|
18
12
|
// TODO: in the near future, we have to assign a fixed name to every
|
|
19
13
|
// TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
|
|
20
14
|
|
|
21
15
|
// TODO: `getCurrentTenant` should be injected as a parameter.
|
|
22
16
|
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
23
17
|
const tenant = context.tenancy?.getCurrentTenant();
|
|
24
|
-
|
|
25
|
-
// TODO: `getContentLocale` should be injected as a parameter.
|
|
26
|
-
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
27
|
-
const contentLocale = context.i18n?.getContentLocale();
|
|
28
|
-
return [tenant ? `tenant:${tenant.id}` : null, contentLocale ? `locale:${contentLocale.code}` : null, plugins.length.toString()].filter(Boolean).join("#");
|
|
29
|
-
};
|
|
30
|
-
const createRequestBody = body => {
|
|
31
|
-
/**
|
|
32
|
-
* We are trusting that the body payload is correct.
|
|
33
|
-
* The `processRequestBody` will fail if it is not.
|
|
34
|
-
*/
|
|
35
|
-
return typeof body === "string" ? JSON.parse(body) : body;
|
|
18
|
+
return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()].filter(Boolean).join("#");
|
|
36
19
|
};
|
|
37
20
|
const formatErrorPayload = error => {
|
|
38
|
-
if (error instanceof
|
|
21
|
+
if (error instanceof WebinyError) {
|
|
39
22
|
return JSON.stringify({
|
|
40
23
|
type: "CoreGraphQLWebinyError",
|
|
41
24
|
message: error.message,
|
|
42
25
|
code: error.code,
|
|
43
|
-
data: error.data
|
|
26
|
+
data: error.data,
|
|
27
|
+
stack: error.stack
|
|
44
28
|
});
|
|
45
29
|
}
|
|
46
30
|
return JSON.stringify({
|
|
@@ -50,12 +34,12 @@ const formatErrorPayload = error => {
|
|
|
50
34
|
stack: error.stack
|
|
51
35
|
});
|
|
52
36
|
};
|
|
53
|
-
|
|
37
|
+
export default (options = {}) => {
|
|
54
38
|
let schema = undefined;
|
|
55
39
|
let cacheKey = undefined;
|
|
56
|
-
const debug =
|
|
40
|
+
const debug = boolean(options.debug);
|
|
57
41
|
const path = options?.path || "/graphql";
|
|
58
|
-
const route = new
|
|
42
|
+
const route = new RoutePlugin(async ({
|
|
59
43
|
onPost,
|
|
60
44
|
onOptions,
|
|
61
45
|
context
|
|
@@ -69,7 +53,7 @@ var _default = (options = {}) => {
|
|
|
69
53
|
const contextCacheKey = createCacheKey(context);
|
|
70
54
|
if (!schema || cacheKey !== contextCacheKey) {
|
|
71
55
|
try {
|
|
72
|
-
schema =
|
|
56
|
+
schema = await createGraphQLSchema(context);
|
|
73
57
|
cacheKey = contextCacheKey;
|
|
74
58
|
} catch (ex) {
|
|
75
59
|
return reply.code(500).send(formatErrorPayload(ex));
|
|
@@ -84,7 +68,14 @@ var _default = (options = {}) => {
|
|
|
84
68
|
throw ex;
|
|
85
69
|
}
|
|
86
70
|
try {
|
|
87
|
-
const result = await
|
|
71
|
+
const result = await processRequestBody(body, schema, context);
|
|
72
|
+
/**
|
|
73
|
+
* IMPORTANT! Do not send anything if reply was already sent.
|
|
74
|
+
*/
|
|
75
|
+
if (reply.sent) {
|
|
76
|
+
console.warn("Reply already sent, cannot send the result (handler-graphql).");
|
|
77
|
+
return reply;
|
|
78
|
+
}
|
|
88
79
|
return reply.status(200).send(result);
|
|
89
80
|
} catch (ex) {
|
|
90
81
|
console.error(`Error while processing the body request.`);
|
|
@@ -94,10 +85,9 @@ var _default = (options = {}) => {
|
|
|
94
85
|
});
|
|
95
86
|
});
|
|
96
87
|
route.name = "handler.graphql.route.default";
|
|
97
|
-
return [...(debug ? (
|
|
88
|
+
return [...(debug ? debugPlugins() : []), {
|
|
98
89
|
type: "wcp-telemetry-tracker"
|
|
99
90
|
}, route];
|
|
100
91
|
};
|
|
101
|
-
exports.default = _default;
|
|
102
92
|
|
|
103
93
|
//# sourceMappingURL=createGraphQLHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["boolean","RoutePlugin","WebinyError","createGraphQLSchema","getSchemaPlugins","debugPlugins","processRequestBody","createRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","tenant","tenancy","getCurrentTenant","id","length","toString","filter","Boolean","join","formatErrorPayload","error","JSON","stringify","type","message","code","data","stack","name","options","schema","undefined","cacheKey","debug","path","route","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","ex","body","console","result","sent","warn"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type { Context } from \"@webiny/handler\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types.js\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema.js\";\nimport debugPlugins from \"./debugPlugins.js\";\nimport { processRequestBody } from \"./processRequestBody.js\";\nimport { createRequestBody } from \"~/createRequestBody.js\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data,\n stack: error.stack\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = await createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler-graphql).\");\n return reply;\n }\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAGjC,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,mBAAmB,EAAEC,gBAAgB;AAC9C,OAAOC,YAAY;AACnB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAE1B,MAAMC,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;A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KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOH,EAAE,EAAE;QACTE,OAAO,CAAC5B,KAAK,CAAC,0CAA0C,CAAC;QACzD4B,OAAO,CAAC5B,KAAK,CAACD,kBAAkB,CAAC2B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFX,KAAK,CAACP,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIK,KAAK,GAAG9B,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACIoB,IAAI,EAAE;EACV,CAAC,EACDY,KAAK,CACR;AACL,CAAC","ignoreList":[]}
|
package/createGraphQLSchema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare const getSchemaPlugins: (context: Context) => GraphQLSchemaPlugin<Context
|
|
4
|
-
export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema
|
|
1
|
+
import type { Context } from "@webiny/api/types.js";
|
|
2
|
+
import type { GraphQLSchemaPlugin } from "./plugins/index.js";
|
|
3
|
+
export declare const getSchemaPlugins: (context: Context) => import("@webiny/plugins/PluginsContainer.js").WithName<GraphQLSchemaPlugin<Context>>[];
|
|
4
|
+
export declare const createGraphQLSchema: (context: Context) => Promise<import("graphql").GraphQLSchema>;
|
package/createGraphQLSchema.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import gql from "graphql-tag";
|
|
2
|
+
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
3
|
+
import { mergeResolvers } from "@graphql-tools/merge";
|
|
4
|
+
import { RefInputScalar, NumberScalar, AnyScalar, DateScalar, DateTimeScalar, JsonScalar, TimeScalar, LongScalar, IconScalar } from "./builtInTypes/index.js";
|
|
5
|
+
import { ResolverDecoration } from "./ResolverDecoration.js";
|
|
6
|
+
import { GraphQLSchemaComposer } from "./features/GraphQLSchemaBuilder/abstractions.js";
|
|
7
|
+
import { GraphQLSchemaComposerFeature } from "./features/GraphQLSchemaBuilder/feature.js";
|
|
8
|
+
export const getSchemaPlugins = context => {
|
|
9
|
+
return context.plugins.byType("graphql-schema").filter(pl => {
|
|
10
|
+
if (typeof pl.isApplicable === "function") {
|
|
11
|
+
return pl.isApplicable(context);
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
export const createGraphQLSchema = async context => {
|
|
17
|
+
GraphQLSchemaComposerFeature.register(context.container);
|
|
16
18
|
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
17
|
-
|
|
18
|
-
// TODO: once the API packages more closed, we'll have the opportunity
|
|
19
|
-
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
20
|
-
const typeDefs = [(0, _graphqlTag.default)`
|
|
19
|
+
const typeDefs = [gql`
|
|
21
20
|
type Query
|
|
22
21
|
type Mutation
|
|
23
22
|
${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
|
|
24
23
|
scalar JSON
|
|
25
24
|
scalar Long
|
|
25
|
+
scalar Icon
|
|
26
26
|
scalar RefInput
|
|
27
27
|
scalar Number
|
|
28
28
|
scalar Any
|
|
@@ -30,42 +30,69 @@ const createGraphQLSchema = context => {
|
|
|
30
30
|
scalar DateTime
|
|
31
31
|
scalar Time
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
type Error {
|
|
34
|
+
code: String
|
|
35
|
+
message: String
|
|
36
|
+
data: JSON
|
|
37
|
+
stack: String
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type BooleanResponse {
|
|
41
|
+
data: Boolean
|
|
42
|
+
error: Error
|
|
43
|
+
}
|
|
37
44
|
`];
|
|
38
45
|
const resolvers = [{
|
|
39
46
|
...scalars.reduce((acc, s) => {
|
|
40
47
|
acc[s.name] = s;
|
|
41
48
|
return acc;
|
|
42
49
|
}, {}),
|
|
43
|
-
JSON:
|
|
44
|
-
Long:
|
|
45
|
-
RefInput:
|
|
46
|
-
Number:
|
|
47
|
-
Any:
|
|
48
|
-
DateTime:
|
|
49
|
-
Date:
|
|
50
|
-
Time:
|
|
50
|
+
JSON: JsonScalar,
|
|
51
|
+
Long: LongScalar,
|
|
52
|
+
RefInput: RefInputScalar,
|
|
53
|
+
Number: NumberScalar,
|
|
54
|
+
Any: AnyScalar,
|
|
55
|
+
DateTime: DateTimeScalar,
|
|
56
|
+
Date: DateScalar,
|
|
57
|
+
Time: TimeScalar,
|
|
58
|
+
Icon: IconScalar
|
|
51
59
|
}];
|
|
60
|
+
const resolverDecoration = new ResolverDecoration();
|
|
61
|
+
|
|
62
|
+
// Process legacy plugins
|
|
52
63
|
const plugins = getSchemaPlugins(context);
|
|
53
64
|
for (const plugin of plugins) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
const schema = plugin.schema;
|
|
66
|
+
if (schema.typeDefs) {
|
|
67
|
+
typeDefs.push(schema.typeDefs);
|
|
68
|
+
}
|
|
69
|
+
if (schema.resolvers) {
|
|
70
|
+
resolvers.push(schema.resolvers);
|
|
71
|
+
}
|
|
72
|
+
if (schema.resolverDecorators) {
|
|
73
|
+
resolverDecoration.addDecorators(schema.resolverDecorators);
|
|
74
|
+
}
|
|
62
75
|
}
|
|
63
|
-
|
|
76
|
+
|
|
77
|
+
// Process new DI implementations
|
|
78
|
+
const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);
|
|
79
|
+
const schema = await graphQLSchemaComposer.build();
|
|
80
|
+
if (schema.typeDefs) {
|
|
81
|
+
typeDefs.push(schema.typeDefs);
|
|
82
|
+
}
|
|
83
|
+
if (schema.resolvers) {
|
|
84
|
+
resolvers.push(schema.resolvers);
|
|
85
|
+
}
|
|
86
|
+
if (schema.resolverDecorators) {
|
|
87
|
+
resolverDecoration.addDecorators(schema.resolverDecorators);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Create executable schema
|
|
91
|
+
return makeExecutableSchema({
|
|
64
92
|
typeDefs,
|
|
65
|
-
resolvers,
|
|
93
|
+
resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
|
|
66
94
|
inheritResolversFromInterfaces: true
|
|
67
95
|
});
|
|
68
96
|
};
|
|
69
|
-
exports.createGraphQLSchema = createGraphQLSchema;
|
|
70
97
|
|
|
71
98
|
//# sourceMappingURL=createGraphQLSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["gql","makeExecutableSchema","mergeResolvers","RefInputScalar","NumberScalar","AnyScalar","DateScalar","DateTimeScalar","JsonScalar","TimeScalar","LongScalar","IconScalar","ResolverDecoration","GraphQLSchemaComposer","GraphQLSchemaComposerFeature","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","createGraphQLSchema","register","container","scalars","map","item","scalar","typeDefs","name","join","resolvers","reduce","acc","s","JSON","Long","RefInput","Number","Any","DateTime","Date","Time","Icon","resolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","graphQLSchemaComposer","resolve","build","decorateResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport type { GraphQLScalarType } from \"graphql/type/definition.js\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar,\n IconScalar\n} from \"./builtInTypes/index.js\";\nimport { ResolverDecoration } from \"./ResolverDecoration.js\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { GraphQLSchemaComposer } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { GraphQLSchemaComposerFeature } from \"~/features/GraphQLSchemaBuilder/feature.js\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\").filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n};\n\nexport const createGraphQLSchema = async (context: Context) => {\n GraphQLSchemaComposerFeature.register(context.container);\n\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n const typeDefs: TypeDefs[] = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar Icon\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n type Error {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type BooleanResponse {\n data: Boolean\n error: Error\n }\n `\n ];\n\n const resolvers: Resolvers<any>[] = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar,\n Icon: IconScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n // Process legacy plugins\n const plugins = getSchemaPlugins(context);\n\n for (const plugin of plugins) {\n const schema = plugin.schema;\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n }\n\n // Process new DI implementations\n const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);\n const schema = await graphQLSchemaComposer.build();\n\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n\n // Create executable schema\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,aAAa;AAC7B,SAASC,oBAAoB,QAAQ,uBAAuB;AAC5D,SAASC,cAAc,QAAQ,sBAAsB;AAIrD,SACIC,cAAc,EACdC,YAAY,EACZC,SAAS,EACTC,UAAU,EACVC,cAAc,EACdC,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,UAAU;AAEd,SAASC,kBAAkB;AAE3B,SAASC,qBAAqB;AAC9B,SAASC,4BAA4B;AAErC,OAAO,MAAMC,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC,CAACC,MAAM,CAACC,EAAE,IAAI;IAC9E,IAAI,OAAOA,EAAE,CAACC,YAAY,KAAK,UAAU,EAAE;MACvC,OAAOD,EAAE,CAACC,YAAY,CAACL,OAAO,CAAC;IACnC;IACA,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMM,mBAAmB,GAAG,MAAON,OAAgB,IAAK;EAC3DF,4BAA4B,CAACS,QAAQ,CAACP,OAAO,CAACQ,SAAS,CAAC;EAExD,MAAMC,OAAO,GAAGT,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gB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CAACf,SAAS,CAAC;IACpC;IACA,IAAIe,MAAM,CAACE,kBAAkB,EAAE;MAC3BJ,kBAAkB,CAACK,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;IAC/D;EACJ;;EAEA;EACA,MAAME,qBAAqB,GAAGnC,OAAO,CAACQ,SAAS,CAAC4B,OAAO,CAACvC,qBAAqB,CAAC;EAC9E,MAAMkC,MAAM,GAAG,MAAMI,qBAAqB,CAACE,KAAK,CAAC,CAAC;EAElD,IAAIN,MAAM,CAAClB,QAAQ,EAAE;IACjBA,QAAQ,CAACmB,IAAI,CAACD,MAAM,CAAClB,QAAQ,CAAC;EAClC;EACA,IAAIkB,MAAM,CAACf,SAAS,EAAE;IAClBA,SAAS,CAACgB,IAAI,CAACD,MAAM,CAACf,SAAS,CAAC;EACpC;EACA,IAAIe,MAAM,CAACE,kBAAkB,EAAE;IAC3BJ,kBAAkB,CAACK,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;EAC/D;;EAEA;EACA,OAAOhD,oBAAoB,CAAC;IACxB4B,QAAQ;IACRG,SAAS,EAAEa,kBAAkB,CAACS,iBAAiB,CAACpD,cAAc,CAAC8B,SAAS,CAAC,CAAC;IAC1EuB,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { WebinyError } from "@webiny/error";
|
|
3
|
+
import { createZodError } from "@webiny/utils/createZodError.js";
|
|
4
|
+
const requestBodySchema = zod.object({
|
|
5
|
+
query: zod.string(),
|
|
6
|
+
variables: zod.record(zod.any()).nullish().optional(),
|
|
7
|
+
operationName: zod.string().nullish().optional().transform(value => {
|
|
8
|
+
return value || undefined;
|
|
9
|
+
})
|
|
10
|
+
}).passthrough();
|
|
11
|
+
const schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);
|
|
12
|
+
export const createRequestBody = input => {
|
|
13
|
+
const body = typeof input === "string" ? JSON.parse(input) : input;
|
|
14
|
+
const result = schema.safeParse(body);
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
const error = createZodError(result.error);
|
|
17
|
+
throw new WebinyError({
|
|
18
|
+
message: "Invalid GraphQL request! Check your query and variables.",
|
|
19
|
+
code: "GRAPHQL_REQUEST_INVALID",
|
|
20
|
+
data: error.data
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return result.data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=createRequestBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["zod","WebinyError","createZodError","requestBodySchema","object","query","string","variables","record","any","nullish","optional","operationName","transform","value","undefined","passthrough","schema","union","array","createRequestBody","input","body","JSON","parse","result","safeParse","success","error","message","code","data"],"sources":["createRequestBody.ts"],"sourcesContent":["import zod from \"zod\";\nimport { WebinyError } from \"@webiny/error\";\nimport { createZodError } from \"@webiny/utils/createZodError.js\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\n\nconst requestBodySchema = zod\n .object({\n query: zod.string(),\n variables: zod.record(zod.any()).nullish().optional(),\n operationName: zod\n .string()\n .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n })\n })\n .passthrough();\n\nconst schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);\n\nexport const createRequestBody = (input: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n const body = typeof input === \"string\" ? JSON.parse(input) : input;\n\n const result = schema.safeParse(body);\n if (!result.success) {\n const error = createZodError(result.error);\n throw new WebinyError({\n message: \"Invalid GraphQL request! Check your query and variables.\",\n code: \"GRAPHQL_REQUEST_INVALID\",\n data: error.data\n });\n }\n return result.data;\n};\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,cAAc,QAAQ,iCAAiC;AAGhE,MAAMC,iBAAiB,GAAGH,GAAG,CACxBI,MAAM,CAAC;EACJC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