@webiny/handler-graphql 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.8feaff8c32

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 (48) hide show
  1. package/builtInTypes/AnyScalar.d.ts +1 -1
  2. package/builtInTypes/AnyScalar.js +3 -6
  3. package/builtInTypes/AnyScalar.js.map +1 -1
  4. package/builtInTypes/DateScalar.js +3 -14
  5. package/builtInTypes/DateScalar.js.map +1 -1
  6. package/builtInTypes/DateTimeScalar.js +3 -14
  7. package/builtInTypes/DateTimeScalar.js.map +1 -1
  8. package/builtInTypes/DateTimeZScalar.js +1 -14
  9. package/builtInTypes/DateTimeZScalar.js.map +1 -1
  10. package/builtInTypes/JsonScalar.js +0 -2
  11. package/builtInTypes/JsonScalar.js.map +1 -1
  12. package/builtInTypes/LongScalar.d.ts +2 -1
  13. package/builtInTypes/LongScalar.js +49 -4
  14. package/builtInTypes/LongScalar.js.map +1 -1
  15. package/builtInTypes/NumberScalar.d.ts +1 -1
  16. package/builtInTypes/NumberScalar.js +10 -15
  17. package/builtInTypes/NumberScalar.js.map +1 -1
  18. package/builtInTypes/RefInputScalar.d.ts +1 -1
  19. package/builtInTypes/RefInputScalar.js +3 -14
  20. package/builtInTypes/RefInputScalar.js.map +1 -1
  21. package/builtInTypes/TimeScalar.js +1 -13
  22. package/builtInTypes/TimeScalar.js.map +1 -1
  23. package/builtInTypes/index.js +0 -18
  24. package/builtInTypes/index.js.map +1 -1
  25. package/createGraphQLHandler.d.ts +1 -1
  26. package/createGraphQLHandler.js +55 -22
  27. package/createGraphQLHandler.js.map +1 -1
  28. package/createGraphQLSchema.d.ts +2 -0
  29. package/createGraphQLSchema.js +23 -26
  30. package/createGraphQLSchema.js.map +1 -1
  31. package/debugPlugins.js +0 -9
  32. package/debugPlugins.js.map +1 -1
  33. package/errors.js +1 -6
  34. package/errors.js.map +1 -1
  35. package/index.d.ts +2 -11
  36. package/index.js +23 -21
  37. package/index.js.map +1 -1
  38. package/interceptConsole.js +4 -10
  39. package/interceptConsole.js.map +1 -1
  40. package/package.json +17 -16
  41. package/plugins/GraphQLSchemaPlugin.js +1 -8
  42. package/plugins/GraphQLSchemaPlugin.js.map +1 -1
  43. package/plugins/index.js +0 -2
  44. package/plugins/index.js.map +1 -1
  45. package/processRequestBody.js +6 -12
  46. package/processRequestBody.js.map +1 -1
  47. package/responses.js +5 -25
  48. package/responses.js.map +1 -1
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _AnyScalar = require("./AnyScalar");
8
-
9
7
  Object.keys(_AnyScalar).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _AnyScalar[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_AnyScalar).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _DateScalar = require("./DateScalar");
21
-
22
18
  Object.keys(_DateScalar).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _DateScalar[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_DateScalar).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _DateTimeScalar = require("./DateTimeScalar");
34
-
35
29
  Object.keys(_DateTimeScalar).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _DateTimeScalar[key]) return;
@@ -42,9 +36,7 @@ Object.keys(_DateTimeScalar).forEach(function (key) {
42
36
  }
43
37
  });
44
38
  });
45
-
46
39
  var _DateTimeZScalar = require("./DateTimeZScalar");
47
-
48
40
  Object.keys(_DateTimeZScalar).forEach(function (key) {
49
41
  if (key === "default" || key === "__esModule") return;
50
42
  if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
@@ -55,9 +47,7 @@ Object.keys(_DateTimeZScalar).forEach(function (key) {
55
47
  }
56
48
  });
57
49
  });
58
-
59
50
  var _JsonScalar = require("./JsonScalar");
