@webiny/handler-graphql 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d
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/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +26 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.js +3 -5
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.js +5 -12
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +5 -12
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +3 -15
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/JsonScalar.js +2 -3
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +49 -4
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.js +6 -15
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +34 -23
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +3 -14
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.js +3 -19
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +72 -22
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +3 -1
- package/createGraphQLSchema.js +55 -30
- package/createGraphQLSchema.js.map +1 -1
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +12 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +2 -9
- package/debugPlugins.js.map +1 -1
- package/errors.js +2 -5
- package/errors.js.map +1 -1
- package/index.d.ts +7 -2
- package/index.js +53 -11
- package/index.js.map +1 -1
- package/interceptConsole.js +9 -13
- package/interceptConsole.js.map +1 -1
- package/package.json +19 -21
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +16 -13
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.js +3 -3
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +20 -17
- package/processRequestBody.js.map +1 -1
- package/responses.js +6 -36
- package/responses.js.map +1 -1
- package/types.d.ts +17 -10
- package/types.js +3 -1
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +28 -0
- package/utils/resolve.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","GraphQLScalarType","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?: string) => {\n if (!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: string): 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":"
|
|
1
|
+
{"version":3,"names":["_graphql","require","_error","_interopRequireDefault","re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","exports","GraphQLScalarType","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?: string) => {\n if (!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: string): 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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAc,IAAK;EAClC,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACpC,MAAM,IAAII,cAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEF;IAAM,CAAC,CAAC;EAC/F;EACA,MAAMG,MAAM,GAAGH,KAAK,CAACI,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAC3C,IAAIH,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;IACnB,MAAM,IAAIL,cAAW,CAAC,4BAA4B,EAAE,uBAAuB,EAAE;MAAEF;IAAM,CAAC,CAAC;EAC3F;EACA,MAAM,CAACQ,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGP,MAAM;EAC5C,IAAIK,KAAK,IAAI,EAAE,EAAE;IACb,MAAM,IAAIN,cAAW,CAAC,qCAAqC,EAAE,uBAAuB,EAAE;MAClFF;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIS,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIP,cAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFF;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIU,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIR,cAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFF;IACJ,CAAC,CAAC;EACN;EACA,OAAO;IACHQ,KAAK;IACLC,OAAO;IACPC;EACJ,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAIX,KAAa,IAAa;EAC7C,MAAM;IAAEQ,KAAK;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGX,SAAS,CAACC,KAAK,CAAC;EACpD,OAAO,GAAGY,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;AAEM,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5CC,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2CAA2C;EACxD;EACAC,SAAS,EAAER,aAAa;EACxB;EACAS,UAAU,EAAET;AAChB,CAAC,CAAC","ignoreList":[]}
|
package/builtInTypes/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _AnyScalar = require("./AnyScalar");
|
|
8
|
-
|
|
9
7
|
Object.keys(_AnyScalar).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _AnyScalar[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_AnyScalar).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _DateScalar = require("./DateScalar");
|
|
21
|
-
|
|
22
18
|
Object.keys(_DateScalar).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _DateScalar[key]) return;
|
|
@@ -29,9 +25,7 @@ Object.keys(_DateScalar).forEach(function (key) {
|
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
var _DateTimeScalar = require("./DateTimeScalar");
|
|
34
|
-
|
|
35
29
|
Object.keys(_DateTimeScalar).forEach(function (key) {
|
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
|
37
31
|
if (key in exports && exports[key] === _DateTimeScalar[key]) return;
|
|
@@ -42,9 +36,7 @@ Object.keys(_DateTimeScalar).forEach(function (key) {
|
|
|
42
36
|
}
|
|
43
37
|
});
|
|
44
38
|
});
|
|
45
|
-
|
|
46
39
|
var _DateTimeZScalar = require("./DateTimeZScalar");
|
|
47
|
-
|
|
48
40
|
Object.keys(_DateTimeZScalar).forEach(function (key) {
|
|
49
41
|
if (key === "default" || key === "__esModule") return;
|
|
50
42
|
if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
|
|
@@ -55,9 +47,7 @@ Object.keys(_DateTimeZScalar).forEach(function (key) {
|
|
|
55
47
|
}
|
|
56
48
|
});
|
|
57
49
|
});
|
|
58
|
-
|
|
59
50
|
var _JsonScalar = require("./JsonScalar");
|
|
60
|
-
|
|
61
51
|
Object.keys(_JsonScalar).forEach(function (key) {
|
|
62
52
|
if (key === "default" || key === "__esModule") return;
|
|
63
53
|
if (key in exports && exports[key] === _JsonScalar[key]) return;
|
|
@@ -68,9 +58,7 @@ Object.keys(_JsonScalar).forEach(function (key) {
|
|
|
68
58
|
}
|
|
69
59
|
});
|
|
70
60
|
});
|
|
71
|
-
|
|
72
61
|
var _LongScalar = require("./LongScalar");
|
|
73
|
-
|
|
74
62
|
Object.keys(_LongScalar).forEach(function (key) {
|
|
75
63
|
if (key === "default" || key === "__esModule") return;
|
|
76
64
|
if (key in exports && exports[key] === _LongScalar[key]) return;
|
|
@@ -81,9 +69,7 @@ Object.keys(_LongScalar).forEach(function (key) {
|
|
|
81
69
|
}
|
|
82
70
|
});
|
|
83
71
|
});
|
|
84
|
-
|
|
85
72
|
var _NumberScalar = require("./NumberScalar");
|
|
86
|
-
|
|
87
73
|
Object.keys(_NumberScalar).forEach(function (key) {
|
|
88
74
|
if (key === "default" || key === "__esModule") return;
|
|
89
75
|
if (key in exports && exports[key] === _NumberScalar[key]) return;
|
|
@@ -94,9 +80,7 @@ Object.keys(_NumberScalar).forEach(function (key) {
|
|
|
94
80
|
}
|
|
95
81
|
});
|
|
96
82
|
});
|
|
97
|
-
|
|
98
83
|
var _RefInputScalar = require("./RefInputScalar");
|
|
99
|
-
|
|
100
84
|
Object.keys(_RefInputScalar).forEach(function (key) {
|
|
101
85
|
if (key === "default" || key === "__esModule") return;
|
|
102
86
|
if (key in exports && exports[key] === _RefInputScalar[key]) return;
|
|
@@ -107,9 +91,7 @@ Object.keys(_RefInputScalar).forEach(function (key) {
|
|
|
107
91
|
}
|
|
108
92
|
});
|
|
109
93
|
});
|
|
110
|
-
|
|
111
94
|
var _TimeScalar = require("./TimeScalar");
|
|
112
|
-
|
|
113
95
|
Object.keys(_TimeScalar).forEach(function (key) {
|
|
114
96
|
if (key === "default" || key === "__esModule") return;
|
|
115
97
|
if (key in exports && exports[key] === _TimeScalar[key]) return;
|
|
@@ -119,4 +101,6 @@ Object.keys(_TimeScalar).forEach(function (key) {
|
|
|
119
101
|
return _TimeScalar[key];
|
|
120
102
|
}
|
|
121
103
|
});
|
|
122
|
-
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_AnyScalar","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_DateScalar","_DateTimeScalar","_DateTimeZScalar","_JsonScalar","_LongScalar","_NumberScalar","_RefInputScalar","_TimeScalar"],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,UAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,UAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,UAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,WAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,WAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,WAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,eAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,eAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,eA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ugin } from "@webiny/plugins/types";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types";
|
|
3
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
4
4
|
export default _default;
|
package/createGraphQLHandler.js
CHANGED
|
@@ -1,36 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _boolean = require("boolean");
|
|
11
|
-
|
|
9
|
+
var _handler = require("@webiny/handler");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
12
11
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
13
|
-
|
|
14
12
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
15
|
-
|
|
16
|
-
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
17
|
-
|
|
18
|
-
var _handler = require("@webiny/handler");
|
|
19
|
-
|
|
13
|
+
var _processRequestBody = require("./processRequestBody");
|
|
20
14
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const createCacheKey = context => {
|
|
17
|
+
const plugins = (0, _createGraphQLSchema.getSchemaPlugins)(context);
|
|
18
|
+
// TODO: in the near future, we have to assign a fixed name to every
|
|
19
|
+
// TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
|
|
25
20
|
|
|
21
|
+
// TODO: `getCurrentTenant` should be injected as a parameter.
|
|
22
|
+
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
23
|
+
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
|
+
};
|
|
26
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
|
+
*/
|
|
27
35
|
return typeof body === "string" ? JSON.parse(body) : body;
|
|
28
36
|
};
|
|
29
|
-
|
|
37
|
+
const formatErrorPayload = error => {
|
|
38
|
+
if (error instanceof _error.default) {
|
|
39
|
+
return JSON.stringify({
|
|
40
|
+
type: "CoreGraphQLWebinyError",
|
|
41
|
+
message: error.message,
|
|
42
|
+
code: error.code,
|
|
43
|
+
data: error.data
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify({
|
|
47
|
+
type: "Error",
|
|
48
|
+
name: error.name,
|
|
49
|
+
message: error.message,
|
|
50
|
+
stack: error.stack
|
|
51
|
+
});
|
|
52
|
+
};
|
|
30
53
|
var _default = (options = {}) => {
|
|
31
54
|
let schema = undefined;
|
|
55
|
+
let cacheKey = undefined;
|
|
32
56
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
33
|
-
const path =
|
|
57
|
+
const path = options?.path || "/graphql";
|
|
34
58
|
const route = new _handler.RoutePlugin(async ({
|
|
35
59
|
onPost,
|
|
36
60
|
onOptions,
|
|
@@ -39,16 +63,41 @@ var _default = (options = {}) => {
|
|
|
39
63
|
onOptions(path, async (_, reply) => {
|
|
40
64
|
return reply.status(204).headers({
|
|
41
65
|
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
42
|
-
}).send({});
|
|
66
|
+
}).send({}).hijack();
|
|
43
67
|
});
|
|
44
68
|
onPost(path, async (request, reply) => {
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
const contextCacheKey = createCacheKey(context);
|
|
70
|
+
if (!schema || cacheKey !== contextCacheKey) {
|
|
71
|
+
try {
|
|
72
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
73
|
+
cacheKey = contextCacheKey;
|
|
74
|
+
} catch (ex) {
|
|
75
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
let body;
|
|
79
|
+
try {
|
|
80
|
+
body = createRequestBody(request.body);
|
|
81
|
+
} catch (ex) {
|
|
82
|
+
console.error(`Error while creating the body request.`);
|
|
83
|
+
console.error(formatErrorPayload(ex));
|
|
84
|
+
throw ex;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const result = await (0, _processRequestBody.processRequestBody)(body, schema, context);
|
|
88
|
+
/**
|
|
89
|
+
* IMPORTANT! Do not send anything if reply was already sent.
|
|
90
|
+
*/
|
|
91
|
+
if (reply.sent) {
|
|
92
|
+
console.warn("Reply already sent, cannot send the result (handler-graphql).");
|
|
93
|
+
return reply;
|
|
94
|
+
}
|
|
95
|
+
return reply.status(200).send(result);
|
|
96
|
+
} catch (ex) {
|
|
97
|
+
console.error(`Error while processing the body request.`);
|
|
98
|
+
console.error(formatErrorPayload(ex));
|
|
99
|
+
throw ex;
|
|
47
100
|
}
|
|
48
|
-
|
|
49
|
-
const body = createRequestBody(request.body);
|
|
50
|
-
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
51
|
-
return reply.status(200).send(result);
|
|
52
101
|
});
|
|
53
102
|
});
|
|
54
103
|
route.name = "handler.graphql.route.default";
|
|
@@ -56,5 +105,6 @@ var _default = (options = {}) => {
|
|
|
56
105
|
type: "wcp-telemetry-tracker"
|
|
57
106
|
}, route];
|
|
58
107
|
};
|
|
108
|
+
exports.default = _default;
|
|
59
109
|
|
|
60
|
-
|
|
110
|
+
//# sourceMappingURL=createGraphQLHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","
|
|
1
|
+
{"version":3,"names":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","tenancy","getCurrentTenant","contentLocale","i18n","getContentLocale","id","code","length","toString","filter","Boolean","join","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","data","name","stack","_default","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","sent","warn","debugPlugins","exports","default"],"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\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\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 // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\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 });\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 = 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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4 @@
|
|
|
1
|
-
import { Context } from "@webiny/api/types";
|
|
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>>[];
|
|
2
4
|
export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
|
package/createGraphQLSchema.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.createGraphQLSchema = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
7
|
+
exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
|
|
12
8
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
|
-
|
|
14
9
|
var _schema = require("@graphql-tools/schema");
|
|
15
|
-
|
|
10
|
+
var _merge = require("@graphql-tools/merge");
|
|
16
11
|
var _builtInTypes = require("./builtInTypes");
|
|
17
|
-
|
|
12
|
+
var _ResolverDecoration = require("./ResolverDecoration");
|
|
13
|
+
const getSchemaPlugins = context => {
|
|
14
|
+
return context.plugins.byType("graphql-schema").filter(pl => {
|
|
15
|
+
if (typeof pl.isApplicable === "function") {
|
|
16
|
+
return pl.isApplicable(context);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.getSchemaPlugins = getSchemaPlugins;
|
|
18
22
|
const createGraphQLSchema = context => {
|
|
19
23
|
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.
|
|
20
27
|
const typeDefs = [(0, _graphqlTag.default)`
|
|
21
28
|
type Query
|
|
22
29
|
type Mutation
|
|
@@ -29,40 +36,58 @@ const createGraphQLSchema = context => {
|
|
|
29
36
|
scalar Date
|
|
30
37
|
scalar DateTime
|
|
31
38
|
scalar Time
|
|
39
|
+
|
|
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
|
+
type Error {
|
|
46
|
+
code: String
|
|
47
|
+
message: String
|
|
48
|
+
data: JSON
|
|
49
|
+
stack: String
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type BooleanResponse {
|
|
53
|
+
data: Boolean
|
|
54
|
+
error: Error
|
|
55
|
+
}
|
|
32
56
|
`];
|
|
33
|
-
const resolvers = [
|
|
34
|
-
acc
|
|
35
|
-
|
|
36
|
-
|
|
57
|
+
const resolvers = [{
|
|
58
|
+
...scalars.reduce((acc, s) => {
|
|
59
|
+
acc[s.name] = s;
|
|
60
|
+
return acc;
|
|
61
|
+
}, {}),
|
|
37
62
|
JSON: _builtInTypes.JsonScalar,
|
|
38
63
|
Long: _builtInTypes.LongScalar,
|
|
39
|
-
RefInput: _builtInTypes.
|
|
64
|
+
RefInput: _builtInTypes.RefInputScalar,
|
|
40
65
|
Number: _builtInTypes.NumberScalar,
|
|
41
66
|
Any: _builtInTypes.AnyScalar,
|
|
42
67
|
DateTime: _builtInTypes.DateTimeScalar,
|
|
43
68
|
Date: _builtInTypes.DateScalar,
|
|
44
69
|
Time: _builtInTypes.TimeScalar
|
|
45
|
-
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
for (
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
}];
|
|
71
|
+
const resolverDecoration = new _ResolverDecoration.ResolverDecoration();
|
|
72
|
+
const plugins = getSchemaPlugins(context);
|
|
73
|
+
for (const plugin of plugins) {
|
|
74
|
+
const schema = plugin.schema;
|
|
75
|
+
if (schema.typeDefs) {
|
|
76
|
+
typeDefs.push(schema.typeDefs);
|
|
77
|
+
}
|
|
78
|
+
if (schema.resolvers) {
|
|
79
|
+
resolvers.push(schema.resolvers);
|
|
80
|
+
}
|
|
81
|
+
if (schema.resolverDecorators) {
|
|
82
|
+
resolverDecoration.addDecorators(schema.resolverDecorators);
|
|
83
|
+
}
|
|
59
84
|
}
|
|
60
|
-
|
|
61
85
|
return (0, _schema.makeExecutableSchema)({
|
|
62
86
|
typeDefs,
|
|
63
|
-
resolvers,
|
|
87
|
+
resolvers: resolverDecoration.decorateResolvers((0, _merge.mergeResolvers)(resolvers)),
|
|
64
88
|
inheritResolversFromInterfaces: true
|
|
65
89
|
});
|
|
66
90
|
};
|
|
91
|
+
exports.createGraphQLSchema = createGraphQLSchema;
|
|
67
92
|
|
|
68
|
-
|
|
93
|
+
//# sourceMappingURL=createGraphQLSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_merge","_builtInTypes","_ResolverDecoration","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","resolverDecoration","ResolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","makeExecutableSchema","decorateResolvers","mergeResolvers","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\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types\";\nimport type { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { ResolverDecoration } from \"./ResolverDecoration\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins\";\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 = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages are more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\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 RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\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 }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\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 return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAIA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AAGO,MAAMK,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;AAACM,OAAA,CAAAP,gBAAA,GAAAA,gBAAA;AAEK,MAAMQ,mBAAmB,GAAIP,OAAgB,IAAK;EACrD,MAAMQ,OAAO,GAAGR,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CO,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAoB,GAAG,CACzB,IAAAC,mBAAG;AACX;AACA;AACA,cAAcL,OAAO,CAACC,GAAG,CAACE,MAAM,IAAI,UAAUA,M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EAAEoB,kBAAkB,CAACQ,iBAAiB,CAAC,IAAAC,qBAAc,EAAC7B,SAAS,CAAC,CAAC;IAC1E8B,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAACxC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createResolverDecorator = void 0;
|
|
7
|
+
const createResolverDecorator = decorator => {
|
|
8
|
+
return decorator;
|
|
9
|
+
};
|
|
10
|
+
exports.createResolverDecorator = createResolverDecorator;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=createResolverDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createResolverDecorator","decorator","exports"],"sources":["createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,uBAAuB,GAChCC,SAAsD,IACrD;EACD,OAAOA,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/debugPlugins.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
-
import { Context } from "@webiny/api/types";
|
|
1
|
+
import type { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
+
import type { Context } from "@webiny/api/types";
|
|
3
3
|
import { ContextPlugin } from "@webiny/api";
|
|
4
4
|
interface Log {
|
|
5
5
|
method: string;
|
package/debugPlugins.js
CHANGED
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _interceptConsole = require("./interceptConsole");
|
|
9
|
-
|
|
10
8
|
var _api = require("@webiny/api");
|
|
11
|
-
|
|
12
9
|
var _default = () => [new _api.ContextPlugin(async context => {
|
|
13
10
|
if (!context.debug) {
|
|
14
11
|
context.debug = {};
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
if (!context.debug.logs) {
|
|
18
14
|
context.debug.logs = [];
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
22
17
|
context.debug.logs.push({
|
|
23
18
|
method,
|
|
@@ -26,7 +21,6 @@ var _default = () => [new _api.ContextPlugin(async context => {
|
|
|
26
21
|
});
|
|
27
22
|
}), {
|
|
28
23
|
type: "graphql-after-query",
|
|
29
|
-
|
|
30
24
|
apply({
|
|
31
25
|
result,
|
|
32
26
|
context
|
|
@@ -34,12 +28,11 @@ var _default = () => [new _api.ContextPlugin(async context => {
|
|
|
34
28
|
result["extensions"] = {
|
|
35
29
|
console: [...(context.debug.logs || [])]
|
|
36
30
|
};
|
|
37
|
-
|
|
38
31
|
if (context.debug.logs) {
|
|
39
32
|
context.debug.logs.length = 0;
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
}];
|
|
36
|
+
exports.default = _default;
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
//# sourceMappingURL=debugPlugins.js.map
|
package/debugPlugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_interceptConsole","require","_api","_default","ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length","exports","default"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport type { GraphQLAfterQueryPlugin } from \"./types\";\nimport type { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAD,OAAA;AAA4C,IAAAE,QAAA,GAY7BA,CAAA,KAAM,CACjB,IAAIC,kBAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEA,IAAAC,kCAAgB,EAAC,CAACC,MAAM,EAAEC,IAAI,KAAK;IAC9BL,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWI,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAKA,CAAC;IAAEC,MAAM;IAAET;EAAQ,CAAC,EAAE;IACvBS,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACS,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ;AAAAC,OAAA,CAAAC,OAAA,GAAAf,QAAA","ignoreList":[]}
|
package/errors.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.NotFoundError = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
class NotFoundError extends _error.default {
|
|
13
10
|
constructor(message = "Not found.") {
|
|
14
11
|
super(message, "NOT_FOUND");
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
}
|
|
14
|
+
exports.NotFoundError = NotFoundError;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
package/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","NotFoundError","WebinyError","constructor","message","exports"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAWA,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAACC,OAAA,CAAAJ,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types";
|
|
2
3
|
export * from "./errors";
|
|
3
4
|
export * from "./responses";
|
|
5
|
+
export * from "./utils";
|
|
4
6
|
export * from "./plugins";
|
|
5
|
-
|
|
7
|
+
export * from "./processRequestBody";
|
|
8
|
+
export * from "./createResolverDecorator";
|
|
9
|
+
export * from "./ResolverDecoration";
|
|
10
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
6
11
|
export default _default;
|