@webiny/handler-graphql 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f

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 (69) hide show
  1. package/ResolverDecoration.d.ts +6 -0
  2. package/ResolverDecoration.js +26 -0
  3. package/ResolverDecoration.js.map +1 -0
  4. package/builtInTypes/AnyScalar.d.ts +1 -1
  5. package/builtInTypes/AnyScalar.js +4 -6
  6. package/builtInTypes/AnyScalar.js.map +1 -0
  7. package/builtInTypes/DateScalar.js +7 -18
  8. package/builtInTypes/DateScalar.js.map +1 -0
  9. package/builtInTypes/DateTimeScalar.js +5 -16
  10. package/builtInTypes/DateTimeScalar.js.map +1 -0
  11. package/builtInTypes/DateTimeZScalar.js +4 -16
  12. package/builtInTypes/DateTimeZScalar.js.map +1 -0
  13. package/builtInTypes/JsonScalar.js +2 -3
  14. package/builtInTypes/JsonScalar.js.map +1 -0
  15. package/builtInTypes/LongScalar.d.ts +2 -1
  16. package/builtInTypes/LongScalar.js +49 -4
  17. package/builtInTypes/LongScalar.js.map +1 -0
  18. package/builtInTypes/NumberScalar.d.ts +1 -1
  19. package/builtInTypes/NumberScalar.js +10 -15
  20. package/builtInTypes/NumberScalar.js.map +1 -0
  21. package/builtInTypes/RefInputScalar.d.ts +1 -1
  22. package/builtInTypes/RefInputScalar.js +34 -23
  23. package/builtInTypes/RefInputScalar.js.map +1 -0
  24. package/builtInTypes/TimeScalar.js +4 -15
  25. package/builtInTypes/TimeScalar.js.map +1 -0
  26. package/builtInTypes/index.js +3 -19
  27. package/builtInTypes/index.js.map +1 -0
  28. package/createGraphQLHandler.d.ts +3 -3
  29. package/createGraphQLHandler.js +90 -57
  30. package/createGraphQLHandler.js.map +1 -0
  31. package/createGraphQLSchema.d.ts +4 -3
  32. package/createGraphQLSchema.js +58 -30
  33. package/createGraphQLSchema.js.map +1 -0
  34. package/createResolverDecorator.d.ts +2 -0
  35. package/createResolverDecorator.js +12 -0
  36. package/createResolverDecorator.js.map +1 -0
  37. package/debugPlugins.d.ts +10 -8
  38. package/debugPlugins.js +18 -28
  39. package/debugPlugins.js.map +1 -0
  40. package/errors.d.ts +2 -2
  41. package/errors.js +3 -6
  42. package/errors.js.map +1 -0
  43. package/index.d.ts +8 -6
  44. package/index.js +67 -22
  45. package/index.js.map +1 -0
  46. package/interceptConsole.d.ts +5 -1
  47. package/interceptConsole.js +7 -7
  48. package/interceptConsole.js.map +1 -0
  49. package/package.json +21 -23
  50. package/plugins/GraphQLSchemaPlugin.d.ts +14 -6
  51. package/plugins/GraphQLSchemaPlugin.js +16 -13
  52. package/plugins/GraphQLSchemaPlugin.js.map +1 -0
  53. package/plugins/index.js +3 -3
  54. package/plugins/index.js.map +1 -0
  55. package/processRequestBody.d.ts +4 -2
  56. package/processRequestBody.js +19 -18
  57. package/processRequestBody.js.map +1 -0
  58. package/responses.d.ts +20 -18
  59. package/responses.js +23 -34
  60. package/responses.js.map +1 -0
  61. package/types.d.ts +21 -12
  62. package/types.js +3 -1
  63. package/types.js.map +1 -0
  64. package/utils/index.d.ts +1 -0
  65. package/utils/index.js +18 -0
  66. package/utils/index.js.map +1 -0
  67. package/utils/resolve.d.ts +21 -0
  68. package/utils/resolve.js +28 -0
  69. package/utils/resolve.js.map +1 -0
@@ -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;
@@ -119,4 +101,6 @@ Object.keys(_TimeScalar).forEach(function (key) {
119
101
  return _TimeScalar[key];
120
102
  }
121
103
  });
122
- });
104
+ });
105
+
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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,UAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,UAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CA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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","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { HandlerGraphQLOptions } from "./types";
2
- import { PluginCollection } from "@webiny/plugins/types";
3
- declare const _default: (options?: HandlerGraphQLOptions) => PluginCollection;
1
+ import type { Plugin } from "@webiny/plugins/types";
2
+ import type { HandlerGraphQLOptions } from "./types";
3
+ declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
4
4
  export default _default;
