@webiny/handler-graphql 5.30.0 → 5.31.0-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.
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
10
  var _boolean = require("boolean");
13
11
 
14
12
  var _createGraphQLSchema = require("./createGraphQLSchema");
@@ -17,66 +15,46 @@ var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
17
15
 
18
16
  var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
19
17
 
20
- var _utils = require("@webiny/utils");
21
-
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
+ var _handler = require("@webiny/handler");
23
19
 
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
+ const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
25
21
 
26
- const DEFAULT_HEADERS = _objectSpread({
27
- "Content-Type": "application/json",
28
- "Access-Control-Allow-Origin": "*",
29
- "Access-Control-Allow-Headers": "*",
30
- "Access-Control-Allow-Methods": "OPTIONS,POST"
31
- }, (0, _utils.getWebinyVersionHeaders)());
22
+ /**
23
+ * TODO Until we figure out how to better convert incoming body, we will leave it as any.
24
+ */
32
25
 
33
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
26
+ const createRequestBody = body => {
27
+ return typeof body === "string" ? JSON.parse(body) : body;
28
+ };
34
29
 
35
30
  var _default = (options = {}) => {
36
31
  let schema = undefined;
37
32
  const debug = (0, _boolean.boolean)(options.debug);
38
- return [...(debug ? (0, _debugPlugins.default)() : []), {
39
- type: "wcp-telemetry-tracker"
40
- }, {
41
- type: "handler",
42
- name: "handler-graphql",
43
-
44
- async handle(context, next) {
45
- const {
46
- http
47
- } = context;
48
-
49
- if (!http) {
50
- return next();
51
- }
52
-
53
- if (http.request.method === "OPTIONS") {
54
- return http.response({
55
- statusCode: 204,
56
- headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
57
- "Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
58
- })
59
- });
60
- }
61
-
62
- if (http.request.method !== "POST") {
63
- return next();
64
- }
65
-
33
+ const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
34
+ const route = new _handler.RoutePlugin(async ({
35
+ onPost,
36
+ onOptions,
37
+ context
38
+ }) => {
39
+ onOptions(path, async (_, reply) => {
40
+ return reply.status(204).headers({
41
+ "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
42
+ }).send({});
43
+ });
44
+ onPost(path, async (request, reply) => {
66
45
  if (!schema) {
67
46
  schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
68
47
  }
69
48
 
70
- const body = JSON.parse(http.request.body);
49
+ const body = createRequestBody(request.body);
71
50
  const result = await (0, _processRequestBody.default)(body, schema, context);
72
- return http.response({
73
- body: JSON.stringify(result),
74
- statusCode: 200,
75
- headers: DEFAULT_HEADERS
76
- });
77
- }
78
-
79
- }];
51
+ return reply.status(200).send(result);
52
+ });
53
+ });
54
+ route.name = "handler.graphql.route.default";
55
+ return [...(debug ? (0, _debugPlugins.default)() : []), {
56
+ type: "wcp-telemetry-tracker"
57
+ }, route];
80
58
  };
81
59
 