60
-
61
51
  Object.keys(_JsonScalar).forEach(function (key) {
62
52
  if (key === "default" || key === "__esModule") return;
63
53
  if (key in exports && exports[key] === _JsonScalar[key]) return;
@@ -68,9 +58,7 @@ Object.keys(_JsonScalar).forEach(function (key) {
68
58
  }
69
59
  });
70
60
  });
71
-
72
61
  var _LongScalar = require("./LongScalar");
73
-
74
62
  Object.keys(_LongScalar).forEach(function (key) {
75
63
  if (key === "default" || key === "__esModule") return;
76
64
  if (key in exports && exports[key] === _LongScalar[key]) return;
@@ -81,9 +69,7 @@ Object.keys(_LongScalar).forEach(function (key) {
81
69
  }
82
70
  });
83
71
  });
84
-
85
72
  var _NumberScalar = require("./NumberScalar");
86
-
87
73
  Object.keys(_NumberScalar).forEach(function (key) {
88
74
  if (key === "default" || key === "__esModule") return;
89
75
  if (key in exports && exports[key] === _NumberScalar[key]) return;
@@ -94,9 +80,7 @@ Object.keys(_NumberScalar).forEach(function (key) {
94
80
  }
95
81
  });
96
82
  });
97
-
98
83
  var _RefInputScalar = require("./RefInputScalar");
99
-
100
84
  Object.keys(_RefInputScalar).forEach(function (key) {
101
85
  if (key === "default" || key === "__esModule") return;
102
86
  if (key in exports && exports[key] === _RefInputScalar[key]) return;
@@ -107,9 +91,7 @@ Object.keys(_RefInputScalar).forEach(function (key) {
107
91
  }
108
92
  });
109
93
  });
110
-
111
94
  var _TimeScalar = require("./TimeScalar");
