@webiny/handler-graphql 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.97a151f74d
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/createGraphQLHandler.js
CHANGED
|
@@ -9,14 +9,16 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _boolean = require("boolean");
|
|
11
11
|
|
|
12
|
+
var _handler = require("@webiny/handler");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
12
16
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
13
17
|
|
|
14
18
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
15
19
|
|
|
16
20
|
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
17
21
|
|
|
18
|
-
var _handler = require("@webiny/handler");
|
|
19
|
-
|
|
20
22
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
21
23
|
|
|
22
24
|
/**
|
|
@@ -27,6 +29,22 @@ const createRequestBody = body => {
|
|
|
27
29
|
return typeof body === "string" ? JSON.parse(body) : body;
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
const formatErrorPayload = error => {
|
|
33
|
+
if (error instanceof _error.default) {
|
|
34
|
+
return {
|
|
35
|
+
message: error.message,
|
|
36
|
+
code: error.code,
|
|
37
|
+
data: error.data
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
name: error.name,
|
|
43
|
+
message: error.message,
|
|
44
|
+
stack: error.stack
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
30
48
|
var _default = (options = {}) => {
|
|
31
49
|
let schema = undefined;
|
|
32
50
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
@@ -43,7 +61,11 @@ var _default = (options = {}) => {
|
|
|
43
61
|
});
|
|
44
62
|
onPost(path, async (request, reply) => {
|
|
45
63
|
if (!schema) {
|
|
46
|
-
|
|
64
|
+
try {
|
|
65
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
68
|
+
}
|
|
47
69
|
}
|
|
48
70
|
|
|
49
71
|
const body = createRequestBody(request.body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","ex","result","processRequestBody","debugPlugins","type"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\n/**\n * TODO Until we figure out how to better convert incoming body, we will leave it as any.\n */\nconst createRequestBody = (body: any): any => {\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error) => {\n if (error instanceof WebinyError) {\n return {\n message: error.message,\n code: error.code,\n data: error.data\n };\n }\n\n return {\n name: error.name,\n message: error.message,\n stack: error.stack\n };\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | 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 });\n onPost(path, async (request, reply) => {\n if (!schema) {\n try {\n schema = createGraphQLSchema(context);\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n const body = createRequestBody(request.body);\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\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;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AAEA,MAAMA,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAExC;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAIC,IAAD,IAAoB;EAC1C,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAFD;;AAIA,MAAMG,kBAAkB,GAAIC,KAAD,IAAkB;EACzC,IAAIA,KAAK,YAAYC,cAArB,EAAkC;IAC9B,OAAO;MACHC,OAAO,EAAEF,KAAK,CAACE,OADZ;MAEHC,IAAI,EAAEH,KAAK,CAACG,IAFT;MAGHC,IAAI,EAAEJ,KAAK,CAACI;IAHT,CAAP;EAKH;;EAED,OAAO;IACHC,IAAI,EAAEL,KAAK,CAACK,IADT;IAEHH,OAAO,EAAEF,KAAK,CAACE,OAFZ;IAGHI,KAAK,EAAEN,KAAK,CAACM;EAHV,CAAP;AAKH,CAdD;;eAgBe,CAACC,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQ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AAOH,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.97a151f74d",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "7.19.0",
|
|
18
18
|
"@graphql-tools/schema": "7.1.5",
|
|
19
|
-
"@webiny/api": "0.0.0-unstable.
|
|
20
|
-
"@webiny/error": "0.0.0-unstable.
|
|
21
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
22
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.97a151f74d",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.97a151f74d",
|
|
21
|
+
"@webiny/handler": "0.0.0-unstable.97a151f74d",
|
|
22
|
+
"@webiny/plugins": "0.0.0-unstable.97a151f74d",
|
|
23
23
|
"boolean": "3.2.0",
|
|
24
24
|
"graphql": "15.8.0",
|
|
25
25
|
"graphql-scalars": "1.12.0",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@babel/cli": "^7.19.3",
|
|
30
30
|
"@babel/core": "^7.19.3",
|
|
31
31
|
"@babel/preset-env": "^7.19.4",
|
|
32
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
33
|
-
"@webiny/handler-aws": "^0.0.0-unstable.
|
|
34
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
32
|
+
"@webiny/cli": "^0.0.0-unstable.97a151f74d",
|
|
33
|
+
"@webiny/handler-aws": "^0.0.0-unstable.97a151f74d",
|
|
34
|
+
"@webiny/project-utils": "^0.0.0-unstable.97a151f74d",
|
|
35
35
|
"jest": "^28.1.0",
|
|
36
36
|
"jest-mock-console": "^1.0.0",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"build": "yarn webiny run build",
|
|
46
46
|
"watch": "yarn webiny run watch"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "97a151f74d8c5679323989fcc8cc7036be0f150e"
|
|
49
49
|
}
|