@webiny/handler-graphql 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac

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.
Files changed (44) hide show
  1. package/builtInTypes/AnyScalar.js +0 -3
  2. package/builtInTypes/AnyScalar.js.map +1 -1
  3. package/builtInTypes/DateScalar.js +0 -7
  4. package/builtInTypes/DateScalar.js.map +1 -1
  5. package/builtInTypes/DateTimeScalar.js +0 -7
  6. package/builtInTypes/DateTimeScalar.js.map +1 -1
  7. package/builtInTypes/DateTimeZScalar.js +0 -13
  8. package/builtInTypes/DateTimeZScalar.js.map +1 -1
  9. package/builtInTypes/JsonScalar.js +0 -2
  10. package/builtInTypes/JsonScalar.js.map +1 -1
  11. package/builtInTypes/LongScalar.d.ts +2 -1
  12. package/builtInTypes/LongScalar.js +49 -4
  13. package/builtInTypes/LongScalar.js.map +1 -1
  14. package/builtInTypes/NumberScalar.js +0 -9
  15. package/builtInTypes/NumberScalar.js.map +1 -1
  16. package/builtInTypes/RefInputScalar.d.ts +1 -1
  17. package/builtInTypes/RefInputScalar.js +3 -14
  18. package/builtInTypes/RefInputScalar.js.map +1 -1
  19. package/builtInTypes/TimeScalar.js +0 -12
  20. package/builtInTypes/TimeScalar.js.map +1 -1
  21. package/builtInTypes/index.js +0 -18
  22. package/builtInTypes/index.js.map +1 -1
  23. package/createGraphQLHandler.d.ts +1 -1
  24. package/createGraphQLHandler.js +44 -20
  25. package/createGraphQLHandler.js.map +1 -1
  26. package/createGraphQLSchema.js +13 -16
  27. package/createGraphQLSchema.js.map +1 -1
  28. package/debugPlugins.js +0 -9
  29. package/debugPlugins.js.map +1 -1
  30. package/errors.js +0 -5
  31. package/errors.js.map +1 -1
  32. package/index.js +0 -10
  33. package/index.js.map +1 -1
  34. package/interceptConsole.js +4 -10
  35. package/interceptConsole.js.map +1 -1
  36. package/package.json +11 -10
  37. package/plugins/GraphQLSchemaPlugin.js +0 -7
  38. package/plugins/GraphQLSchemaPlugin.js.map +1 -1
  39. package/plugins/index.js +0 -2
  40. package/plugins/index.js.map +1 -1
  41. package/processRequestBody.js +6 -12
  42. package/processRequestBody.js.map +1 -1
  43. package/responses.js +4 -24
  44. package/responses.js.map +1 -1
@@ -1,32 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _boolean = require("boolean");
11
-
9
+ var _handler = require("@webiny/handler");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
12
11
  var _createGraphQLSchema = require("./createGraphQLSchema");
13
-
14
12
  var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
15
-
16
13
  var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
17
-
18
- var _handler = require("@webiny/handler");
19
-
20
14
  const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
21
15
 
22
- /**
23
- * TODO Until we figure out how to better convert incoming body, we will leave it as any.
24
- */
25
-
26
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
+ */
27
21
  return typeof body === "string" ? JSON.parse(body) : body;
28
22
  };
29
-
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
+ };
30
39
  var _default = (options = {}) => {
31
40
  let schema = undefined;
32
41
  const debug = (0, _boolean.boolean)(options.debug);
@@ -39,16 +48,32 @@ var _default = (options = {}) => {
39
48
  onOptions(path, async (_, reply) => {
40
49
  return reply.status(204).headers({
41
50
  "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
42
- }).send({});
51
+ }).send({}).hijack();
43
52
  });
44
53
  onPost(path, async (request, reply) => {
45
54
  if (!schema) {
46
- 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;
47
76
  }
48
-
49
- const body = createRequestBody(request.body);
50
- const result = await (0, _processRequestBody.default)(body, schema, context);
51
- return reply.status(200).send(result);
52
77
  });
53
78
  });
54
79
  route.name = "handler.graphql.route.default";
@@ -56,5 +81,4 @@ var _default = (options = {}) => {
56
81
  type: "wcp-telemetry-tracker"
57
82
  }, route];
58
83
  };
59
-
60
84
  exports.default = _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,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
+ {"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":"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"}
@@ -1,22 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createGraphQLSchema = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
-
14
10
  var _schema = require("@graphql-tools/schema");
15
-
16
11
  var _builtInTypes = require("./builtInTypes");