112
-
113
95
  Object.keys(_TimeScalar).forEach(function (key) {
114
96
  if (key === "default" || key === "__esModule") return;
115
97
  if (key in exports && exports[key] === _TimeScalar[key]) return;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":["_AnyScalar","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_DateScalar","_DateTimeScalar","_DateTimeZScalar","_JsonScalar","_LongScalar","_NumberScalar","_RefInputScalar","_TimeScalar"],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,UAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,UAA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,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAW,eAAA,CAAAX,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAO,eAAA,CAAAX,GAAA;IAAA;EAAA;AAAA;AACA,IAAAY,WAAA,GAAAhB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAc,WAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAY,WAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,WAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA"}
@@ -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;
@@ -1,34 +1,50 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
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
-
16
+ const createCacheKey = context => {
17
+ const plugins = (0, _createGraphQLSchema.getSchemaPlugins)(context);
18
+ // TODO: in the near future, we have to assign a fixed name to every GraphQLSchema plugin,
19
+ // to be able to create a reliable cache key.
20
+ return plugins.length.toString();
21
+ };
26
22
  const createRequestBody = body => {
23
+ /**
24
+ * We are trusting that the body payload is correct.
25
+ * The `processRequestBody` will fail if it is not.
26
+ */
27
27
  return typeof body === "string" ? JSON.parse(body) : body;
28
28
  };
29
-
29
+ const formatErrorPayload = error => {
30
+ if (error instanceof _error.default) {
31
+ return JSON.stringify({
32
+ type: "CoreGraphQLWebinyError",
33
+ message: error.message,
34
+ code: error.code,
35
+ data: error.data
36
+ });
37
+ }
38
+ return JSON.stringify({
39
+ type: "Error",
40
+ name: error.name,
41
+ message: error.message,
42
+ stack: error.stack
43
+ });
44
+ };
30
45
  var _default = (options = {}) => {
31
46
  let schema = undefined;
47
+ let cacheKey = undefined;
32
48
  const debug = (0, _boolean.boolean)(options.debug);
33
49
  const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
34
50
  const route = new _handler.RoutePlugin(async ({
@@ -39,16 +55,34 @@ var _default = (options = {}) => {
39
55
  onOptions(path, async (_, reply) => {
40
56
  return reply.status(204).headers({
41
57
  "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
42
- }).send({});
58
+ }).send({}).hijack();
43
59
  });
44
60
  onPost(path, async (request, reply) => {
45
- if (!schema) {
46
- schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
61
+ const contextCacheKey = createCacheKey(context);
62
+ if (!schema || cacheKey !== contextCacheKey) {
63
+ try {
64
+ schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
65
+ cacheKey = contextCacheKey;
66
+ } catch (ex) {
67
+ return reply.code(500).send(formatErrorPayload(ex));
68
+ }
69
+ }
70
+ let body;
71
+ try {
72
+ body = createRequestBody(request.body);
73
+ } catch (ex) {
74
+ console.error(`Error while creating the body request.`);
75
+ console.error(formatErrorPayload(ex));
76
+ throw ex;
77
+ }
78
+ try {
79
+ const result = await (0, _processRequestBody.default)(body, schema, context);
80
+ return reply.status(200).send(result);
81
+ } catch (ex) {
82
+ console.error(`Error while processing the body request.`);
83
+ console.error(formatErrorPayload(ex));
84
+ throw ex;
47
85
  }
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
86
  });
53
87
  });
54
88
  route.name = "handler.graphql.route.default";
@@ -56,5 +90,4 @@ var _default = (options = {}) => {
56
90
  type: "wcp-telemetry-tracker"
57
91
  }, route];
58
92
  };
59
-
60
93
  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":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","length","toString","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","code","data","name","stack","_default","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","debugPlugins","exports","default"],"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, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\nimport { Context } from \"@webiny/handler\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every GraphQLSchema plugin,\n // to be able to create a reliable cache key.\n return plugins.length.toString();\n};\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 let cacheKey: string | 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 const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\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,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,mBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAGA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;EACA,OAAOC,OAAO,CAACE,MAAM,CAACC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAMC,iBAAiB,GAAIC,IAAa,IAAgD;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAED,MAAMG,kBAAkB,GAAIC,KAAY,IAAa;EACjD,IAAIA,KAAK,YAAYC,cAAW,EAAE;IAC9B,OAAOJ,IAAI,CAACK,SAAS,CAAC;MAClBC,IAAI,EAAE,wBAAwB;MAC9BC,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,IAAI,EAAEL,KAAK,CAACK,IAAI;MAChBC,IAAI,EAAEN,KAAK,CAACM;IAChB,CAAC,CAAC;EACN;EAEA,OAAOT,IAAI,CAACK,SAAS,CAAC;IAClBC,IAAI,EAAE,OAAO;IACbI,IAAI,EAAEP,KAAK,CAACO,IAAI;IAChBH,OAAO,EAAEJ,KAAK,CAACI,OAAO;IACtBI,KAAK,EAAER,KAAK,CAACQ;EACjB,CAAC,CAAC;AACN,CAAC;AAAC,IAAA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AAC/B,KAAK,CAAE,wCAAuC,CAAC;QACvD+B,OAAO,CAAC/B,KAAK,CAACD,kBAAkB,CAAC+B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;MACA,IAAI;QACA,MAAME,MAAM,GAAG,MAAM,IAAAC,2BAAkB,EAACrC,IAAI,EAAEe,MAAM,EAAErB,OAAO,CAAC;QAC9D,OAAOgC,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC/B,KAAK,CAAE,0CAAyC,CAAC;QACzD+B,OAAO,CAAC/B,KAAK,CAACD,kBAAkB,CAAC+B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFb,KAAK,CAACV,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIO,KAAK,GAAG,IAAAoB,qBAAY,EAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACI/B,IAAI,EAAE;EACV,CAAC,EACDc,KAAK,CACR;AACL,CAAC;AAAAkB,OAAA,CAAAC,OAAA,GAAA3B,QAAA"}
@@ -1,2 +1,4 @@
1
+ import { GraphQLSchemaPlugin } from "./types";
1
2
  import { Context } from "@webiny/api/types";
3
+ export declare const getSchemaPlugins: (context: Context) => GraphQLSchemaPlugin<Context>[];
2
4
  export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