82
60
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","DEFAULT_CACHE_MAX_AGE","options","schema","undefined","debug","boolean","debugPlugins","type","name","handle","context","next","http","request","method","response","statusCode","headers","createGraphQLSchema","body","JSON","parse","result","processRequestBody","stringify"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { HandlerPlugin, Context } from \"@webiny/handler/types\";\nimport { HttpContext } from \"@webiny/handler-http/types\";\nimport { 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 { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { GraphQLSchema } from \"graphql\";\n\nconst DEFAULT_HEADERS = {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"*\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST\",\n ...getWebinyVersionHeaders()\n};\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n return [\n ...(debug ? debugPlugins() : []),\n { type: \"wcp-telemetry-tracker\" },\n {\n type: \"handler\",\n name: \"handler-graphql\",\n async handle(context: Context & HttpContext, next) {\n const { http } = context;\n if (!http) {\n return next();\n }\n\n if (http.request.method === \"OPTIONS\") {\n return http.response({\n statusCode: 204,\n headers: {\n ...DEFAULT_HEADERS,\n \"Cache-Control\": \"public, max-age=\" + DEFAULT_CACHE_MAX_AGE\n }\n });\n }\n\n if (http.request.method !== \"POST\") {\n return next();\n }\n\n if (!schema) {\n schema = createGraphQLSchema(context);\n }\n\n const body = JSON.parse(http.request.body);\n const result = await processRequestBody(body, schema, context);\n\n return http.response({\n body: JSON.stringify(result),\n statusCode: 200,\n headers: DEFAULT_HEADERS\n });\n }\n } as HandlerPlugin\n ];\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAEA;;AAEA;;AACA;;AACA;;;;;;AAGA,MAAMA,eAAe;EACjB,gBAAgB,kBADC;EAEjB,+BAA+B,GAFd;EAGjB,gCAAgC,GAHf;EAIjB,gCAAgC;AAJf,GAKd,IAAAC,8BAAA,GALc,CAArB;;AAQA,MAAMC,qBAAqB,GAAG,QAA9B,C,CAAwC;;eAEzB,CAACC,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQJ,OAAO,CAACG,KAAhB,CAAd;EAEA,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAE,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IAAEC,IAAI,EAAE;EAAR,CAFG,EAGH;IACIA,IAAI,EAAE,SADV;IAEIC,IAAI,EAAE,iBAFV;;IAGI,MAAMC,MAAN,CAAaC,OAAb,EAA6CC,IAA7C,EAAmD;MAC/C,MAAM;QAAEC;MAAF,IAAWF,OAAjB;;MACA,IAAI,CAACE,IAAL,EAAW;QACP,OAAOD,IAAI,EAAX;MACH;;MAED,IAAIC,IAAI,CAACC,OAAL,CAAaC,MAAb,KAAwB,SAA5B,EAAuC;QACnC,OAAOF,IAAI,CAACG,QAAL,CAAc;UACjBC,UAAU,EAAE,GADK;UAEjBC,OAAO,kCACAnB,eADA;YAEH,iBAAiB,qBAAqBE;UAFnC;QAFU,CAAd,CAAP;MAOH;;MAED,IAAIY,IAAI,CAACC,OAAL,CAAaC,MAAb,KAAwB,MAA5B,EAAoC;QAChC,OAAOH,IAAI,EAAX;MACH;;MAED,IAAI,CAACT,MAAL,EAAa;QACTA,MAAM,GAAG,IAAAgB,wCAAA,EAAoBR,OAApB,CAAT;MACH;;MAED,MAAMS,IAAI,GAAGC,IAAI,CAACC,KAAL,CAAWT,IAAI,CAACC,OAAL,CAAaM,IAAxB,CAAb;MACA,MAAMG,MAAM,GAAG,MAAM,IAAAC,2BAAA,EAAmBJ,IAAnB,EAAyBjB,MAAzB,EAAiCQ,OAAjC,CAArB;MAEA,OAAOE,IAAI,CAACG,QAAL,CAAc;QACjBI,IAAI,EAAEC,IAAI,CAACI,SAAL,CAAeF,MAAf,CADW;QAEjBN,UAAU,EAAE,GAFK;QAGjBC,OAAO,EAAEnB;MAHQ,CAAd,CAAP;IAKH;;EAnCL,CAHG,CAAP;AAyCH,C"}
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,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;;eAIe,CAACG,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQJ,OAAO,CAACG,KAAhB,CAAd;EAEA,MAAME,IAAI,GAAG,CAAAL,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEK,IAAT,KAAiB,UAA9B;EAEA,MAAMC,KAAK,GAAG,IAAIC,oBAAJ,CAAgB,OAAO;IAAEC,MAAF;IAAUC,SAAV;IAAqBC;EAArB,CAAP,KAA0C;IACpED,SAAS,CAACJ,IAAD,EAAO,OAAOM,CAAP,EAAUC,KAAV,KAAoB;MAChC,OAAOA,KAAK,CACPC,MADE,CACK,GADL,EAEFC,OAFE,CAEM;QACL,iBAAkB,mBAAkBnB,qBAAsB;MADrD,CAFN,EAKFoB,IALE,CAKG,EALH,CAAP;IAMH,CAPQ,CAAT;IAQAP,MAAM,CAACH,IAAD,EAAO,OAAOW,OAAP,EAAgBJ,KAAhB,KAA0B;MACnC,IAAI,CAACX,MAAL,EAAa;QACTA,MAAM,GAAG,IAAAgB,wCAAA,EAAoBP,OAApB,CAAT;MACH;;MACD,MAAMb,IAAI,GAAGD,iBAAiB,CAACoB,OAAO,CAACnB,IAAT,CAA9B;MACA,MAAMqB,MAAM,GAAG,MAAM,IAAAC,2BAAA,EAAmBtB,IAAnB,EAAyBI,MAAzB,EAAiCS,OAAjC,CAArB;MACA,OAAOE,KAAK,CAACC,MAAN,CAAa,GAAb,EAAkBE,IAAlB,CAAuBG,MAAvB,CAAP;IACH,CAPK,CAAN;EAQH,CAjBa,CAAd;EAmBAZ,KAAK,CAACc,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIjB,KAAK,GAAG,IAAAkB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACIC,IAAI,EAAE;EADV,CAFG,EAKHhB,KALG,CAAP;AAOH,C"}
@@ -1,2 +1,2 @@
1
- import { HttpContext } from "@webiny/handler-http/types";
2
- export declare const createGraphQLSchema: (context: HttpContext) => import("graphql").GraphQLSchema;
1
+ import { Context } from "@webiny/api/types";
2
+ export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
@@ -53,7 +53,7 @@ const createGraphQLSchema = context => {
53
53
  const plugin = gqlPlugins[i];
54
54
  /**
55
55
  * TODO @ts-refactor
56
- * Figure out correct tyeps on typeDefs and resolvers
56
+ * Figure out correct types on typeDefs and resolvers
57
57
  */
58
58
  // @ts-ignore
59
59
 
@@ -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 { HttpContext } from \"@webiny/handler-http/types\";\nimport {\n RefInput,\n Number as NumberScalar,\n Any as 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: HttpContext) => {\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 tyeps 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,OAAD,IAA0B;EACzD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAR,CACXC,MADW,CACiB,gBADjB,EAEXC,GAFW,CAEPC,IAAI,IAAIA,IAAI,CAACC,MAFN,CAAhB;EAIA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAA,CAAI;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAR,CAAYE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAA5C,EAA+CC,IAA/C,CAAoD,GAApD,CAAyD;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAbqB,CAAjB;EAgBA,MAAMC,SAAS,GAAG,iCAEPV,OAAO,CAACW,MAAR,CAAe,CAACC,GAAD,EAAMC,CAAN,KAAY;IAC1BD,GAAG,CAACC,CAAC,CAACL,IAAH,CAAH,GAAcK,CAAd;IACA,OAAOD,GAAP;EACH,CAHE,EAGA,EAHA,CAFO;IAMVE,IAAI,EAAEC,wBANI;IAOVC,IAAI,EAAEC,wBAPI;IAQVC,QAAQ,EAARA,sBARU;IASVC,MAAM,EAAEC,oBATE;IAUVC,GAAG,EAAEC,iBAVK;IAWVC,QAAQ,EAAEC,4BAXA;IAYVC,IAAI,EAAEC,wBAZI;IAaVC,IAAI,EAAEC;EAbI,GAAlB;EAiBA,MAAMC,UAAU,GAAG9B,OAAO,CAACE,OAAR,CAAgBC,MAAhB,CAA4C,gBAA5C,CAAnB;;EACA,KAAK,IAAI4B,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,EAAxC,EAA4C;IACxC,MAAME,MAAM,GAAGH,UAAU,CAACC,CAAD,CAAzB;IACA;AACR;AACA;AACA;IACQ;;IACAxB,QAAQ,CAAC2B,IAAT,CAAcD,MAAM,CAACE,MAAP,CAAc5B,QAA5B,EAPwC,CAQxC;;IACAI,SAAS,CAACuB,IAAV,CAAeD,MAAM,CAACE,MAAP,CAAcxB,SAA7B;EACH;;EAED,OAAO,IAAAyB,4BAAA,EAAqB;IACxB7B,QADwB;IAExBI,SAFwB;IAGxB0B,8BAA8B,EAAE;EAHR,CAArB,CAAP;AAKH,CAxDM"}
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 Number as NumberScalar,\n Any as 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,OAAD,IAAsB;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAR,CACXC,MADW,CACiB,gBADjB,EAEXC,GAFW,CAEPC,IAAI,IAAIA,IAAI,CAACC,MAFN,CAAhB;EAIA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAA,CAAI;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAR,CAAYE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAA5C,EAA+CC,IAA/C,CAAoD,GAApD,CAAyD;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAbqB,CAAjB;EAgBA,MAAMC,SAAS,GAAG,iCAEPV,OAAO,CAACW,MAAR,CAAe,CAACC,GAAD,EAAMC,CAAN,KAAY;IAC1BD,GAAG,CAACC,CAAC,CAACL,IAAH,CAAH,GAAcK,CAAd;IACA,OAAOD,GAAP;EACH,CAHE,EAGA,EAHA,CAFO;IAMVE,IAAI,EAAEC,wBANI;IAOVC,IAAI,EAAEC,wBAPI;IAQVC,QAAQ,EAARA,sBARU;IASVC,MAAM,EAAEC,oBATE;IAUVC,GAAG,EAAEC,iBAVK;IAWVC,QAAQ,EAAEC,4BAXA;IAYVC,IAAI,EAAEC,wBAZI;IAaVC,IAAI,EAAEC;EAbI,GAAlB;EAiBA,MAAMC,UAAU,GAAG9B,OAAO,CAACE,OAAR,CAAgBC,MAAhB,CAA4C,gBAA5C,CAAnB;;EACA,KAAK,IAAI4B,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,EAAxC,EAA4C;IACxC,MAAME,MAAM,GAAGH,UAAU,CAACC,CAAD,CAAzB;IACA;AACR;AACA;AACA;IACQ;;IACAxB,QAAQ,CAAC2B,IAAT,CAAcD,MAAM,CAACE,MAAP,CAAc5B,QAA5B,EAPwC,CAQxC;;IACAI,SAAS,CAACuB,IAAV,CAAeD,MAAM,CAACE,MAAP,CAAcxB,SAA7B;EACH;;EAED,OAAO,IAAAyB,4BAAA,EAAqB;IACxB7B,QADwB;IAExBI,SAFwB;IAGxB0B,8BAA8B,EAAE;EAHR,CAArB,CAAP;AAKH,CAxDM"}
package/debugPlugins.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { GraphQLAfterQueryPlugin } from "./types";
2
- import { Context, ContextPlugin } from "@webiny/handler/types";
2
+ import { Context } from "@webiny/api/types";
3
+ import { ContextPlugin } from "@webiny/api";
3
4
  interface Log {
4
5
  method: string;
5
6
  args: any;
@@ -9,5 +10,5 @@ interface DebugContext extends Context {
9
10
  logs?: Log[];
10
11
  };
11
12
  }