17
-
18
12
  const createGraphQLSchema = context => {
19
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.
20
17
  const typeDefs = [(0, _graphqlTag.default)`
21
18
  type Query
22
19
  type Mutation
@@ -29,6 +26,11 @@ const createGraphQLSchema = context => {
29
26
  scalar Date
30
27
  scalar DateTime
31
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
32
34
  `];
33
35
  const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
34
36
  acc[s.name] = s;
@@ -36,33 +38,28 @@ const createGraphQLSchema = context => {
36
38
  }, {})), {}, {
37
39
  JSON: _builtInTypes.JsonScalar,
38
40
  Long: _builtInTypes.LongScalar,
39
- RefInput: _builtInTypes.RefInput,
41
+ RefInput: _builtInTypes.RefInputScalar,
40
42
  Number: _builtInTypes.NumberScalar,
41
43
  Any: _builtInTypes.AnyScalar,
42
44
  DateTime: _builtInTypes.DateTimeScalar,
43
45
  Date: _builtInTypes.DateScalar,
44
46
  Time: _builtInTypes.TimeScalar
45
47
  })];
46
- const gqlPlugins = context.plugins.byType("graphql-schema");
47
-
48
- for (let i = 0; i < gqlPlugins.length; i++) {
49
- const plugin = gqlPlugins[i];
48
+ const plugins = context.plugins.byType("graphql-schema");
49
+ for (const plugin of plugins) {
50
50
  /**
51
51
  * TODO @ts-refactor
52
52
  * Figure out correct types on typeDefs and resolvers
53
53
  */
54
54
  // @ts-ignore
55
-
56
- typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
57
-
55
+ typeDefs.push(plugin.schema.typeDefs);
56
+ // @ts-ignore
58
57
  resolvers.push(plugin.schema.resolvers);
59
58
  }
60
-
61
59
  return (0, _schema.makeExecutableSchema)({
62
60
  typeDefs,
63
61
  resolvers,
64
62
  inheritResolversFromInterfaces: true
65
63
  });
66
64
  };
67
-
68
65
  exports.createGraphQLSchema = createGraphQLSchema;
@@ -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,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,6DAEPV,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,0BATE;IAUVC,GAAG,EAAEC,uBAVK;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","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/debugPlugins.js CHANGED
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _interceptConsole = require("./interceptConsole");
9
-
10
8
  var _api = require("@webiny/api");
