@webiny/handler-graphql 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97

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.
@@ -1 +1,2 @@
1
- export declare const LongScalar: import("graphql").GraphQLScalarType;
1
+ import { GraphQLScalarType } from "graphql";
2
+ export declare const LongScalar: GraphQLScalarType;
@@ -1,9 +1,56 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.LongScalar = void 0;
7
- var _graphqlScalars = require("graphql-scalars");
8
- const LongScalar = _graphqlScalars.LongResolver;
8
+ var _graphql = require("graphql");
9
+ var _language = require("graphql/language");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ const parseValue = value => {
12
+ if (String(value).includes(".")) {
13
+ throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
14
+ value
15
+ });
16
+ }
17
+ if (typeof value === "number") {
18
+ return value;
19
+ }
20
+ if (value === null || value === undefined) {
21
+ return null;
22
+ }
23
+ if (isNaN(value) === true) {
24
+ throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
25
+ value
26
+ });
27
+ }
28
+ return parseInt(value);
29
+ };
30
+ const LongScalar = new _graphql.GraphQLScalarType({
31
+ name: "Long",
32
+ description: "A custom input type to be used for large integers (Long).",
33
+ serialize: value => {
34
+ try {
35
+ return parseValue(value);
36
+ } catch (ex) {
37
+ console.log({
38
+ message: "Value sent must be an integer.",
39
+ code: "INVALID_VALUE",
40
+ data: {
41
+ value
42
+ }
43
+ });
44
+ return null;
45
+ }
46
+ },
47
+ parseValue,
48
+ parseLiteral: ast => {
49
+ const value = ast.value;
50
+ if (ast.kind === _language.Kind.INT) {
51
+ return parseInt(value);
52
+ }
53
+ throw new Error(`Expected type Long, found {${value}}`);
54
+ }
55
+ });
9
56
  exports.LongScalar = LongScalar;