12
- declare const _default: () => (ContextPlugin<DebugContext, Context, Context, Context, Context, Context, Context, Context, Context, Context> | GraphQLAfterQueryPlugin<DebugContext>)[];
13
+ declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
13
14
  export default _default;
package/debugPlugins.js CHANGED
@@ -7,27 +7,24 @@ exports.default = void 0;
7
7
 
8
8
  var _interceptConsole = require("./interceptConsole");
9
9
 
10
- var _default = () => [{
11
- type: "context",
10
+ var _api = require("@webiny/api");
12
11
 
13
- apply(context) {
14
- if (!context.debug) {
15
- context.debug = {};
16
- }
17
-
18
- if (!context.debug.logs) {
19
- context.debug.logs = [];
20
- }
12
+ var _default = () => [new _api.ContextPlugin(async context => {
13
+ if (!context.debug) {
14
+ context.debug = {};
15
+ }
21
16
 
22
- (0, _interceptConsole.interceptConsole)((method, args) => {
23
- context.debug.logs.push({
24
- method,
25
- args
26
- });
27
- });
17
+ if (!context.debug.logs) {
18
+ context.debug.logs = [];
28
19
  }
29
20
 
30
- }, {
21
+ (0, _interceptConsole.interceptConsole)((method, args) => {
22
+ context.debug.logs.push({
23
+ method,
24
+ args
25
+ });
26
+ });
27
+ }), {
31
28
  type: "graphql-after-query",
32
29
 
33
30
  apply({
@@ -1 +1 @@
1
- {"version":3,"names":["type","apply","context","debug","logs","interceptConsole","method","args","push","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context, ContextPlugin } from \"@webiny/handler/types\";\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 {\n type: \"context\",\n apply(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 } as ContextPlugin<DebugContext>,\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;;eAce,MAAM,CACjB;EACIA,IAAI,EAAE,SADV;;EAEIC,KAAK,CAACC,OAAD,EAAU;IACX,IAAI,CAACA,OAAO,CAACC,KAAb,EAAoB;MAChBD,OAAO,CAACC,KAAR,GAAgB,EAAhB;IACH;;IAED,IAAI,CAACD,OAAO,CAACC,KAAR,CAAcC,IAAnB,EAAyB;MACrBF,OAAO,CAACC,KAAR,CAAcC,IAAd,GAAqB,EAArB;IACH;;IAED,IAAAC,kCAAA,EAAiB,CAACC,MAAD,EAASC,IAAT,KAAkB;MAC9BL,OAAO,CAACC,KAAR,CAAcC,IAAf,CAA8BI,IAA9B,CAAmC;QAAEF,MAAF;QAAUC;MAAV,CAAnC;IACH,CAFD;EAGH;;AAdL,CADiB,EAiBjB;EACIP,IAAI,EAAE,qBADV;;EAEIC,KAAK,CAAC;IAAEQ,MAAF;IAAUP;EAAV,CAAD,EAAsB;IACvBO,MAAM,CAAC,YAAD,CAAN,GAAuB;MAAEC,OAAO,EAAE,CAAC,IAAIR,OAAO,CAACC,KAAR,CAAcC,IAAd,IAAsB,EAA1B,CAAD;IAAX,CAAvB;;IACA,IAAIF,OAAO,CAACC,KAAR,CAAcC,IAAlB,EAAwB;MACpBF,OAAO,CAACC,KAAR,CAAcC,IAAd,CAAmBO,MAAnB,GAA4B,CAA5B;IACH;EACJ;;AAPL,CAjBiB,C"}
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":";;;;;;;AAAA;;AAGA;;eAYe,MAAM,CACjB,IAAIA,kBAAJ,CAAgC,MAAMC,OAAN,IAAiB;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAb,EAAoB;IAChBD,OAAO,CAACC,KAAR,GAAgB,EAAhB;EACH;;EAED,IAAI,CAACD,OAAO,CAACC,KAAR,CAAcC,IAAnB,EAAyB;IACrBF,OAAO,CAACC,KAAR,CAAcC,IAAd,GAAqB,EAArB;EACH;;EAED,IAAAC,kCAAA,EAAiB,CAACC,MAAD,EAASC,IAAT,KAAkB;IAC9BL,OAAO,CAACC,KAAR,CAAcC,IAAf,CAA8BI,IAA9B,CAAmC;MAAEF,MAAF;MAAUC;IAAV,CAAnC;EACH,CAFD;AAGH,CAZD,CADiB,EAcjB;EACIE,IAAI,EAAE,qBADV;;EAEIC,KAAK,CAAC;IAAEC,MAAF;IAAUT;EAAV,CAAD,EAAsB;IACvBS,MAAM,CAAC,YAAD,CAAN,GAAuB;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAR,CAAcC,IAAd,IAAsB,EAA1B,CAAD;IAAX,CAAvB;;IACA,IAAIF,OAAO,CAACC,KAAR,CAAcC,IAAlB,EAAwB;MACpBF,OAAO,CAACC,KAAR,CAAcC,IAAd,CAAmBS,MAAnB,GAA4B,CAA5B;IACH;EACJ;;AAPL,CAdiB,C"}
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HandlerGraphQLOptions } from "./types";
2
- import { Context } from "@webiny/handler/types";
2
+ import { Context } from "@webiny/api/types";
3
3
  import { GraphQLFieldResolver } from "./types";
4
4
  /**
5
5
  * Can be anything.
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["options","createGraphQLHandler","pipe","fns","resolver","reduce","v","f","compose","reduceRight"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\nimport { Context } from \"@webiny/handler/types\";\nimport { GraphQLFieldResolver } from \"./types\";\n\n/**\n * Can be anything.\n * TODO: Figure out if required at all.\n */\ninterface Callable {\n (params: any): any;\n}\nexport * from \"./errors\";\nexport * from \"./responses\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n\nexport const pipe =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduce((v, f) => f(v), resolver);\n\nexport const compose =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduceRight((v, f) => f(v), resolver);\n"],"mappings":";;;;;;;;;;;;;AACA;;AAWA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C;;;;AAEjD,MAAME,IAAI,GACb,CAAiE,GAAGC,GAApE,KACCC,QAAD,IACID,GAAG,CAACE,MAAJ,CAAW,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAAtB,EAA2BF,QAA3B,CAHD;;;;AAKA,MAAMI,OAAO,GAChB,CAAiE,GAAGL,GAApE,KACCC,QAAD,IACID,GAAG,CAACM,WAAJ,CAAgB,CAACH,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAA3B,EAAgCF,QAAhC,CAHD"}
1
+ {"version":3,"names":["options","createGraphQLHandler","pipe","fns","resolver","reduce","v","f","compose","reduceRight"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\nimport { Context } from \"@webiny/api/types\";\nimport { GraphQLFieldResolver } from \"./types\";\n\n/**\n * Can be anything.\n * TODO: Figure out if required at all.\n */\ninterface Callable {\n (params: any): any;\n}\nexport * from \"./errors\";\nexport * from \"./responses\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n\nexport const pipe =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduce((v, f) => f(v), resolver);\n\nexport const compose =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduceRight((v, f) => f(v), resolver);\n"],"mappings":";;;;;;;;;;;;;AACA;;AAWA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C;;;;AAEjD,MAAME,IAAI,GACb,CAAiE,GAAGC,GAApE,KACCC,QAAD,IACID,GAAG,CAACE,MAAJ,CAAW,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAAtB,EAA2BF,QAA3B,CAHD;;;;AAKA,MAAMI,OAAO,GAChB,CAAiE,GAAGL,GAApE,KACCC,QAAD,IACID,GAAG,CAACM,WAAJ,CAAgB,CAACH,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAA3B,EAAgCF,QAAhC,CAHD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "5.30.0",
3
+ "version": "5.31.0-beta.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,13 +14,12 @@
14
14
  "Adrian Smijulj <adrian@webiny.com>"
15
15
  ],
16
16
  "dependencies": {
17
- "@babel/runtime": "7.18.6",
17
+ "@babel/runtime": "7.18.9",
18
18
  "@graphql-tools/schema": "7.1.5",
19
- "@webiny/error": "5.30.0",
20
- "@webiny/handler": "5.30.0",
21
- "@webiny/handler-http": "5.30.0",
22
- "@webiny/plugins": "5.30.0",
23
- "@webiny/utils": "5.30.0",
19
+ "@webiny/api": "5.31.0-beta.0",
20
+ "@webiny/error": "5.31.0-beta.0",
21
+ "@webiny/handler": "5.31.0-beta.0",
22
+ "@webiny/plugins": "5.31.0-beta.0",
24
23
  "boolean": "3.2.0",
25
24
  "graphql": "15.8.0",
26
25
  "graphql-scalars": "1.12.0",
@@ -30,9 +29,9 @@
30
29
  "@babel/cli": "^7.16.0",
31
30
  "@babel/core": "^7.16.0",
32
31
  "@babel/preset-env": "^7.16.4",
33
- "@webiny/cli": "^5.30.0",
34
- "@webiny/handler-args": "^5.30.0",
35
- "@webiny/project-utils": "^5.30.0",
32
+ "@webiny/cli": "^5.31.0-beta.0",
33
+ "@webiny/handler-aws": "^5.31.0-beta.0",
34
+ "@webiny/project-utils": "^5.31.0-beta.0",
36
35
  "jest": "^28.1.0",
37
36
  "jest-mock-console": "^1.0.0",
38
37
  "rimraf": "^3.0.2",
@@ -46,5 +45,5 @@
46
45
  "build": "yarn webiny run build",
47
46
  "watch": "yarn webiny run watch"
48
47
  },
49
- "gitHead": "3cadc5d26e565586b28772afbc18ae554ce7b782"
48
+ "gitHead": "dea7c56325ff140ef0e2d761f3e65708d46d401e"
50
49
  }
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
3
- import { Context } from "@webiny/handler/types";
3
+ import { Context } from "@webiny/api/types";
4
4
  export interface GraphQLSchemaPluginConfig<TContext> {
5
5
  typeDefs?: Types;
6
6
  resolvers?: Resolvers<TContext>;
@@ -1 +1 @@
1
- {"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/handler/types\";\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context> extends Plugin {\n public static override readonly type: string = \"graphql-schema\";\n private config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,mBAAN,SAAsDC,eAAtD,CAA6D;EAIhEC,WAAW,CAACC,MAAD,EAA8C;IACrD;IADqD;IAErD,KAAKA,MAAL,GAAcA,MAAd;EACH;;EAES,IAANC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,KAAKF,MAAL,CAAYE,QAAZ,IAAwB,EAD/B;MAEHC,SAAS,EAAE,KAAKH,MAAL,CAAYG;IAFpB,CAAP;EAIH;;AAd+D;;;8BAAvDN,mB,UACsC,gB"}
1
+ {"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context> extends Plugin {\n public static override readonly type: string = \"graphql-schema\";\n private config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,mBAAN,SAAsDC,eAAtD,CAA6D;EAIhEC,WAAW,CAACC,MAAD,EAA8C;IACrD;IADqD;IAErD,KAAKA,MAAL,GAAcA,MAAd;EACH;;EAES,IAANC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,KAAKF,MAAL,CAAYE,QAAZ,IAAwB,EAD/B;MAEHC,SAAS,EAAE,KAAKH,MAAL,CAAYG;IAFpB,CAAP;EAIH;;AAd+D;;;8BAAvDN,mB,UACsC,gB"}
@@ -1,5 +1,5 @@
1
1
  import { ExecutionResult, GraphQLSchema } from "graphql";
2
2
  import { GraphQLRequestBody } from "./types";
3
- import { Context } from "@webiny/handler/types";
3
+ import { Context } from "@webiny/api/types";
4
4
  declare const _default: (requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult[] | ExecutionResult>;
5
5
  export default _default;
@@ -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/handler/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,IADuB,EAEvBC,MAFuB,EAGvBC,OAHuB,KAItB;EACD,MAAM;IAAEC,KAAF;IAASC,SAAT;IAAoBC;EAApB,IAAsCL,IAA5C;EAEAE,OAAO,CAACI,OAAR,CACKC,MADL,CACsC,sBADtC,EAEKC,OAFL,CAEaC,EAAE,IAAIA,EAAE,CAACC,KAAH,CAAS;IAAEV,IAAF;IAAQC,MAAR;IAAgBC;EAAhB,CAAT,CAFnB;EAIA,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAA,EAAQX,MAAR,EAAgBE,KAAhB,EAAuB,EAAvB,EAA2BD,OAA3B,EAAoCE,SAApC,EAA+CC,aAA/C,CAArB;EAEAH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAAgD,qBAAhD,EAAuEC,OAAvE,CAA+EC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAH,CAAS;MAAEC,MAAF;MAAUX,IAAV;MAAgBC,MAAhB;MAAwBC;IAAxB,CAAT;EACH,CAFD;EAIA,OAAOS,MAAP;AACH,CAlBD;;eAoBe,OACXE,WADW,EAEXZ,MAFW,EAGXC,OAHW,KAIoC;EAC/C,IAAIY,KAAK,CAACC,OAAN,CAAcF,WAAd,MAA+B,IAAnC,EAAyC;IACrC,MAAMF,MAAyB,GAAG,EAAlC;;IACA,KAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAIH,WAAD,CAAsCI,MAA1D,EAAkED,CAAC,EAAnE,EAAuE;MACnEL,MAAM,CAACO,IAAP,CACI,MAAMnB,kBAAkB,CAAEc,WAAD,CAAsCG,CAAtC,CAAD,EAA2Cf,MAA3C,EAAmDC,OAAnD,CAD5B;IAGH;;IACD,OAAOS,MAAP;EACH;;EACD,OAAO,MAAMZ,kBAAkB,CAACc,WAAD,EAAoCZ,MAApC,EAA4CC,OAA5C,CAA/B;AACH,C"}
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,IADuB,EAEvBC,MAFuB,EAGvBC,OAHuB,KAItB;EACD,MAAM;IAAEC,KAAF;IAASC,SAAT;IAAoBC;EAApB,IAAsCL,IAA5C;EAEAE,OAAO,CAACI,OAAR,CACKC,MADL,CACsC,sBADtC,EAEKC,OAFL,CAEaC,EAAE,IAAIA,EAAE,CAACC,KAAH,CAAS;IAAEV,IAAF;IAAQC,MAAR;IAAgBC;EAAhB,CAAT,CAFnB;EAIA,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAA,EAAQX,MAAR,EAAgBE,KAAhB,EAAuB,EAAvB,EAA2BD,OAA3B,EAAoCE,SAApC,EAA+CC,aAA/C,CAArB;EAEAH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAAgD,qBAAhD,EAAuEC,OAAvE,CAA+EC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAH,CAAS;MAAEC,MAAF;MAAUX,IAAV;MAAgBC,MAAhB;MAAwBC;IAAxB,CAAT;EACH,CAFD;EAIA,OAAOS,MAAP;AACH,CAlBD;;eAoBe,OACXE,WADW,EAEXZ,MAFW,EAGXC,OAHW,KAIoC;EAC/C,IAAIY,KAAK,CAACC,OAAN,CAAcF,WAAd,MAA+B,IAAnC,EAAyC;IACrC,MAAMF,MAAyB,GAAG,EAAlC;;IACA,KAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAIH,WAAD,CAAsCI,MAA1D,EAAkED,CAAC,EAAnE,EAAuE;MACnEL,MAAM,CAACO,IAAP,CACI,MAAMnB,kBAAkB,CAAEc,WAAD,CAAsCG,CAAtC,CAAD,EAA2Cf,MAA3C,EAAmDC,OAAnD,CAD5B;IAGH;;IACD,OAAOS,MAAP;EACH;;EACD,OAAO,MAAMZ,kBAAkB,CAACc,WAAD,EAAoCZ,MAApC,EAA4CC,OAA5C,CAA/B;AACH,C"}
package/types.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
2
2
  import { Plugin } from "@webiny/plugins/types";
3
- import { Context } from "@webiny/handler/types";
3
+ import { Context } from "@webiny/api/types";
4
+ import { RouteMethodPath } from "@webiny/handler/types";
4
5
  export interface GraphQLScalarPlugin extends Plugin {
5
6
  type: "graphql-scalar";
6
7
  scalar: GraphQLScalarType;
7
8
  }
8
9
  export interface HandlerGraphQLOptions {
10
+ path?: RouteMethodPath;
9
11
  debug?: boolean | string;
10
12
  }
11
13
  export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | (() => string | Promise<string>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> };\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | (() => string | Promise<string>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> };\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":""}