11
-
12
9
  var _default = () => [new _api.ContextPlugin(async context => {
13
10
  if (!context.debug) {
14
11
  context.debug = {};
15
12
  }
16
-
17
13
  if (!context.debug.logs) {
18
14
  context.debug.logs = [];
19
15
  }
20
-
21
16
  (0, _interceptConsole.interceptConsole)((method, args) => {
22
17
  context.debug.logs.push({
23
18
  method,
@@ -26,7 +21,6 @@ var _default = () => [new _api.ContextPlugin(async context => {
26
21
  });
27
22
  }), {
28
23
  type: "graphql-after-query",
29
-
30
24
  apply({
31
25
  result,
32
26
  context
@@ -34,12 +28,9 @@ var _default = () => [new _api.ContextPlugin(async context => {
34
28
  result["extensions"] = {
35
29
  console: [...(context.debug.logs || [])]
36
30
  };
37
-
38
31
  if (context.debug.logs) {
39
32
  context.debug.logs.length = 0;
40
33
  }
41
34
  }
42
-
43
35
  }];
44
-
45
36
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;;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"}
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;AAA4C,eAY7B,MAAM,CACjB,IAAIA,kBAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEA,IAAAC,kCAAgB,EAAC,CAACC,MAAM,EAAEC,IAAI,KAAK;IAC9BL,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWI,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAK,CAAC;IAAEC,MAAM;IAAET;EAAQ,CAAC,EAAE;IACvBS,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACS,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ;AAAA"}
package/errors.js CHANGED
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.NotFoundError = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  class NotFoundError extends _error.default {
13
10
  constructor(message = "Not found.") {
14
11
  super(message, "NOT_FOUND");
15
12
  }
16
-
17
13
  }
18
-
19
14
  exports.NotFoundError = NotFoundError;
package/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEO,MAAMA,aAAN,SAA4BC,cAA5B,CAAwC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAX,EAAyB;IAChC,MAAMA,OAAN,EAAe,WAAf;EACH;;AAH0C"}
1
+ {"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAAC"}
package/index.js CHANGED
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  var _exportNames = {};
9
8
  exports.default = void 0;
10
-
11
9
  var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
12
-
13
10
  var _errors = require("./errors");
14
-
15
11
  Object.keys(_errors).forEach(function (key) {
16
12
  if (key === "default" || key === "__esModule") return;
17
13
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -23,9 +19,7 @@ Object.keys(_errors).forEach(function (key) {
23
19
  }
24
20
  });
25
21
  });
26
-
27
22
  var _responses = require("./responses");
28
-
29
23
  Object.keys(_responses).forEach(function (key) {
30
24
  if (key === "default" || key === "__esModule") return;
31
25
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -37,9 +31,7 @@ Object.keys(_responses).forEach(function (key) {
37
31
  }
38
32
  });
39
33
  });
40
-
41
34
  var _plugins = require("./plugins");
42
-
43
35
  Object.keys(_plugins).forEach(function (key) {
44
36
  if (key === "default" || key === "__esModule") return;
45
37
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -51,7 +43,5 @@ Object.keys(_plugins).forEach(function (key) {
51
43
  }
52
44
  });
53
45
  });
54
-
55
46
  var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
56
-
57
47
  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;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C"}
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"}
@@ -7,37 +7,31 @@ exports.interceptConsole = void 0;
7
7
  const consoleMethods = ["assert", "debug", "dir", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "table", "warn"];
8
8
  const originalMethods = {};
9
9
  const skipOriginal = ["table"];
10
-
11
10
  const restoreOriginalMethods = () => {
12
11
  for (const method of consoleMethods) {
13
12
  // @ts-ignore
14
13
  console[method] = originalMethods[method];
15
14
  }
16
15
  };
17
-
18
16
  const interceptConsole = callback => {
19
17
  // @ts-ignore
20
18
  if (console["__WEBINY__"] === true) {
21
19
  restoreOriginalMethods();
22
- } // @ts-ignore
23
-
20
+ }
24
21
 
22
+ // @ts-ignore
25
23
  console["__WEBINY__"] = true;
26
-
27
24
  for (const method of consoleMethods) {
28
25
  // @ts-ignore
29
- originalMethods[method] = console[method]; // @ts-ignore
30
-
26
+ originalMethods[method] = console[method];
27
+ // @ts-ignore
31
28
  console[method] = (...args) => {
32
29
  callback(method, args);
33
-
34
30
  if (skipOriginal.includes(method)) {
35
31
  return;
36
32
  }
37
-
38
33
  originalMethods[method](...args);
39
34
  };
40
35
  }
41
36
  };
42
-
43
37
  exports.interceptConsole = interceptConsole;
@@ -1 +1 @@
1
- {"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-ignore\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QADmB,EAEnB,OAFmB,EAGnB,KAHmB,EAInB,OAJmB,EAKnB,OALmB,EAMnB,gBANmB,EAOnB,UAPmB,EAQnB,MARmB,EASnB,KATmB,EAUnB,OAVmB,EAWnB,MAXmB,CAAvB;AAcA,MAAMC,eAAoC,GAAG,EAA7C;AACA,MAAMC,YAAsB,GAAG,CAAC,OAAD,CAA/B;;AAEA,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAK,OAAO,CAACD,MAAD,CAAP,GAAkBH,eAAe,CAACG,MAAD,CAAjC;EACH;AACJ,CALD;;AAWO,MAAME,gBAAgB,GAAIC,QAAD,IAAwC;EACpE;EACA,IAAIF,OAAO,CAAC,YAAD,CAAP,KAA0B,IAA9B,EAAoC;IAChCF,sBAAsB;EACzB,CAJmE,CAMpE;;;EACAE,OAAO,CAAC,YAAD,CAAP,GAAwB,IAAxB;;EAEA,KAAK,MAAMD,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAC,eAAe,CAACG,MAAD,CAAf,GAA0BC,OAAO,CAACD,MAAD,CAAjC,CAFiC,CAGjC;;IACAC,OAAO,CAACD,MAAD,CAAP,GAAkB,CAAC,GAAGI,IAAJ,KAAa;MAC3BD,QAAQ,CAACH,MAAD,EAASI,IAAT,CAAR;;MACA,IAAIN,YAAY,CAACO,QAAb,CAAsBL,MAAtB,CAAJ,EAAmC;QAC/B;MACH;;MACDH,eAAe,CAACG,MAAD,CAAf,CAAwB,GAAGI,IAA3B;IACH,CAND;EAOH;AACJ,CArBM"}
1
+ {"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-ignore\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,CACT;AAED,MAAMC,eAAoC,GAAG,CAAC,CAAC;AAC/C,MAAMC,YAAsB,GAAG,CAAC,OAAO,CAAC;AAExC,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAK,OAAO,CAACD,MAAM,CAAC,GAAGH,eAAe,CAACG,MAAM,CAAC;EAC7C;AACJ,CAAC;AAMM,MAAME,gBAAgB,GAAIC,QAAkC,IAAK;EACpE;EACA,IAAIF,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;IAChCF,sBAAsB,EAAE;EAC5B;;EAEA;EACAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;EAE5B,KAAK,MAAMD,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAC,eAAe,CAACG,MAAM,CAAC,GAAGC,OAAO,CAACD,MAAM,CAAC;IACzC;IACAC,OAAO,CAACD,MAAM,CAAC,GAAG,CAAC,GAAGI,IAAI,KAAK;MAC3BD,QAAQ,CAACH,MAAM,EAAEI,IAAI,CAAC;MACtB,IAAIN,YAAY,CAACO,QAAQ,CAACL,MAAM,CAAC,EAAE;QAC/B;MACJ;MACAH,eAAe,CAACG,MAAM,CAAC,CAAC,GAAGI,IAAI,CAAC;IACpC,CAAC;EACL;AACJ,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "0.0.0-unstable.40876133bb",
3
+ "version": "0.0.0-unstable.496cf268ac",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,12 +14,12 @@
14
14
  "Adrian Smijulj <adrian@webiny.com>"
15
15
  ],
16
16
  "dependencies": {
17
- "@babel/runtime": "7.19.0",
17
+ "@babel/runtime": "7.20.13",
18
18
  "@graphql-tools/schema": "7.1.5",
19
- "@webiny/api": "0.0.0-unstable.40876133bb",
20
- "@webiny/error": "0.0.0-unstable.40876133bb",
21
- "@webiny/handler": "0.0.0-unstable.40876133bb",
22
- "@webiny/plugins": "0.0.0-unstable.40876133bb",
19
+ "@webiny/api": "0.0.0-unstable.496cf268ac",
20
+ "@webiny/error": "0.0.0-unstable.496cf268ac",
21
+ "@webiny/handler": "0.0.0-unstable.496cf268ac",
22
+ "@webiny/plugins": "0.0.0-unstable.496cf268ac",
23
23
  "boolean": "3.2.0",
24
24
  "graphql": "15.8.0",
25
25
  "graphql-scalars": "1.12.0",
@@ -29,12 +29,13 @@
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.40876133bb",
33
- "@webiny/handler-aws": "^0.0.0-unstable.40876133bb",
34
- "@webiny/project-utils": "^0.0.0-unstable.40876133bb",
32
+ "@webiny/cli": "^0.0.0-unstable.496cf268ac",
33
+ "@webiny/handler-aws": "^0.0.0-unstable.496cf268ac",
34
+ "@webiny/project-utils": "^0.0.0-unstable.496cf268ac",
35
35
  "jest": "^28.1.0",
36
36
  "jest-mock-console": "^1.0.0",
37
37
  "rimraf": "^3.0.2",
38
+ "ttypescript": "^1.5.13",
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": "f33811072795d25c5787ae39808e75e3312fb247"
49
+ "gitHead": "496cf268acd5b092c860b62d75c7d765c9472043"
49
50
  }
@@ -1,31 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.GraphQLSchemaPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class GraphQLSchemaPlugin extends _plugins.Plugin {
15
11
  constructor(config) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "config", void 0);
18
14
  this.config = config;
19
15
  }
20
-
21
16
  get schema() {
22
17
  return {
23
18
  typeDefs: this.config.typeDefs || "",
24
19
  resolvers: this.config.resolvers
25
20
  };
26
21
  }
27
-
28
22
  }
29
-
30
23
  exports.GraphQLSchemaPlugin = GraphQLSchemaPlugin;
31
24
  (0, _defineProperty2.default)(GraphQLSchemaPlugin, "type", "graphql-schema");
@@ -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/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
+ {"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,mBAAmB,SAA6BC,eAAM,CAAC;EAIhEC,WAAW,CAACC,MAA2C,EAAE;IACrD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,IAAIC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,IAAI,CAACF,MAAM,CAACE,QAAQ,IAAI,EAAE;MACpCC,SAAS,EAAE,IAAI,CAACH,MAAM,CAACG;IAC3B,CAAC;EACL;AACJ;AAAC;AAAA,8BAfYN,mBAAmB,UACmB,gBAAgB"}
package/plugins/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _GraphQLSchemaPlugin = require("./GraphQLSchemaPlugin");
8
-
9
7
  Object.keys(_GraphQLSchemaPlugin).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _GraphQLSchemaPlugin[key]) return;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _graphql = require("graphql");
9
-
10
8
  const processRequestBody = async (body, schema, context) => {
11
9
  const {
12
10
  query,
@@ -29,19 +27,15 @@ const processRequestBody = async (body, schema, context) => {
29
27
  });
30
28
  return result;
31
29
  };
32
-
33
30
  var _default = async (requestBody, schema, context) => {
34
- if (Array.isArray(requestBody) === true) {
35
- const result = [];
36
-
37
- for (let i = 0; i < requestBody.length; i++) {
38
- 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);
39
36
  }
40
-
41
- return result;
37
+ return results;
42
38
  }
43
-
44
39
  return await processRequestBody(requestBody, schema, context);
45
40
  };
46
-
47
41
  exports.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/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"}
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"}