@@ -1,26 +1,23 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.createGraphQLSchema = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
7
+ exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
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
- 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; }
19
-
20
- 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; }
21
-
12
+ const getSchemaPlugins = context => {
13
+ return context.plugins.byType("graphql-schema");
14
+ };
15
+ exports.getSchemaPlugins = getSchemaPlugins;
22
16
  const createGraphQLSchema = context => {
23
17
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
18
+
19
+ // TODO: once the API packages more closed, we'll have the opportunity
20
+ // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
24
21
  const typeDefs = [(0, _graphqlTag.default)`
25
22
  type Query
26
23
  type Mutation
@@ -33,40 +30,40 @@ const createGraphQLSchema = context => {
33
30
  scalar Date
34
31
  scalar DateTime
35
32
  scalar Time
33
+
34
+ # This directive doesn't do anything on the GraphQL resolution level. It just serves
35
+ # as a way to tell the Prerendering Service whether the GraphQL query needs to be
36
+ # cached or not.
37
+ directive @ps(cache: Boolean) on QUERY
36
38
  `];
37
- const resolvers = [_objectSpread(_objectSpread({}, scalars.reduce((acc, s) => {
39
+ const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
38
40
  acc[s.name] = s;
39
41
  return acc;
40
42
  }, {})), {}, {
41
43
  JSON: _builtInTypes.JsonScalar,
42
44
  Long: _builtInTypes.LongScalar,
43
- RefInput: _builtInTypes.RefInput,
44
- Number: _builtInTypes.Number,
45
- Any: _builtInTypes.Any,
45
+ RefInput: _builtInTypes.RefInputScalar,
46
+ Number: _builtInTypes.NumberScalar,
47
+ Any: _builtInTypes.AnyScalar,
46
48
  DateTime: _builtInTypes.DateTimeScalar,
47
49
  Date: _builtInTypes.DateScalar,
48
50
  Time: _builtInTypes.TimeScalar
49
51
  })];
50
- const gqlPlugins = context.plugins.byType("graphql-schema");
51
-
52
- for (let i = 0; i < gqlPlugins.length; i++) {
53
- const plugin = gqlPlugins[i];
52
+ const plugins = getSchemaPlugins(context);
53
+ for (const plugin of plugins) {
54
54
  /**
55
55
  * TODO @ts-refactor
56
56
  * Figure out correct types on typeDefs and resolvers
57
57
  */
58
58
  // @ts-ignore
59
-
60
- typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
61
-
59
+ typeDefs.push(plugin.schema.typeDefs);
60
+ // @ts-ignore
62
61
  resolvers.push(plugin.schema.resolvers);
63
62
  }
64
-
65
63
  return (0, _schema.makeExecutableSchema)({
66
64
  typeDefs,
67
65
  resolvers,
68
66
  inheritResolversFromInterfaces: true
69
67
  });
70
68
  };
71
-
72
69
  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 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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graphqlTag","_interopRequireDefault","require","_schema","_builtInTypes","getSchemaPlugins","context","plugins","byType","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","_objectSpread2","default","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 getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n};\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 = getSchemaPlugins(context);\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,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AAYO,MAAMG,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAEK,MAAMK,mBAAmB,GAAIJ,OAAgB,IAAK;EACrD,MAAMK,OAAO,GAAGL,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CI,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAG,CAAC;AACZ;AACA;AACA,cAAcL,OAAO,CAACC,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,KAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAEPV,OAAO,CAACW,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;IAC7DD,GAAG,CAACC,CAAC,CAACP,IAAI,CAAC,GAAGO,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,MAAMjC,OAAO,GAAGF,gBAAgB,CAACC,OAAO,CAAC;EACzC,KAAK,MAAMmC,MAAM,IAAIlC,OAAO,EAAE;IAC1B;AACR;AACA;AACA;IACQ;IACAQ,QAAQ,CAAC2B,IAAI,CAACD,MAAM,CAACE,MAAM,CAAC5B,QAAQ,CAAC;IACrC;IACAI,SAAS,CAACuB,IAAI,CAACD,MAAM,CAACE,MAAM,CAACxB,SAAS,CAAC;EAC3C;EAEA,OAAO,IAAAyB,4BAAoB,EAAC;IACxB7B,QAAQ;IACRI,SAAS;IACT0B,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAACpC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA"}
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":["_interceptConsole","require","_api","_default","ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length","exports","default"],"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,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAD,OAAA;AAA4C,IAAAE,QAAA,GAY7BA,CAAA,KAAM,CACjB,IAAIC,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,KAAKA,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;AAAAC,OAAA,CAAAC,OAAA,GAAAf,QAAA"}
package/errors.js CHANGED
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
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":["_error","_interopRequireDefault","require","NotFoundError","WebinyError","constructor","message","exports"],"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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAWA,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAACC,OAAA,CAAAJ,aAAA,GAAAA,aAAA"}
package/index.d.ts CHANGED
@@ -1,16 +1,7 @@
1
1
  import { HandlerGraphQLOptions } from "./types";