@@ -1,77 +1,110 @@
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
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
8
  var _boolean = require("boolean");
13
-
9
+ var _handler = require("@webiny/handler");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
14
11
  var _createGraphQLSchema = require("./createGraphQLSchema");
15
-
16
12
  var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
13
+ var _processRequestBody = require("./processRequestBody");
14
+ const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
17
15
 
18
- var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
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
19
+ // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
21
20
 
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+ // TODO: `getCurrentTenant` should be injected as a parameter.
22
+ // @ts-expect-error TODO: We should not be accessing `context` like this here.
23
+ const tenant = context.tenancy?.getCurrentTenant();
23
24
 
24
- const DEFAULT_HEADERS = {
25
- "Content-Type": "application/json",
26
- "Access-Control-Allow-Origin": "*",
27
- "Access-Control-Allow-Headers": "*",
28
- "Access-Control-Allow-Methods": "OPTIONS,POST"
25
+ // TODO: `getContentLocale` should be injected as a parameter.
26
+ // @ts-expect-error TODO: We should not be accessing `context` like this here.
27
+ const contentLocale = context.i18n?.getContentLocale();
28
+ return [tenant ? `tenant:${tenant.id}` : null, contentLocale ? `locale:${contentLocale.code}` : null, plugins.length.toString()].filter(Boolean).join("#");
29
+ };
30
+ const createRequestBody = body => {
31
+ /**
32
+ * We are trusting that the body payload is correct.
33
+ * The `processRequestBody` will fail if it is not.
34
+ */
35
+ return typeof body === "string" ? JSON.parse(body) : body;
36
+ };
37
+ const formatErrorPayload = error => {
38
+ if (error instanceof _error.default) {
39
+ return JSON.stringify({
40
+ type: "CoreGraphQLWebinyError",
41
+ message: error.message,
42
+ code: error.code,
43
+ data: error.data
44
+ });
45
+ }
46
+ return JSON.stringify({
47
+ type: "Error",
48
+ name: error.name,
49
+ message: error.message,
50
+ stack: error.stack
51
+ });
29
52
  };