@@ -1 +1 @@
1
- {"version":3,"names":["LongScalar","LongResolver"],"sources":["LongScalar.ts"],"sourcesContent":["import { LongResolver } from \"graphql-scalars\";\nexport const LongScalar = LongResolver;\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,UAAU,GAAGC,4BAAY;AAAC"}
1
+ {"version":3,"names":["parseValue","value","String","includes","WebinyError","undefined","isNaN","parseInt","LongScalar","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Error"],"sources":["LongScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).includes(\".\")) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n if (typeof value === \"number\") {\n return value;\n }\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n\n return parseInt(value);\n};\n\nexport const LongScalar = new GraphQLScalarType({\n name: \"Long\",\n description: \"A custom input type to be used for large integers (Long).\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be an integer.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n const value = (ast as any).value;\n if (ast.kind === Kind.INT) {\n return parseInt(value);\n }\n\n throw new Error(`Expected type Long, found {${value}}`);\n }\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA,MAAMA,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC7B,MAAM,IAAIC,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB;EAEA,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKI,SAAS,EAAE;IACvC,OAAO,IAAI;EACf;EAEA,IAAIC,KAAK,CAACL,KAAK,CAAC,KAAK,IAAI,EAAE;IACvB,MAAM,IAAIG,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EAEA,OAAOM,QAAQ,CAACN,KAAK,CAAC;AAC1B,CAAC;AAEM,MAAMO,UAAU,GAAG,IAAIC,0BAAiB,CAAC;EAC5CC,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2DAA2D;EACxEC,SAAS,EAAGX,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,OAAOY,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,gCAAgC;QACzCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFjB;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVmB,YAAY,EAAEC,GAAG,IAAI;IACjB,MAAMnB,KAAK,GAAImB,GAAG,CAASnB,KAAK;IAChC,IAAImB,GAAG,CAACC,IAAI,KAAKC,cAAI,CAACC,GAAG,EAAE;MACvB,OAAOhB,QAAQ,CAACN,KAAK,CAAC;IAC1B;IAEA,MAAM,IAAIuB,KAAK,CAAE,8BAA6BvB,KAAM,GAAE,CAAC;EAC3D;AACJ,CAAC,CAAC;AAAC"}
@@ -1,2 +1,2 @@
1
1
  import { GraphQLScalarType } from "graphql";
2
- export declare const RefInput: GraphQLScalarType;
2
+ export declare const RefInputScalar: GraphQLScalarType;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RefInput = void 0;
6
+ exports.RefInputScalar = void 0;
7
7
  var _graphql = require("graphql");
8
8
  const isMongoId = value => {
9
9
  if (/^[0-9a-fA-F]{24}$/.test(value)) {
@@ -11,7 +11,7 @@ const isMongoId = value => {
11
11
  }
12
12
  throw new Error("Must be a valid Mongo ID!");
13
13
  };
14
- const RefInput = new _graphql.GraphQLScalarType({
14
+ const RefInputScalar = new _graphql.GraphQLScalarType({
15
15
  name: "RefInput",
16
16
  description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
17
17
  serialize: value => {
@@ -51,4 +51,4 @@ const RefInput = new _graphql.GraphQLScalarType({
51
51
  throw new Error("Invalid RefInput value!");
52
52
  }
53
53
  });
54
- exports.RefInput = RefInput;
54
+ exports.RefInputScalar = RefInputScalar;
@@ -1 +1 @@
1
- {"version":3,"names":["isMongoId","value","test","Error","RefInput","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields","length"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst isMongoId = (value: any): string => {\n if (/^[0-9a-fA-F]{24}$/.test(value)) {\n return value;\n }\n\n throw new Error(\"Must be a valid Mongo ID!\");\n};\n\nexport const RefInput = 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 serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isMongoId(value);\n }\n\n if (\"id\" in value) {\n return isMongoId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isMongoId(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-ignore\n return isMongoId(value.value);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E;QACxC,MAAM;UAAER,IAAI;UAAEL;QAAM,CAAC,GAAGW,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACL,KAAK,KAAK,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;AAAC"}
1
+ {"version":3,"names":["isMongoId","value","test","Error","RefInputScalar","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields","length"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst isMongoId = (value: any): string => {\n if (/^[0-9a-fA-F]{24}$/.test(value)) {\n return value;\n }\n\n throw new Error(\"Must be a valid Mongo ID!\");\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 serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isMongoId(value);\n }\n\n if (\"id\" in value) {\n return isMongoId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isMongoId(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-ignore\n return isMongoId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;AAAA;AAEA,MAAMA,SAAS,GAAIC,KAAU,IAAa;EACtC,IAAI,mBAAmB,CAACC,IAAI,CAACD,KAAK,CAAC,EAAE;IACjC,OAAOA,KAAK;EAChB;E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jC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC;AAAC"}
@@ -1,4 +1,4 @@
1
- import { HandlerGraphQLOptions } from "./types";
2
1
  import { PluginCollection } from "@webiny/plugins/types";
2
+ import { HandlerGraphQLOptions } from "./types";
3
3
  declare const _default: (options?: HandlerGraphQLOptions) => PluginCollection;
4
4
  export default _default;
@@ -6,18 +6,36 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _boolean = require("boolean");
9
+ var _handler = require("@webiny/handler");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
11
  var _createGraphQLSchema = require("./createGraphQLSchema");
10
12
  var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
11
13
  var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
12
- var _handler = require("@webiny/handler");
13
14
  const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
14
15
 
15
- /**
16
- * TODO Until we figure out how to better convert incoming body, we will leave it as any.
17
- */
18
16
  const createRequestBody = body => {
17
+ /**
18
+ * We are trusting that the body payload is correct.
19
+ * The `processRequestBody` will fail if it is not.
20
+ */
19
21
  return typeof body === "string" ? JSON.parse(body) : body;
20
22
  };
23
+ const formatErrorPayload = error => {
24
+ if (error instanceof _error.default) {
25
+ return JSON.stringify({
26
+ type: "CoreGraphQLWebinyError",
27
+ message: error.message,
28
+ code: error.code,
29
+ data: error.data
30
+ });
31
+ }
32
+ return JSON.stringify({
33
+ type: "Error",
34
+ name: error.name,
35
+ message: error.message,
36
+ stack: error.stack
37
+ });
38
+ };
21
39
  var _default = (options = {}) => {
22
40
  let schema = undefined;
23
41
  const debug = (0, _boolean.boolean)(options.debug);
@@ -30,15 +48,32 @@ var _default = (options = {}) => {
30
48
  onOptions(path, async (_, reply) => {
31
49
  return reply.status(204).headers({
32
50
  "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
33
- }).send({});
51
+ }).send({}).hijack();
34
52
  });
35
53
  onPost(path, async (request, reply) => {
36
54
  if (!schema) {
37
- schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
55
+ try {
56
+ schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
57
+ } catch (ex) {
58
+ return reply.code(500).send(formatErrorPayload(ex));
59
+ }
60
+ }
61
+ let body;
62
+ try {
63
+ body = createRequestBody(request.body);
64
+ } catch (ex) {
65
+ console.error(`Error while creating the body request.`);
66
+ console.error(formatErrorPayload(ex));
67
+ throw ex;
68
+ }
69
+ try {
70
+ const result = await (0, _processRequestBody.default)(body, schema, context);
71
+ return reply.status(200).send(result);
72
+ } catch (ex) {
73
+ console.error(`Error while processing the body request.`);
74
+ console.error(formatErrorPayload(ex));
75
+ throw ex;
38
76
  }
39
- const body = createRequestBody(request.body);
40
- const result = await (0, _processRequestBody.default)(body, schema, context);
41
- return reply.status(200).send(result);
42
77
  });
43
78
  });
44
79
  route.name = "handler.graphql.route.default";
@@ -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","result","processRequestBody","name","debugPlugins","type"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema } from \"./createGraphQLSchema\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\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\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 schema = createGraphQLSchema(context);\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;AAEA;AACA;AAEA;AAEA,MAAMA,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC;AACA;AACA;AACA,MAAMC,iBAAiB,GAAIC,IAAS,IAAU;EAC1C,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAAC,eAEa,CAACG,OAA8B,GAAG,CAAC,CAAC,KAAuB;EACtE,IAAIC,MAAiC,GAAGC,SAAS;EAEjD,MAAMC,KAAK,GAAG,IAAAC,gBAAO,EAACJ,OAAO,CAACG,KAAK,CAAC;EAEpC,MAAME,IAAI,GAAG,CAAAL,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,IAAI,KAAI,UAAU;EAExC,MAAMC,KAAK,GAAG,IAAIC,oBAAW,CAAC,OAAO;IAAEC,MAAM;IAAEC,SAAS;IAAEC;EAAQ,CAAC,KAAK;IACpED,SAAS,CAACJ,IAAI,EAAE,OAAOM,CAAC,EAAEC,KAAK,KAAK;MAChC,OAAOA,KAAK,CACPC,MAAM,CAAC,GAAG,CAAC,CACXC,OAAO,CAAC;QACL,eAAe,EAAG,mBAAkBnB,qBAAsB;MAC9D,CAAC,CAAC,CACDoB,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC;IACFP,MAAM,CAACH,IAAI,EAAE,OAAOW,OAAO,EAAEJ,KAAK,KAAK;MACnC,IAAI,CAACX,MAAM,EAAE;QACTA,MAAM,GAAG,IAAAgB,wCAAmB,EAACP,OAAO,CAAC;MACzC;MACA,MAAMb,IAAI,GAAGD,iBAAiB,CAACoB,OAAO,CAACnB,IAAI,CAAC;MAC5C,MAAMqB,MAAM,GAAG,MAAM,IAAAC,2BAAkB,EAACtB,IAAI,EAAEI,MAAM,EAAES,OAAO,CAAC;MAC9D,OAAOE,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACG,MAAM,CAAC;IACzC,CAAC,CAAC;EACN,CAAC,CAAC;EAEFZ,KAAK,CAACc,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIjB,KAAK,GAAG,IAAAkB,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChC;IACIC,IAAI,EAAE;EACV,CAAC,EACDhB,KAAK,CACR;AACL,CAAC;AAAA"}
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","console","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: \"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 = {}): 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 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 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;AAEA;AACA;AAGA;AACA;AACA;AAEA,MAAMA,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,iBAAiB,GAAIC,IAAa,IAAgD;EACpF;AACJ;AACA;AACA;EACI,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,OAAO,EAAEL,KAAK,KAAK;MACnC,IAAI,CAACX,MAAM,EAAE;QACT,IAAI;UACAA,MAAM,GAAG,IAAAiB,wCAAmB,EAACR,OAAO,CAAC;QACzC,CAAC,CAAC,OAAOS,EAAE,EAAE;UACT,OAAOP,KAAK,CAAChB,IAAI,CAAC,GAAG,CAAC,CAACmB,IAAI,CAACzB,kBAAkB,CAAC6B,EAAE,CAAC,CAAC;QACvD;MACJ;MACA,IAAIhC,IAA+C;MACnD,IAAI;QACAA,IAAI,GAAGD,iBAAiB,CAAC+B,OAAO,CAAC9B,IAAI,CAAC;MAC1C,CAAC,CAAC,OAAOgC,EAAE,EAAE;QACTC,OAAO,CAAC7B,KAAK,CAAE,wCAAuC,CAAC;QACvD6B,OAAO,CAAC7B,KAAK,CAACD,kBAAkB,CAAC6B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;MACA,IAAI;QACA,MAAME,MAAM,GAAG,MAAM,IAAAC,2BAAkB,EAACnC,IAAI,EAAEc,MAAM,EAAES,OAAO,CAAC;QAC9D,OAAOE,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACM,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC7B,KAAK,CAAE,0CAAyC,CAAC;QACzD6B,OAAO,CAAC7B,KAAK,CAACD,kBAAkB,CAAC6B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFb,KAAK,CAACR,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIK,KAAK,GAAG,IAAAoB,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChC;IACI7B,IAAI,EAAE;EACV,CAAC,EACDY,KAAK,CACR;AACL,CAAC;AAAA"}
@@ -11,6 +11,9 @@ var _schema = require("@graphql-tools/schema");
11
11
  var _builtInTypes = require("./builtInTypes");
12
12
  const createGraphQLSchema = context => {
13
13
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
14
+
15
+ // TODO: once the API packages more closed, we'll have the opportunity
16
+ // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
14
17
  const typeDefs = [(0, _graphqlTag.default)`
15
18
  type Query
16
19
  type Mutation
@@ -23,6 +26,11 @@ const createGraphQLSchema = context => {
23
26
  scalar Date
24
27
  scalar DateTime
25
28
  scalar Time
29
+
30
+ # This directive doesn't do anything on the GraphQL resolution level. It just serves
31
+ # as a way to tell the Prerendering Service whether the GraphQL query needs to be
32
+ # cached or not.
33
+ directive @ps(cache: Boolean) on QUERY
26
34
  `];
27
35
  const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
28
36
  acc[s.name] = s;
@@ -30,16 +38,15 @@ const createGraphQLSchema = context => {
30
38
  }, {})), {}, {
31
39
  JSON: _builtInTypes.JsonScalar,
32
40
  Long: _builtInTypes.LongScalar,
33
- RefInput: _builtInTypes.RefInput,
41
+ RefInput: _builtInTypes.RefInputScalar,
34
42
  Number: _builtInTypes.NumberScalar,
35
43
  Any: _builtInTypes.AnyScalar,
36
44
  DateTime: _builtInTypes.DateTimeScalar,
37
45
  Date: _builtInTypes.DateScalar,
38
46
  Time: _builtInTypes.TimeScalar
39
47
  })];
40
- const gqlPlugins = context.plugins.byType("graphql-schema");
41
- for (let i = 0; i < gqlPlugins.length; i++) {
42
- const plugin = gqlPlugins[i];
48
+ const plugins = context.plugins.byType("graphql-schema");
49
+ for (const plugin of plugins) {
43
50
  /**
44
51
  * TODO @ts-refactor
45
52
  * Figure out correct types on typeDefs and resolvers
@@ -1 +1 @@
1
- {"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","gqlPlugins","i","length","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInput,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n const 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 ];\n\n const resolvers = [\n {\n ...scalars.reduce((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {} as Record<string, GraphQLScalarType>),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const gqlPlugins = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (let i = 0; i < gqlPlugins.length; i++) {\n const plugin = gqlPlugins[i];\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AAYO,MAAMA,mBAAmB,GAAIC,OAAgB,IAAK;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAC1BC,M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AA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","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","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { 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 { GraphQLScalarType } from \"graphql/type/definition\";\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 more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const 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 ];\n\n const resolvers = [\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 plugins = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AAYO,MAAMA,mBAAmB,GAAIC,OAAgB,IAAK;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CC,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAG,CAAC;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAG,CAACE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,CACJ;EAED,MAAMC,SAAS,GAAG,6DAEPV,OAAO,CAACW,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;IAC7DD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;IACf,OAAOD,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAC;IACNE,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC,wBAAU;IAChBC,QAAQ,EAAEC,4BAAc;IACxBC,MAAM,EAAEC,0BAAY;IACpBC,GAAG,EAAEC,uBAAS;IACdC,QAAQ,EAAEC,4BAAc;IACxBC,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC;EAAU,GAEvB;EAED,MAAM5B,OAAO,GAAGF,OAAO,CAACE,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;EAC7E,KAAK,MAAM4B,MAAM,IAAI7B,OAAO,EAAE;IAC1B;AACR;AACA;AACA;IACQ;IACAK,QAAQ,CAACyB,IAAI,CAACD,MAAM,CAACE,MAAM,CAAC1B,QAAQ,CAAC;IACrC;IACAI,SAAS,CAACqB,IAAI,CAACD,MAAM,CAACE,MAAM,CAACtB,SAAS,CAAC;EAC3C;EAEA,OAAO,IAAAuB,4BAAoB,EAAC;IACxB3B,QAAQ;IACRI,SAAS;IACTwB,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAAC"}
package/index.d.ts CHANGED
@@ -2,5 +2,6 @@ import { HandlerGraphQLOptions } from "./types";
2
2
  export * from "./errors";
3
3
  export * from "./responses";
4
4
  export * from "./plugins";
5
+ export { default as processRequestBody } from "./processRequestBody";
5
6
  declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
6
7
  export default _default;
package/index.js CHANGED
@@ -4,8 +4,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- var _exportNames = {};
7
+ var _exportNames = {
8
+ processRequestBody: true
9
+ };
8
10
  exports.default = void 0;
11
+ Object.defineProperty(exports, "processRequestBody", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _processRequestBody.default;
15
+ }
16
+ });
9
17
  var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
10
18
  var _errors = require("./errors");
11
19
  Object.keys(_errors).forEach(function (key) {
@@ -43,5 +51,6 @@ Object.keys(_plugins).forEach(function (key) {
43
51
  }
44
52
  });
45
53
  });
54
+ var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
46
55
  var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
47
56
  exports.default = _default;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["options","createGraphQLHandler"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n"],"mappings":";;;;;;;;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAA0B,eAEX,CAACA,OAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,IAAAC,6BAAoB,EAACD,OAAO,CAAC,CAAC;AAAA"}
1
+ {"version":3,"names":["options","createGraphQLHandler"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\nexport { default as processRequestBody } from \"./processRequestBody\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n"],"mappings":";;;;;;;;;;;;;;;;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAqE,eAEtD,CAACA,OAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,IAAAC,6BAAoB,EAACD,OAAO,CAAC,CAAC;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "0.0.0-unstable.990c3ab1b6",
3
+ "version": "0.0.0-unstable.aa00eecd97",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,27 +14,28 @@
14
14
  "Adrian Smijulj <adrian@webiny.com>"
15
15
  ],
16
16
  "dependencies": {
17
- "@babel/runtime": "7.20.1",
17
+ "@babel/runtime": "7.20.13",
18
18
  "@graphql-tools/schema": "7.1.5",
19
- "@webiny/api": "0.0.0-unstable.990c3ab1b6",
20
- "@webiny/error": "0.0.0-unstable.990c3ab1b6",
21
- "@webiny/handler": "0.0.0-unstable.990c3ab1b6",
22
- "@webiny/plugins": "0.0.0-unstable.990c3ab1b6",
19
+ "@webiny/api": "0.0.0-unstable.aa00eecd97",
20
+ "@webiny/error": "0.0.0-unstable.aa00eecd97",
21
+ "@webiny/handler": "0.0.0-unstable.aa00eecd97",
22
+ "@webiny/plugins": "0.0.0-unstable.aa00eecd97",
23
23
  "boolean": "3.2.0",
24
24
  "graphql": "15.8.0",
25
25
  "graphql-scalars": "1.12.0",
26
26
  "graphql-tag": "2.12.6"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/cli": "^7.19.3",
30
- "@babel/core": "^7.19.3",
31
- "@babel/preset-env": "^7.19.4",
32
- "@webiny/cli": "^0.0.0-unstable.990c3ab1b6",
33
- "@webiny/handler-aws": "^0.0.0-unstable.990c3ab1b6",
34
- "@webiny/project-utils": "^0.0.0-unstable.990c3ab1b6",
35
- "jest": "^28.1.0",
36
- "jest-mock-console": "^1.0.0",
37
- "rimraf": "^3.0.2",
29
+ "@babel/cli": "7.20.7",
30
+ "@babel/core": "7.20.12",
31
+ "@babel/preset-env": "7.20.2",
32
+ "@webiny/cli": "0.0.0-unstable.aa00eecd97",
33
+ "@webiny/handler-aws": "0.0.0-unstable.aa00eecd97",
34
+ "@webiny/project-utils": "0.0.0-unstable.aa00eecd97",
35
+ "jest": "28.1.3",
36
+ "jest-mock-console": "1.3.0",
37
+ "rimraf": "3.0.2",
38
+ "ttypescript": "1.5.15",
38
39
  "typescript": "4.7.4"
39
40
  },
40
41
  "publishConfig": {
@@ -45,5 +46,5 @@
45
46
  "build": "yarn webiny run build",
46
47
  "watch": "yarn webiny run watch"
47
48
  },
48
- "gitHead": "87e7b4d0a643f65b31d029d6bf2a81902fb940a8"
49
+ "gitHead": "aa00eecd97d16da9bdb0581f33d491487ce43ce9"
49
50
  }
@@ -28,12 +28,13 @@ const processRequestBody = async (body, schema, context) => {
28
28
  return result;
29
29
  };
30
30
  var _default = async (requestBody, schema, context) => {
31
- if (Array.isArray(requestBody) === true) {
32
- const result = [];
33
- for (let i = 0; i < requestBody.length; i++) {
34
- result.push(await processRequestBody(requestBody[i], schema, context));
31
+ if (Array.isArray(requestBody)) {
32
+ const results = [];
33
+ for (const body of requestBody) {
34
+ const result = await processRequestBody(body, schema, context);
35
+ results.push(result);
35
36
  }
36
- return result;
37
+ return results;
37
38
  }
38
39
  return await processRequestBody(requestBody, schema, context);
39
40
  };
@@ -1 +1 @@
1
- {"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","i","length","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import { ExecutionResult, graphql, GraphQLSchema } from \"graphql\";\nimport { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin, GraphQLRequestBody } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\n\nconst processRequestBody = async (\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n) => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql(schema, query, {}, context, variables, operationName);\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result;\n};\n\nexport default async (\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult[] | ExecutionResult> => {\n if (Array.isArray(requestBody) === true) {\n const result: ExecutionResult[] = [];\n for (let i = 0; i < (requestBody as GraphQLRequestBody[]).length; i++) {\n result.push(\n await processRequestBody((requestBody as GraphQLRequestBody[])[i], schema, context)\n );\n }\n return result;\n }\n return await processRequestBody(requestBody as GraphQLRequestBody, schema, context);\n};\n"],"mappings":";;;;;;AAAA;AAIA,MAAMA,kBAAkB,GAAG,OACvBC,IAAwB,EACxBC,MAAqB,EACrBC,OAAgB,KACf;EACD,MAAM;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGL,IAAI;EAEhDE,OAAO,CAACI,OAAO,CACVC,MAAM,CAA2B,sBAAsB,CAAC,CACxDC,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACC,KAAK,CAAC;IAAEV,IAAI;IAAEC,MAAM;IAAEC;EAAQ,CAAC,CAAC,CAAC;EAEvD,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAO,EAACX,MAAM,EAAEE,KAAK,EAAE,CAAC,CAAC,EAAED,OAAO,EAAEE,SAAS,EAAEC,aAAa,CAAC;EAElFH,OAAO,CAACI,OAAO,CAACC,MAAM,CAA0B,qBAAqB,CAAC,CAACC,OAAO,CAACC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAK,CAAC;MAAEC,MAAM;MAAEX,IAAI;MAAEC,MAAM;MAAEC;IAAQ,CAAC,CAAC;EAC/C,CAAC,CAAC;EAEF,OAAOS,MAAM;AACjB,CAAC;AAAC,eAEa,OACXE,WAAsD,EACtDZ,MAAqB,EACrBC,OAAgB,KAC+B;EAC/C,IAAIY,KAAK,CAACC,OAAO,CAACF,WAAW,CAAC,KAAK,IAAI,EAAE;IACrC,MAAMF,MAAyB,GAAG,EAAE;IACpC,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAIH,WAAW,CAA0BI,MAAM,EAAED,CAAC,EAAE,EAAE;MACnEL,MAAM,CAACO,IAAI,CACP,MAAMnB,kBAAkB,CAAEc,WAAW,CAA0BG,CAAC,CAAC,EAAEf,MAAM,EAAEC,OAAO,CAAC,CACtF;IACL;IACA,OAAOS,MAAM;EACjB;EACA,OAAO,MAAMZ,kBAAkB,CAACc,WAAW,EAAwBZ,MAAM,EAAEC,OAAO,CAAC;AACvF,CAAC;AAAA"}
1
+ {"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","results","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import { ExecutionResult, graphql, GraphQLSchema } from \"graphql\";\nimport { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin, GraphQLRequestBody } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nconst processRequestBody = async (\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n) => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql(schema, query, {}, context, variables, operationName);\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result;\n};\n\nexport default async (\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult[] | ExecutionResult> => {\n if (Array.isArray(requestBody)) {\n const results: ExecutionResult[] = [];\n for (const body of requestBody) {\n const result = await processRequestBody(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await processRequestBody(requestBody, schema, context);\n};\n"],"mappings":";;;;;;AAAA;AAIA,MAAMA,kBAAkB,GAAG,OACvBC,IAAwB,EACxBC,MAAqB,EACrBC,OAAgB,KACf;EACD,MAAM;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGL,IAAI;EAEhDE,OAAO,CAACI,OAAO,CACVC,MAAM,CAA2B,sBAAsB,CAAC,CACxDC,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACC,KAAK,CAAC;IAAEV,IAAI;IAAEC,MAAM;IAAEC;EAAQ,CAAC,CAAC,CAAC;EAEvD,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAO,EAACX,MAAM,EAAEE,KAAK,EAAE,CAAC,CAAC,EAAED,OAAO,EAAEE,SAAS,EAAEC,aAAa,CAAC;EAElFH,OAAO,CAACI,OAAO,CAACC,MAAM,CAA0B,qBAAqB,CAAC,CAACC,OAAO,CAACC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAK,CAAC;MAAEC,MAAM;MAAEX,IAAI;MAAEC,MAAM;MAAEC;IAAQ,CAAC,CAAC;EAC/C,CAAC,CAAC;EAEF,OAAOS,MAAM;AACjB,CAAC;AAAC,eAEa,OACXE,WAAsD,EACtDZ,MAAqB,EACrBC,OAAgB,KAC+B;EAC/C,IAAIY,KAAK,CAACC,OAAO,CAACF,WAAW,CAAC,EAAE;IAC5B,MAAMG,OAA0B,GAAG,EAAE;IACrC,KAAK,MAAMhB,IAAI,IAAIa,WAAW,EAAE;MAC5B,MAAMF,MAAM,GAAG,MAAMZ,kBAAkB,CAACC,IAAI,EAAEC,MAAM,EAAEC,OAAO,CAAC;MAC9Dc,OAAO,CAACC,IAAI,CAACN,MAAM,CAAC;IACxB;IACA,OAAOK,OAAO;EAClB;EACA,OAAO,MAAMjB,kBAAkB,CAACc,WAAW,EAAEZ,MAAM,EAAEC,OAAO,CAAC;AACjE,CAAC;AAAA"}