@webiny/handler-graphql 6.0.0-alpha.5 → 6.0.0-rc.0
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 +1 -1
- package/ResolverDecoration.js +3 -10
- package/ResolverDecoration.js.map +1 -1
- 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 +2 -2
- package/createGraphQLHandler.js +18 -35
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -4
- package/createGraphQLSchema.js +41 -36
- 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 +1 -1
- package/createResolverDecorator.js +1 -8
- package/createResolverDecorator.js.map +1 -1
- 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 +9 -9
- package/index.js +10 -96
- package/index.js.map +1 -1
- package/interceptConsole.js +1 -8
- package/interceptConsole.js.map +1 -1
- package/package.json +23 -23
- package/plugins/GraphQLSchemaPlugin.d.ts +2 -2
- package/plugins/GraphQLSchemaPlugin.js +3 -11
- 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 +3 -3
- package/processRequestBody.js +3 -10
- package/processRequestBody.js.map +1 -1
- package/responses.js +5 -16
- package/responses.js.map +1 -1
- package/types.d.ts +6 -6
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -16
- package/utils/index.js.map +1 -1
- package/utils/resolve.d.ts +2 -2
- package/utils/resolve.js +8 -17
- package/utils/resolve.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n /**\n * We can set value as any because we are handling it.\n */\n parseValue: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAE3C,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EAAE,oBAAoB;EACxBC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,CACJ;AAED,MAAMC,SAAS,GAAIC,KAAU,IAAa;EACtC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;EAClE;EACA,KAAK,MAAMC,IAAI,IAAIP,KAAK,EAAE;IACtB,IAAIO,IAAI,CAACN,EAAE,CAACM,IAAI,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC9B,MA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,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const TimeScalar: GraphQLScalarType
|
|
2
|
+
export declare const TimeScalar: GraphQLScalarType<string, string>;
|
|
@@ -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,MAAM,IAAIT,WAAW,CAAC,4BAA4B,EAAE,uBAAuB,EAAE;MAAEG;IAAM,CAAC,CAAC;EAC3F;EACA,MAAM,CAACO,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGP,MAAM;EAC5C,IAAIK,KAAK,IAAI,EAAE,EAAE;IACb,MAAM,IAAIV,WAAW,CAAC,qCAAqC,EAAE,uBAAuB,EAAE;MAClFG;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIQ,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIX,WAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFG;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIS,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIZ,WAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFG;IACJ,CAAC,CAAC;EACN;EACA,OAAO;IACHO,KAAK;IACLC,OAAO;IACPC;EACJ,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAIV,KAAc,IAAa;EAC9C,MAAM;IAAEO,KAAK;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGV,SAAS,CAACC,KAAK,CAAC;EACpD,OAAO,GAAGW,MAAM,CAACJ,KAAK,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAID,MAAM,CAACH,OAAO,CAAC,CAACI,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAID,MAAM,CAClFF,OACJ,CAAC,CAACG,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;AACxB,CAAC;AAED,OAAO,MAAMC,UAAU,GAAG,IAAIjB,iBAAiB,CAAC;EAC5CkB,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2CAA2C;EACxD;EACAC,SAAS,EAAEN,aAAa;EACxB;EACAO,UAAU,EAAEP;AAChB,CAAC,CAAC","ignoreList":[]}
|
package/builtInTypes/index.d.ts
CHANGED
|
@@ -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 type { Plugin } from "@webiny/plugins/types";
|
|
2
|
-
import type { HandlerGraphQLOptions } from "./types";
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types.js";
|
|
3
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,7 @@ var _default = (options = {}) => {
|
|
|
84
68
|
throw ex;
|
|
85
69
|
}
|
|
86
70
|
try {
|
|
87
|
-
const result = await
|
|
71
|
+
const result = await processRequestBody(body, schema, context);
|
|
88
72
|
/**
|
|
89
73
|
* IMPORTANT! Do not send anything if reply was already sent.
|
|
90
74
|
*/
|
|
@@ -101,10 +85,9 @@ var _default = (options = {}) => {
|
|
|
101
85
|
});
|
|
102
86
|
});
|
|
103
87
|
route.name = "handler.graphql.route.default";
|
|
104
|
-
return [...(debug ? (
|
|
88
|
+
return [...(debug ? debugPlugins() : []), {
|
|
105
89
|
type: "wcp-telemetry-tracker"
|
|
106
90
|
}, route];
|
|
107
91
|
};
|
|
108
|
-
exports.default = _default;
|
|
109
92
|
|
|
110
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;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAGP,gBAAgB,CAACM,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAME,MAAM,GAAGF,OAAO,CAACG,OAAO,EAAEC,gBAAgB,CAAC,CAAC;EAElD,OAAO,CAACF,MAAM,GAAG,UAAUA,MAAM,CAACG,EAAE,EAAE,GAAG,IAAI,EAAEJ,OAAO,CAACK,MAAM,CAACC,QAAQ,CAAC,CAAC,CAAC,CACpEC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAMC,kBAAkB,GAAIC,KAAY,IAAa;EACjD,IAAIA,KAAK,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;AACL,CAAC","ignoreList":[]}
|
package/createGraphQLSchema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@webiny/api/types";
|
|
2
|
-
import type { GraphQLSchemaPlugin } from "./plugins";
|
|
3
|
-
export declare const getSchemaPlugins: (context: Context) => import("@webiny/plugins/PluginsContainer").WithName<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,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _schema = require("@graphql-tools/schema");
|
|
10
|
-
var _merge = require("@graphql-tools/merge");
|
|
11
|
-
var _builtInTypes = require("./builtInTypes");
|
|
12
|
-
var _ResolverDecoration = require("./ResolverDecoration");
|
|
13
|
-
const getSchemaPlugins = context => {
|
|
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 => {
|
|
14
9
|
return context.plugins.byType("graphql-schema").filter(pl => {
|
|
15
10
|
if (typeof pl.isApplicable === "function") {
|
|
16
11
|
return pl.isApplicable(context);
|
|
@@ -18,18 +13,16 @@ const getSchemaPlugins = context => {
|
|
|
18
13
|
return true;
|
|
19
14
|
});
|
|
20
15
|
};
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
export const createGraphQLSchema = async context => {
|
|
17
|
+
GraphQLSchemaComposerFeature.register(context.container);
|
|
23
18
|
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
24
|
-
|
|
25
|
-
// TODO: once the API packages are more closed, we'll have the opportunity
|
|
26
|
-
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
27
|
-
const typeDefs = [(0, _graphqlTag.default)`
|
|
19
|
+
const typeDefs = [gql`
|
|
28
20
|
type Query
|
|
29
21
|
type Mutation
|
|
30
22
|
${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
|
|
31
23
|
scalar JSON
|
|
32
24
|
scalar Long
|
|
25
|
+
scalar Icon
|
|
33
26
|
scalar RefInput
|
|
34
27
|
scalar Number
|
|
35
28
|
scalar Any
|
|
@@ -37,11 +30,6 @@ const createGraphQLSchema = context => {
|
|
|
37
30
|
scalar DateTime
|
|
38
31
|
scalar Time
|
|
39
32
|
|
|
40
|
-
# This directive doesn't do anything on the GraphQL resolution level. It just serves
|
|
41
|
-
# as a way to tell the Prerendering Service whether the GraphQL query needs to be
|
|
42
|
-
# cached or not.
|
|
43
|
-
directive @ps(cache: Boolean) on QUERY
|
|
44
|
-
|
|
45
33
|
type Error {
|
|
46
34
|
code: String
|
|
47
35
|
message: String
|
|
@@ -59,16 +47,19 @@ const createGraphQLSchema = context => {
|
|
|
59
47
|
acc[s.name] = s;
|
|
60
48
|
return acc;
|
|
61
49
|
}, {}),
|
|
62
|
-
JSON:
|
|
63
|
-
Long:
|
|
64
|
-
RefInput:
|
|
65
|
-
Number:
|
|
66
|
-
Any:
|
|
67
|
-
DateTime:
|
|
68
|
-
Date:
|
|
69
|
-
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
|
|
70
59
|
}];
|
|
71
|
-
const resolverDecoration = new
|
|
60
|
+
const resolverDecoration = new ResolverDecoration();
|
|
61
|
+
|
|
62
|
+
// Process legacy plugins
|
|
72
63
|
const plugins = getSchemaPlugins(context);
|
|
73
64
|
for (const plugin of plugins) {
|
|
74
65
|
const schema = plugin.schema;
|
|
@@ -82,12 +73,26 @@ const createGraphQLSchema = context => {
|
|
|
82
73
|
resolverDecoration.addDecorators(schema.resolverDecorators);
|
|
83
74
|
}
|
|
84
75
|
}
|
|
85
|
-
|
|
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({
|
|
86
92
|
typeDefs,
|
|
87
|
-
resolvers: resolverDecoration.decorateResolvers(
|
|
93
|
+
resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
|
|
88
94
|
inheritResolversFromInterfaces: true
|
|
89
95
|
});
|
|
90
96
|
};
|
|
91
|
-
exports.createGraphQLSchema = createGraphQLSchema;
|
|
92
97
|
|
|
93
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\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S,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
|