30
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
31
-
32
53
  var _default = (options = {}) => {
33
- let schema;
54
+ let schema = undefined;
55
+ let cacheKey = undefined;
34
56
  const debug = (0, _boolean.boolean)(options.debug);
35
- return [...(debug ? (0, _debugPlugins.default)() : []), {
36
- type: "handler",
37
- name: "handler-graphql",
38
-
39
- async handle(context, next) {
40
- const {
41
- http
42
- } = context;
43
-
44
- if (!http) {
45
- return next();
46
- }
47
-
48
- if (http.request.method === "OPTIONS") {
49
- return http.response({
50
- statusCode: 204,
51
- headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
52
- "Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
53
- })
54
- });
57
+ const path = options?.path || "/graphql";
58
+ const route = new _handler.RoutePlugin(async ({
59
+ onPost,
60
+ onOptions,
61
+ context
62
+ }) => {
63
+ onOptions(path, async (_, reply) => {
64
+ return reply.status(204).headers({
65
+ "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
66
+ }).send({}).hijack();
67
+ });
68
+ onPost(path, async (request, reply) => {
69
+ const contextCacheKey = createCacheKey(context);
70
+ if (!schema || cacheKey !== contextCacheKey) {
71
+ try {
72
+ schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
73
+ cacheKey = contextCacheKey;
74
+ } catch (ex) {
75
+ return reply.code(500).send(formatErrorPayload(ex));
76
+ }
55
77
  }
56
-
57
- if (http.request.method !== "POST") {
58
- return next();
78
+ let body;
79
+ try {
80
+ body = createRequestBody(request.body);
81
+ } catch (ex) {
82
+ console.error(`Error while creating the body request.`);
83
+ console.error(formatErrorPayload(ex));
84
+ throw ex;
59
85
  }
60
-
61
- if (!schema) {
62
- schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
86
+ try {
87
+ const result = await (0, _processRequestBody.processRequestBody)(body, schema, context);
88
+ /**
89
+ * IMPORTANT! Do not send anything if reply was already sent.
90
+ */
91
+ if (reply.sent) {
92
+ console.warn("Reply already sent, cannot send the result (handler-graphql).");
93
+ return reply;
94
+ }
95
+ return reply.status(200).send(result);
96
+ } catch (ex) {
97
+ console.error(`Error while processing the body request.`);
98
+ console.error(formatErrorPayload(ex));
99
+ throw ex;
63
100
  }
64
-
65
- const body = JSON.parse(http.request.body);
66
- const result = await (0, _processRequestBody.default)(body, schema, context);
67
- return http.response({
68
- body: JSON.stringify(result),
69
- statusCode: 200,
70
- headers: DEFAULT_HEADERS
71
- });
72
- }
73
-
74
- }];
101
+ });
102
+ });
103
+ route.name = "handler.graphql.route.default";
104
+ return [...(debug ? (0, _debugPlugins.default)() : []), {
105
+ type: "wcp-telemetry-tracker"
106
+ }, route];
75
107
  };
108
+ exports.default = _default;
76
109
 
77
- exports.default = _default;
110
+ //# sourceMappingURL=createGraphQLHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","tenancy","getCurrentTenant","contentLocale","i18n","getContentLocale","id","code","length","toString","filter","Boolean","join","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","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","sent","warn","debugPlugins","exports","default"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type { Context } from \"@webiny/handler\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin } from \"@webiny/plugins/types\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\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\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\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 = {}): Plugin[] => {\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 /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler-graphql).\");\n return reply;\n }\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;AAGA,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,GAAAN,OAAA;AAEA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAMG,MAAM,GAAGH,OAAO,CAACI,OAAO,EAAEC,gBAAgB,CAAC,CAAC;;EAElD;EACA;EACA,MAAMC,aAAa,GAAGN,OAAO,CAACO,IAAI,EAAEC,gBAAgB,CAAC,CAAC;EAEtD,OAAO,CACHL,MAAM,GAAG,UA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,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC9B,KAAK,CAAC,0CAA0C,CAAC;QACzD8B,OAAO,CAAC9B,KAAK,CAACD,kBAAkB,CAAC8B,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,IAAAsB,qBAAY,EAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACIhC,IAAI,EAAE;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAAoB,OAAA,CAAAC,OAAA,GAAA7B,QAAA","ignoreList":[]}
@@ -1,3 +1,4 @@
1
- import { Context } from "@webiny/handler/types";
2
- import { HttpContext } from "@webiny/handler-http/types";
3
- export declare const createGraphQLSchema: (context: Context<HttpContext>) => import("graphql").GraphQLSchema;
1
+ import type { Context } from "@webiny/api/types";
2
+ import type { GraphQLSchemaPlugin } from "./plugins";
3
+ export declare const getSchemaPlugins: (context: Context) => import("@webiny/plugins/PluginsContainer").WithName<GraphQLSchemaPlugin<Context>>[];
4
+ export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
@@ -1,26 +1,29 @@
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;
12
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
-
14
9
  var _schema = require("@graphql-tools/schema");
15
-
10
+ var _merge = require("@graphql-tools/merge");
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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
-
12
+ var _ResolverDecoration = require("./ResolverDecoration");
13
+ const getSchemaPlugins = context => {
14
+ return context.plugins.byType("graphql-schema").filter(pl => {
15
+ if (typeof pl.isApplicable === "function") {
16
+ return pl.isApplicable(context);
17
+ }
18
+ return true;
19
+ });
20
+ };
21
+ exports.getSchemaPlugins = getSchemaPlugins;
22
22
  const createGraphQLSchema = context => {
23
23
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
24
+
25
+ // TODO: once the API packages are more closed, we'll have the opportunity
26
+ // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
24
27
  const typeDefs = [(0, _graphqlTag.default)`
25
28
  type Query
26
29
  type Mutation
@@ -33,33 +36,58 @@ const createGraphQLSchema = context => {
33
36
  scalar Date
34
37
  scalar DateTime
35
38
  scalar Time
39
+
40
+ # This directive doesn't do anything on the GraphQL resolution level. It just serves
41
+ # as a way to tell the Prerendering Service whether the GraphQL query needs to be
42
+ # cached or not.
43
+ directive @ps(cache: Boolean) on QUERY
44
+
45
+ type Error {
46
+ code: String
47
+ message: String
48
+ data: JSON
49
+ stack: String
50
+ }
51
+
52
+ type BooleanResponse {
53
+ data: Boolean
54
+ error: Error
55
+ }
36
56
  `];
37
- const resolvers = [_objectSpread(_objectSpread({}, scalars.reduce((acc, s) => {
38
- acc[s.name] = s;
39
- return acc;
40
- }, {})), {}, {
57
+ const resolvers = [{
58
+ ...scalars.reduce((acc, s) => {
59
+ acc[s.name] = s;
60
+ return acc;
61
+ }, {}),
41
62
  JSON: _builtInTypes.JsonScalar,
42
63
  Long: _builtInTypes.LongScalar,
43
- RefInput: _builtInTypes.RefInput,
44
- Number: _builtInTypes.Number,
45
- Any: _builtInTypes.Any,
64
+ RefInput: _builtInTypes.RefInputScalar,
65
+ Number: _builtInTypes.NumberScalar,
66
+ Any: _builtInTypes.AnyScalar,
46
67
  DateTime: _builtInTypes.DateTimeScalar,
47
68
  Date: _builtInTypes.DateScalar,
48
69
  Time: _builtInTypes.TimeScalar
49
- })];
50
- const gqlPlugins = context.plugins.byType("graphql-schema");
51
-
52
- for (let i = 0; i < gqlPlugins.length; i++) {
53
- const plugin = gqlPlugins[i];
54
- typeDefs.push(plugin.schema.typeDefs);
55
- resolvers.push(plugin.schema.resolvers);
70
+ }];
71
+ const resolverDecoration = new _ResolverDecoration.ResolverDecoration();
72
+ const plugins = getSchemaPlugins(context);
73
+ for (const plugin of plugins) {
74
+ const schema = plugin.schema;
75
+ if (schema.typeDefs) {
76
+ typeDefs.push(schema.typeDefs);
77
+ }
78
+ if (schema.resolvers) {
79
+ resolvers.push(schema.resolvers);
80
+ }
81
+ if (schema.resolverDecorators) {
82
+ resolverDecoration.addDecorators(schema.resolverDecorators);
83
+ }
56
84
  }
57
-
58
85
  return (0, _schema.makeExecutableSchema)({
59
86
  typeDefs,
60
- resolvers,
87
+ resolvers: resolverDecoration.decorateResolvers((0, _merge.mergeResolvers)(resolvers)),
61
88
  inheritResolversFromInterfaces: true
62
89
  });
63
90
  };
91
+ exports.createGraphQLSchema = createGraphQLSchema;
64
92
 
65
- exports.createGraphQLSchema = createGraphQLSchema;
93
+ //# sourceMappingURL=createGraphQLSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_merge","_builtInTypes","_ResolverDecoration","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","exports","createGraphQLSchema","scalars","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","resolverDecoration","ResolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","makeExecutableSchema","decorateResolvers","mergeResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport type { GraphQLScalarType } from \"graphql/type/definition\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types\";\nimport type { 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 { ResolverDecoration } from \"./ResolverDecoration\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\").filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\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 are more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs: 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 type Error {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type BooleanResponse {\n data: Boolean\n error: Error\n }\n `\n ];\n\n const resolvers: Resolvers<any>[] = [\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 resolverDecoration = new ResolverDecoration();\n\n const plugins = getSchemaPlugins(context);\n\n for (const plugin of plugins) {\n const schema = plugin.schema;\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAIA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AAGO,MAAMK,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC,CAACC,MAAM,CAACC,EAAE,IAAI;IAC9E,IAAI,OAAOA,EAAE,CAACC,YAAY,KAAK,UAAU,EAAE;MACvC,OAAO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E;IAC1B,MAAMsC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC5B,IAAIA,MAAM,CAAC3B,QAAQ,EAAE;MACjBA,QAAQ,CAAC4B,IAAI,CAACD,MAAM,CAAC3B,QAAQ,CAAC;IAClC;IACA,IAAI2B,MAAM,CAACvB,SAAS,EAAE;MAClBA,SAAS,CAACwB,IAAI,CAACD,MAAM,CAACvB,SAAS,CAAC;IACpC;IACA,IAAIuB,MAAM,CAACE,kBAAkB,EAAE;MAC3BL,kBAAkB,CAACM,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;IAC/D;EACJ;EAEA,OAAO,IAAAE,4BAAoB,EAAC;IACxB/B,QAAQ;IACRI,SAAS,EAAEoB,kBAAkB,CAACQ,iBAAiB,CAAC,IAAAC,qBAAc,EAAC7B,SAAS,CAAC,CAAC;IAC1E8B,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAACxC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { ResolverDecorator } from "./types";
2
+ export declare const createResolverDecorator: <TSource = any, TContext = any, TArgs = any>(decorator: ResolverDecorator<TSource, TContext, TArgs>) => ResolverDecorator<TSource, TContext, TArgs>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createResolverDecorator = void 0;
7
+ const createResolverDecorator = decorator => {
8
+ return decorator;
9
+ };
10
+ exports.createResolverDecorator = createResolverDecorator;
11
+
12
+ //# sourceMappingURL=createResolverDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createResolverDecorator","decorator","exports"],"sources":["createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,uBAAuB,GAChCC,SAAsD,IACrD;EACD,OAAOA,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
package/debugPlugins.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin } from "./types";
2
- import { ContextInterface, ContextPlugin } from "@webiny/handler/types";
3
- interface DebugContext extends ContextInterface {
1
+ import type { GraphQLAfterQueryPlugin } from "./types";
2
+ import type { Context } from "@webiny/api/types";
3
+ import { ContextPlugin } from "@webiny/api";
4
+ interface Log {
5
+ method: string;
6
+ args: any;
7
+ }
8
+ interface DebugContext extends Context {
4
9
  debug: {
5
- logs?: {
6
- method: string;
7
- args: any;
8
- }[];
10
+ logs?: Log[];
9
11
  };
10
12
  }
11
- declare const _default: () => (ContextPlugin<DebugContext, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>> | GraphQLBeforeQueryPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
13
+ declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
12
14
  export default _default;
package/debugPlugins.js CHANGED
@@ -4,45 +4,35 @@ 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
- var _default = () => [{
11
- type: "context",
12
-
13
- apply(context) {
14
- context.debug = context.debug || {};
15
- context.debug.logs = [];
16
- (0, _interceptConsole.interceptConsole)((method, args) => {
17
- context.debug.logs.push({
18
- method,
19
- args
20
- });
21
- });
8
+ var _api = require("@webiny/api");
9
+ var _default = () => [new _api.ContextPlugin(async context => {
10
+ if (!context.debug) {
11
+ context.debug = {};
22
12
  }
23
-
24
- }, {
25
- type: "graphql-before-query",
26
-
27
- apply({
28
- context
29
- }) {
30
- // Empty logs
13
+ if (!context.debug.logs) {
31
14
  context.debug.logs = [];
32
15
  }
33
-
34
- }, {
16
+ (0, _interceptConsole.interceptConsole)((method, args) => {
17
+ context.debug.logs.push({
18
+ method,
19
+ args
20
+ });
21
+ });
22
+ }), {
35
23
  type: "graphql-after-query",
36
-
37
24
  apply({
38
25
  result,
39
26
  context
40
27
  }) {
41
28
  result["extensions"] = {
42
- console: context.debug.logs || []
29
+ console: [...(context.debug.logs || [])]
43
30
  };
31
+ if (context.debug.logs) {
32
+ context.debug.logs.length = 0;
33
+ }
44
34
  }
45
-
46
35
  }];
36
+ exports.default = _default;
47
37
 
48
- exports.default = _default;
38
+ //# sourceMappingURL=debugPlugins.js.map
@@ -0,0 +1 @@
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 type { GraphQLAfterQueryPlugin } from \"./types\";\nimport type { 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","ignoreList":[]}
package/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Error from "@webiny/error";
2
- export declare class NotFoundError extends Error {
1
+ import WebinyError from "@webiny/error";
2
+ export declare class NotFoundError extends WebinyError {
3
3
  constructor(message?: string);
4
4
  }
package/errors.js CHANGED
@@ -1,19 +1,16 @@
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
  }
14
+ exports.NotFoundError = NotFoundError;
18
15
 
19
- exports.NotFoundError = NotFoundError;
16
+ //# sourceMappingURL=errors.js.map
package/errors.js.map ADDED
@@ -0,0 +1 @@
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","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { HandlerGraphQLOptions } from "./types";
2
- import { Context } from "@webiny/handler/types";
3
- import { GraphQLFieldResolver } from "./types";
1
+ import type { Plugin } from "@webiny/plugins/types";
2
+ import type { HandlerGraphQLOptions } from "./types";
4
3
  export * from "./errors";
5
4
  export * from "./responses";
6
- declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
5
+ export * from "./utils";
6
+ export * from "./plugins";
7
+ export * from "./processRequestBody";
8
+ export * from "./createResolverDecorator";
9
+ export * from "./ResolverDecoration";
10
+ declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
7
11
  export default _default;
8
- export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
9
- export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;