2
- import { Context } from "@webiny/api/types";
3
- import { GraphQLFieldResolver } from "./types";
4
- /**
5
- * Can be anything.
6
- * TODO: Figure out if required at all.
7
- */
8
- interface Callable {
9
- (params: any): any;
10
- }
11
2
  export * from "./errors";
12
3
  export * from "./responses";
4
+ export * from "./plugins";
5
+ export { default as processRequestBody } from "./processRequestBody";
13
6
  declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
14
7
  export default _default;
15
- export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
16
- export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
package/index.js CHANGED
@@ -1,20 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  var _exportNames = {
9
- pipe: true,
10
- compose: true
8
+ processRequestBody: true
11
9
  };
12
- exports.pipe = exports.default = exports.compose = void 0;
13
-
10
+ exports.default = void 0;
11
+ Object.defineProperty(exports, "processRequestBody", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _processRequestBody.default;
15
+ }
16
+ });
14
17
  var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
15
-
16
18
  var _errors = require("./errors");
17
-
18
19
  Object.keys(_errors).forEach(function (key) {
19
20
  if (key === "default" || key === "__esModule") return;
20
21
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -26,9 +27,7 @@ Object.keys(_errors).forEach(function (key) {
26
27
  }
27
28
  });
28
29
  });
29
-
30
30
  var _responses = require("./responses");
31
-
32
31
  Object.keys(_responses).forEach(function (key) {
33
32
  if (key === "default" || key === "__esModule") return;
34
33
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -40,15 +39,18 @@ Object.keys(_responses).forEach(function (key) {
40
39
  }
41
40
  });
42
41
  });
43
-
42
+ var _plugins = require("./plugins");
43
+ Object.keys(_plugins).forEach(function (key) {
44
+ if (key === "default" || key === "__esModule") return;
45
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
46
+ if (key in exports && exports[key] === _plugins[key]) return;
47
+ Object.defineProperty(exports, key, {
48
+ enumerable: true,
49
+ get: function () {
50
+ return _plugins[key];
51
+ }
52
+ });
53
+ });
54
+ var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
44
55
  var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
45
-
46
- exports.default = _default;
47
-
48
- const pipe = (...fns) => resolver => fns.reduce((v, f) => f(v), resolver);
49
-
50
- exports.pipe = pipe;
51
-
52
- const compose = (...fns) => resolver => fns.reduceRight((v, f) => f(v), resolver);
53
-
54
- exports.compose = compose;
56
+ exports.default = _default;
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/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"}
1
+ {"version":3,"names":["_createGraphQLHandler","_interopRequireDefault","require","_errors","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_responses","_plugins","_processRequestBody","_default","options","createGraphQLHandler","default"],"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,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,OAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,OAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,UAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,QAAA,GAAAf,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAY,QAAA,EAAAX,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAU,QAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,QAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,mBAAA,GAAAjB,sBAAA,CAAAC,OAAA;AAAqE,IAAAiB,QAAA,GAEtDA,CAACC,OAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,IAAAC,6BAAoB,EAACD,OAAO,CAAC,CAAC;AAAAR,OAAA,CAAAU,OAAA,GAAAH,QAAA"}
@@ -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;