@webiny/handler-graphql 5.34.2 → 5.34.3-beta.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.
@@ -31,18 +31,20 @@ const createRequestBody = body => {
31
31
 
32
32
  const formatErrorPayload = error => {
33
33
  if (error instanceof _error.default) {
34
- return {
34
+ return JSON.stringify({
35
+ type: "WebinyError",
35
36
  message: error.message,
36
37
  code: error.code,
37
38
  data: error.data
38
- };
39
+ });
39
40
  }
40
41
 
41
- return {
42
+ return JSON.stringify({
43
+ type: "Error",
42
44
  name: error.name,
43
45
  message: error.message,
44
46
  stack: error.stack
45
- };
47
+ });
46
48
  };
47
49
 
48
50
  var _default = (options = {}) => {
@@ -57,7 +59,7 @@ var _default = (options = {}) => {
57
59
  onOptions(path, async (_, reply) => {
58
60
  return reply.status(204).headers({
59
61
  "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
60
- }).send({});
62
+ }).send({}).hijack();
61
63
  });
62
64
  onPost(path, async (request, reply) => {
63
65
  if (!schema) {
@@ -1 +1 @@
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 { GraphQLRequestBody, 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\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) => {\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,MAAMC,iBAAiB,GAAIC,IAAD,IAA8D;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAND;;AAQA,MAAMG,kBAAkB,GAAIC,KAAD,IAAkB;EACzC,IAAIA,KAAK,YAAYC,cAArB,EAAkC;IAC9B,OAAO;MACHC,OAAO,EAAEF,KAAK,CAACE,OADZ;MAEHC,IAAI,EAAEH,KAAK,CAACG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B,EAAyBY,MAAzB,EAAiCS,OAAjC,CAArB;MACA,OAAOE,KAAK,CAACC,MAAN,CAAa,GAAb,EAAkBE,IAAlB,CAAuBI,MAAvB,CAAP;IACH,CAXK,CAAN;EAYH,CArBa,CAAd;EAuBAb,KAAK,CAACR,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIK,KAAK,GAAG,IAAAkB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACIC,IAAI,EAAE;EADV,CAFG,EAKHhB,KALG,CAAP;AAOH,C"}
1
+ {"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","hijack","request","createGraphQLSchema","ex","result","processRequestBody","debugPlugins"],"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 { GraphQLRequestBody, 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\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: \"WebinyError\",\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 = {}): 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 .hijack();\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,MAAMC,iBAAiB,GAAIC,IAAD,IAA8D;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAND;;AAQA,MAAMG,kBAAkB,GAAIC,KAAD,IAA0B;EACjD,IAAIA,KAAK,YAAYC,cAArB,EAAkC;IAC9B,OAAOJ,IAAI,CAACK,SAAL,CAAe;MAClBC,IAAI,EAAE,aADY;MAElBC,OAAO,EAAEJ,KAAK,CAACI,OAFG;MAGlBC,IAAI,EAAEL,KAAK,CAACK,IAHM;MAIlBC,IAAI,EAAEN,KAAK,CAACM;IAJM,CAAf,CAAP;EAMH;;EAED,OAAOT,IAAI,CAACK,SAAL,CAAe;IAClBC,IAAI,EAAE,OADY;IAElBI,IAAI,EAAEP,KAAK,CAACO,IAFM;IAGlBH,OAAO,EAAEJ,KAAK,CAACI,OAHG;IAIlBI,KAAK,EA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a,CAAd;EAwBAd,KAAK,CAACR,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIK,KAAK,GAAG,IAAAmB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACI5B,IAAI,EAAE;EADV,CAFG,EAKHY,KALG,CAAP;AAOH,C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "5.34.2",
3
+ "version": "5.34.3-beta.0",
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": "5.34.2",
20
- "@webiny/error": "5.34.2",
21
- "@webiny/handler": "5.34.2",
22
- "@webiny/plugins": "5.34.2",
19
+ "@webiny/api": "5.34.3-beta.0",
20
+ "@webiny/error": "5.34.3-beta.0",
21
+ "@webiny/handler": "5.34.3-beta.0",
22
+ "@webiny/plugins": "5.34.3-beta.0",
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": "^5.34.2",
33
- "@webiny/handler-aws": "^5.34.2",
34
- "@webiny/project-utils": "^5.34.2",
32
+ "@webiny/cli": "^5.34.3-beta.0",
33
+ "@webiny/handler-aws": "^5.34.3-beta.0",
34
+ "@webiny/project-utils": "^5.34.3-beta.0",
35
35
  "jest": "^28.1.0",
36
36
  "jest-mock-console": "^1.0.0",
37
37
  "rimraf": "^3.0.2",
@@ -46,5 +46,5 @@
46
46
  "build": "yarn webiny run build",
47
47
  "watch": "yarn webiny run watch"
48
48
  },
49
- "gitHead": "518ff6226deeeb8fdb12e1bd58f250d0c34d966a"
49
+ "gitHead": "84d06078c5532532fdf1edf38f3d006f207aa9f7"
50
50
  }