@webiny/handler-graphql 0.0.0-unstable.b14eaecf38 → 0.0.0-unstable.b6d7105cee

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 (102) hide show
  1. package/README.md +9 -5
  2. package/ResolverDecoration.d.ts +6 -0
  3. package/ResolverDecoration.js +23 -0
  4. package/ResolverDecoration.js.map +1 -0
  5. package/builtInTypes/AnyScalar.d.ts +1 -1
  6. package/builtInTypes/AnyScalar.js +10 -16
  7. package/builtInTypes/AnyScalar.js.map +1 -1
  8. package/builtInTypes/DateScalar.d.ts +1 -1
  9. package/builtInTypes/DateScalar.js +22 -26
  10. package/builtInTypes/DateScalar.js.map +1 -1
  11. package/builtInTypes/DateTimeScalar.d.ts +1 -1
  12. package/builtInTypes/DateTimeScalar.js +17 -26
  13. package/builtInTypes/DateTimeScalar.js.map +1 -1
  14. package/builtInTypes/DateTimeZScalar.d.ts +1 -1
  15. package/builtInTypes/DateTimeZScalar.js +27 -45
  16. package/builtInTypes/DateTimeZScalar.js.map +1 -1
  17. package/builtInTypes/IconScalar.d.ts +10 -0
  18. package/builtInTypes/IconScalar.js +65 -0
  19. package/builtInTypes/IconScalar.js.map +1 -0
  20. package/builtInTypes/JsonScalar.d.ts +1 -1
  21. package/builtInTypes/JsonScalar.js +4 -8
  22. package/builtInTypes/JsonScalar.js.map +1 -1
  23. package/builtInTypes/LongScalar.d.ts +1 -1
  24. package/builtInTypes/LongScalar.js +34 -50
  25. package/builtInTypes/LongScalar.js.map +1 -1
  26. package/builtInTypes/NumberScalar.d.ts +1 -1
  27. package/builtInTypes/NumberScalar.js +35 -49
  28. package/builtInTypes/NumberScalar.js.map +1 -1
  29. package/builtInTypes/RefInputScalar.d.ts +1 -1
  30. package/builtInTypes/RefInputScalar.js +48 -49
  31. package/builtInTypes/RefInputScalar.js.map +1 -1
  32. package/builtInTypes/TimeScalar.d.ts +1 -1
  33. package/builtInTypes/TimeScalar.js +31 -50
  34. package/builtInTypes/TimeScalar.js.map +1 -1
  35. package/builtInTypes/index.d.ts +10 -9
  36. package/builtInTypes/index.js +10 -104
  37. package/createGraphQLHandler.d.ts +3 -3
  38. package/createGraphQLHandler.js +76 -78
  39. package/createGraphQLHandler.js.map +1 -1
  40. package/createGraphQLSchema.d.ts +4 -2
  41. package/createGraphQLSchema.js +69 -53
  42. package/createGraphQLSchema.js.map +1 -1
  43. package/createRequestBody.d.ts +2 -0
  44. package/createRequestBody.js +28 -0
  45. package/createRequestBody.js.map +1 -0
  46. package/createResolverDecorator.d.ts +2 -0
  47. package/createResolverDecorator.js +4 -0
  48. package/createResolverDecorator.js.map +1 -0
  49. package/debugPlugins.d.ts +3 -3
  50. package/debugPlugins.js +27 -35
  51. package/debugPlugins.js.map +1 -1
  52. package/errors.js +8 -13
  53. package/errors.js.map +1 -1
  54. package/exports/api/graphql.d.ts +2 -0
  55. package/exports/api/graphql.js +2 -0
  56. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
  57. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +57 -0
  58. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
  59. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
  60. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +35 -0
  61. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
  62. package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
  63. package/features/GraphQLSchemaBuilder/abstractions.js +6 -0
  64. package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
  65. package/features/GraphQLSchemaBuilder/feature.d.ts +4 -0
  66. package/features/GraphQLSchemaBuilder/feature.js +11 -0
  67. package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
  68. package/graphql/abstractions.core.d.ts +11 -0
  69. package/graphql/abstractions.core.js +5 -0
  70. package/graphql/abstractions.core.js.map +1 -0
  71. package/graphql/abstractions.d.ts +2 -0
  72. package/graphql/abstractions.js +2 -0
  73. package/graphql/abstractions.public.d.ts +18 -0
  74. package/graphql/abstractions.public.js +5 -0
  75. package/graphql/abstractions.public.js.map +1 -0
  76. package/index.d.ts +10 -6
  77. package/index.js +11 -55
  78. package/index.js.map +1 -1
  79. package/interceptConsole.js +32 -34
  80. package/interceptConsole.js.map +1 -1
  81. package/package.json +32 -30
  82. package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
  83. package/plugins/GraphQLSchemaPlugin.js +24 -23
  84. package/plugins/GraphQLSchemaPlugin.js.map +1 -1
  85. package/plugins/index.d.ts +1 -1
  86. package/plugins/index.js +1 -16
  87. package/processRequestBody.d.ts +4 -5
  88. package/processRequestBody.js +36 -37
  89. package/processRequestBody.js.map +1 -1
  90. package/responses.d.ts +11 -1
  91. package/responses.js +45 -73
  92. package/responses.js.map +1 -1
  93. package/types.d.ts +20 -13
  94. package/types.js +0 -5
  95. package/utils/index.d.ts +1 -0
  96. package/utils/index.js +1 -0
  97. package/utils/resolve.d.ts +21 -0
  98. package/utils/resolve.js +20 -0
  99. package/utils/resolve.js.map +1 -0
  100. package/builtInTypes/index.js.map +0 -1
  101. package/plugins/index.js.map +0 -1
  102. package/types.js.map +0 -1
@@ -1,84 +1,82 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _boolean = require("boolean");
9
- var _handler = require("@webiny/handler");
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
- var _createGraphQLSchema = require("./createGraphQLSchema");
12
- var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
13
- var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
14
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
15
-
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
- */
21
- return typeof body === "string" ? JSON.parse(body) : body;
1
+ import { toBoolean } from "@webiny/stdlib";
2
+ import { RoutePlugin } from "@webiny/handler";
3
+ import _webiny_error from "@webiny/error";
4
+ import { createGraphQLSchema, getSchemaPlugins } from "./createGraphQLSchema.js";
5
+ import debugPlugins from "./debugPlugins.js";
6
+ import { processRequestBody } from "./processRequestBody.js";
7
+ import { createRequestBody } from "./createRequestBody.js";
8
+ const DEFAULT_CACHE_MAX_AGE = 30758400;
9
+ const createCacheKey = (context)=>{
10
+ const plugins = getSchemaPlugins(context);
11
+ const tenant = context.tenancy?.getCurrentTenant();
12
+ return [
13
+ tenant ? `tenant:${tenant.id}` : null,
14
+ plugins.length.toString()
15
+ ].filter(Boolean).join("#");
22
16
  };
23
- const formatErrorPayload = error => {
24
- if (error instanceof _error.default) {
17
+ const formatErrorPayload = (error)=>{
18
+ if (error instanceof _webiny_error) return JSON.stringify({
19
+ type: "CoreGraphQLWebinyError",
20
+ message: error.message,
21
+ code: error.code,
22
+ data: error.data,
23
+ stack: error.stack
24
+ });
25
25
  return JSON.stringify({
26
- type: "CoreGraphQLWebinyError",
27
- message: error.message,
28
- code: error.code,
29
- data: error.data
26
+ type: "Error",
27
+ name: error.name,
28
+ message: error.message,
29
+ stack: error.stack
30
30
  });
31
- }
32
- return JSON.stringify({
33
- type: "Error",
34
- name: error.name,
35
- message: error.message,
36
- stack: error.stack
37
- });
38
31
  };
39
- var _default = (options = {}) => {
40
- let schema = undefined;
41
- const debug = (0, _boolean.boolean)(options.debug);
42
- const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
43
- const route = new _handler.RoutePlugin(async ({
44
- onPost,
45
- onOptions,
46
- context
47
- }) => {
48
- onOptions(path, async (_, reply) => {
49
- return reply.status(204).headers({
50
- "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
51
- }).send({}).hijack();
32
+ const createGraphQLHandler = (options = {})=>{
33
+ let schema;
34
+ let cacheKey;
35
+ const debug = toBoolean(options.debug);
36
+ const path = options?.path || "/graphql";
37
+ const route = new RoutePlugin(async ({ onPost, onOptions, context })=>{
38
+ onOptions(path, async (_, reply)=>reply.status(204).headers({
39
+ "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
40
+ }).send({}).hijack());
41
+ onPost(path, async (request, reply)=>{
42
+ const contextCacheKey = createCacheKey(context);
43
+ if (!schema || cacheKey !== contextCacheKey) try {
44
+ schema = await createGraphQLSchema(context);
45
+ cacheKey = contextCacheKey;
46
+ } catch (ex) {
47
+ return reply.code(500).send(formatErrorPayload(ex));
48
+ }
49
+ let body;
50
+ try {
51
+ body = createRequestBody(request.body);
52
+ } catch (ex) {
53
+ console.error("Error while creating the body request.");
54
+ console.error(formatErrorPayload(ex));
55
+ throw ex;
56
+ }
57
+ try {
58
+ const result = await processRequestBody(body, schema, context);
59
+ if (reply.sent) {
60
+ console.warn("Reply already sent, cannot send the result (handler-graphql).");
61
+ return reply;
62
+ }
63
+ return reply.status(200).send(result);
64
+ } catch (ex) {
65
+ console.error("Error while processing the body request.");
66
+ console.error(formatErrorPayload(ex));
67
+ throw ex;
68
+ }
69
+ });
52
70
  });
53
- onPost(path, async (request, reply) => {
54
- if (!schema) {
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;
76
- }
77
- });
78
- });
79
- route.name = "handler.graphql.route.default";
80
- return [...(debug ? (0, _debugPlugins.default)() : []), {
81
- type: "wcp-telemetry-tracker"
82
- }, route];
71
+ route.name = "handler.graphql.route.default";
72
+ return [
73
+ ...debug ? debugPlugins() : [],
74
+ {
75
+ type: "wcp-telemetry-tracker"
76
+ },
77
+ route
78
+ ];
83
79
  };
84
- exports.default = _default;
80
+ export default createGraphQLHandler;
81
+
82
+ //# sourceMappingURL=createGraphQLHandler.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"createGraphQLHandler.js","sources":["../src/createGraphQLHandler.ts"],"sourcesContent":["import { toBoolean } from \"@webiny/stdlib\";\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.js\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types.js\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema.js\";\nimport debugPlugins from \"./debugPlugins.js\";\nimport { processRequestBody } from \"./processRequestBody.js\";\nimport { createRequestBody } from \"~/createRequestBody.js\";\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 return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()]\n .filter(Boolean)\n .join(\"#\");\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 stack: error.stack\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 = toBoolean(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 = await 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"],"names":["DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","Boolean","formatErrorPayload","error","WebinyError","JSON","options","schema","cacheKey","debug","toBoolean","path","route","RoutePlugin","onPost","onOptions","_","reply","request","contextCacheKey","createGraphQLSchema","ex","body","createRequestBody","console","result","processRequestBody","debugPlugins"],"mappings":";;;;;;;AAYA,MAAMA,wBAAwB;AAE9B,MAAMC,iBAAiB,CAACC;IACpB,MAAMC,UAAUC,iBAAiBF;IAMjC,MAAMG,SAASH,QAAQ,OAAO,EAAE;IAEhC,OAAO;QAACG,SAAS,CAAC,OAAO,EAAEA,OAAO,EAAE,EAAE,GAAG;QAAMF,QAAQ,MAAM,CAAC,QAAQ;KAAG,CACpE,MAAM,CAACG,SACP,IAAI,CAAC;AACd;AAEA,MAAMC,qBAAqB,CAACC;IACxB,IAAIA,iBAAiBC,eACjB,OAAOC,KAAK,SAAS,CAAC;QAClB,MAAM;QACN,SAASF,MAAM,OAAO;QACtB,MAAMA,MAAM,IAAI;QAChB,MAAMA,MAAM,IAAI;QAChB,OAAOA,MAAM,KAAK;IACtB;IAGJ,OAAOE,KAAK,SAAS,CAAC;QAClB,MAAM;QACN,MAAMF,MAAM,IAAI;QAChB,SAASA,MAAM,OAAO;QACtB,OAAOA,MAAM,KAAK;IACtB;AACJ;AAEA,6BAAgB,CAAAG,UAAiC,CAAC,CAAC;IAC/C,IAAIC;IACJ,IAAIC;IAEJ,MAAMC,QAAQC,UAAUJ,QAAQ,KAAK;IAErC,MAAMK,OAAOL,SAAS,QAAQ;IAE9B,MAAMM,QAAQ,IAAIC,YAAY,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAElB,OAAO,EAAE;QAC/DkB,UAAUJ,MAAM,OAAOK,GAAGC,QACfA,MACF,MAAM,CAAC,KACP,OAAO,CAAC;gBACL,iBAAiB,CAAC,gBAAgB,EAAEtB,uBAAuB;YAC/D,GACC,IAAI,CAAC,CAAC,GACN,MAAM;QAEfmB,OAAOH,MAAM,OAAOO,SAASD;YACzB,MAAME,kBAAkBvB,eAAeC;YACvC,IAAI,CAACU,UAAUC,aAAaW,iBACxB,IAAI;gBACAZ,SAAS,MAAMa,oBAAoBvB;gBACnCW,WAAWW;YACf,EAAE,OAAOE,IAAI;gBACT,OAAOJ,MAAM,IAAI,CAAC,KAAK,IAAI,CAACf,mBAAmBmB;YACnD;YAEJ,IAAIC;YACJ,IAAI;gBACAA,OAAOC,kBAAkBL,QAAQ,IAAI;YACzC,EAAE,OAAOG,IAAI;gBACTG,QAAQ,KAAK,CAAC;gBACdA,QAAQ,KAAK,CAACtB,mBAAmBmB;gBACjC,MAAMA;YACV;YACA,IAAI;gBACA,MAAMI,SAAS,MAAMC,mBAAmBJ,MAAMf,QAAQV;gBAItD,IAAIoB,MAAM,IAAI,EAAE;oBACZO,QAAQ,IAAI,CAAC;oBACb,OAAOP;gBACX;gBACA,OAAOA,MAAM,MAAM,CAAC,KAAK,IAAI,CAACQ;YAClC,EAAE,OAAOJ,IAAI;gBACTG,QAAQ,KAAK,CAAC;gBACdA,QAAQ,KAAK,CAACtB,mBAAmBmB;gBACjC,MAAMA;YACV;QACJ;IACJ;IAEAT,MAAM,IAAI,GAAG;IAEb,OAAO;WACCH,QAAQkB,iBAAiB,EAAE;QAC/B;YACI,MAAM;QACV;QACAf;KACH;AACL"}
@@ -1,2 +1,4 @@
1
- import { Context } from "@webiny/api/types";
2
- export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
1
+ import type { Context } from "@webiny/api/types.js";
2
+ import type { GraphQLSchemaPlugin } from "./plugins/index.js";
3
+ export declare const getSchemaPlugins: (context: Context) => import("@webiny/plugins/PluginsContainer.js").WithName<GraphQLSchemaPlugin<Context>>[];
4
+ export declare const createGraphQLSchema: (context: Context) => Promise<import("graphql").GraphQLSchema>;
@@ -1,25 +1,25 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGraphQLSchema = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
- var _schema = require("@graphql-tools/schema");
11
- var _builtInTypes = require("./builtInTypes");
12
- const createGraphQLSchema = context => {
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.
17
- const typeDefs = [(0, _graphqlTag.default)`
1
+ import graphql_tag from "graphql-tag";
2
+ import { makeExecutableSchema } from "@graphql-tools/schema";
3
+ import { mergeResolvers } from "@graphql-tools/merge";
4
+ import { AnyScalar, DateScalar, DateTimeScalar, IconScalar, JsonScalar, LongScalar, NumberScalar, RefInputScalar, TimeScalar } from "./builtInTypes/index.js";
5
+ import { ResolverDecoration } from "./ResolverDecoration.js";
6
+ import { GraphQLSchemaComposer } from "./features/GraphQLSchemaBuilder/abstractions.js";
7
+ import { GraphQLSchemaComposerFeature } from "./features/GraphQLSchemaBuilder/feature.js";
8
+ const getSchemaPlugins = (context)=>context.plugins.byType("graphql-schema").filter((pl)=>{
9
+ if ("function" == typeof pl.isApplicable) return pl.isApplicable(context);
10
+ return true;
11
+ });
12
+ const createGraphQLSchema = async (context)=>{
13
+ GraphQLSchemaComposerFeature.register(context.container);
14
+ const scalars = context.plugins.byType("graphql-scalar").map((item)=>item.scalar);
15
+ const typeDefs = [
16
+ graphql_tag`
18
17
  type Query
19
18
  type Mutation
20
- ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
19
+ ${scalars.map((scalar)=>`scalar ${scalar.name}`).join(" ")}
21
20
  scalar JSON
22
21
  scalar Long
22
+ scalar Icon
23
23
  scalar RefInput
24
24
  scalar Number
25
25
  scalar Any
@@ -27,39 +27,55 @@ const createGraphQLSchema = context => {
27
27
  scalar DateTime
28
28
  scalar Time
29
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
34
- `];
35
- const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
36
- acc[s.name] = s;
37
- return acc;
38
- }, {})), {}, {
39
- JSON: _builtInTypes.JsonScalar,
40
- Long: _builtInTypes.LongScalar,
41
- RefInput: _builtInTypes.RefInputScalar,
42
- Number: _builtInTypes.NumberScalar,
43
- Any: _builtInTypes.AnyScalar,
44
- DateTime: _builtInTypes.DateTimeScalar,
45
- Date: _builtInTypes.DateScalar,
46
- Time: _builtInTypes.TimeScalar
47
- })];
48
- const plugins = context.plugins.byType("graphql-schema");
49
- for (const plugin of plugins) {
50
- /**
51
- * TODO @ts-refactor
52
- * Figure out correct types on typeDefs and resolvers
53
- */
54
- // @ts-ignore
55
- typeDefs.push(plugin.schema.typeDefs);
56
- // @ts-ignore
57
- resolvers.push(plugin.schema.resolvers);
58
- }
59
- return (0, _schema.makeExecutableSchema)({
60
- typeDefs,
61
- resolvers,
62
- inheritResolversFromInterfaces: true
63
- });
30
+ type Error {
31
+ code: String
32
+ message: String
33
+ data: JSON
34
+ stack: String
35
+ }
36
+
37
+ type BooleanResponse {
38
+ data: Boolean
39
+ error: Error
40
+ }
41
+ `
42
+ ];
43
+ const resolvers = [
44
+ {
45
+ ...scalars.reduce((acc, s)=>{
46
+ acc[s.name] = s;
47
+ return acc;
48
+ }, {}),
49
+ JSON: JsonScalar,
50
+ Long: LongScalar,
51
+ RefInput: RefInputScalar,
52
+ Number: NumberScalar,
53
+ Any: AnyScalar,
54
+ DateTime: DateTimeScalar,
55
+ Date: DateScalar,
56
+ Time: TimeScalar,
57
+ Icon: IconScalar
58
+ }
59
+ ];
60
+ const resolverDecoration = new ResolverDecoration();
61
+ const plugins = getSchemaPlugins(context);
62
+ for (const plugin of plugins){
63
+ const schema = plugin.schema;
64
+ if (schema.typeDefs) typeDefs.push(schema.typeDefs);
65
+ if (schema.resolvers) resolvers.push(schema.resolvers);
66
+ if (schema.resolverDecorators) resolverDecoration.addDecorators(schema.resolverDecorators);
67
+ }
68
+ const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);
69
+ const schema = await graphQLSchemaComposer.build();
70
+ if (schema.typeDefs) typeDefs.push(schema.typeDefs);
71
+ if (schema.resolvers) resolvers.push(schema.resolvers);
72
+ if (schema.resolverDecorators) resolverDecoration.addDecorators(schema.resolverDecorators);
73
+ return makeExecutableSchema({
74
+ typeDefs,
75
+ resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
76
+ inheritResolversFromInterfaces: true
77
+ });
64
78
  };
65
- exports.createGraphQLSchema = createGraphQLSchema;
79
+ export { createGraphQLSchema, getSchemaPlugins };
80
+
81
+ //# sourceMappingURL=createGraphQLSchema.js.map
@@ -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","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"}
1
+ {"version":3,"file":"createGraphQLSchema.js","sources":["../src/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.js\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar,\n IconScalar\n} from \"./builtInTypes/index.js\";\nimport { ResolverDecoration } from \"./ResolverDecoration.js\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { GraphQLSchemaComposer } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { GraphQLSchemaComposerFeature } from \"~/features/GraphQLSchemaBuilder/feature.js\";\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 = async (context: Context) => {\n GraphQLSchemaComposerFeature.register(context.container);\n\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\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 Icon\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\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 Icon: IconScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n // Process legacy plugins\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 // Process new DI implementations\n const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);\n const schema = await graphQLSchemaComposer.build();\n\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 // Create executable schema\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"names":["getSchemaPlugins","context","pl","createGraphQLSchema","GraphQLSchemaComposerFeature","scalars","item","typeDefs","gql","scalar","resolvers","acc","s","JsonScalar","LongScalar","RefInputScalar","NumberScalar","AnyScalar","DateTimeScalar","DateScalar","TimeScalar","IconScalar","resolverDecoration","ResolverDecoration","plugins","plugin","schema","graphQLSchemaComposer","GraphQLSchemaComposer","makeExecutableSchema","mergeResolvers"],"mappings":";;;;;;;AAsBO,MAAMA,mBAAmB,CAACC,UACtBA,QAAQ,OAAO,CAAC,MAAM,CAAsB,kBAAkB,MAAM,CAACC,CAAAA;QACxE,IAAI,AAA2B,cAA3B,OAAOA,GAAG,YAAY,EACtB,OAAOA,GAAG,YAAY,CAACD;QAE3B,OAAO;IACX;AAGG,MAAME,sBAAsB,OAAOF;IACtCG,6BAA6B,QAAQ,CAACH,QAAQ,SAAS;IAEvD,MAAMI,UAAUJ,QAAQ,OAAO,CAC1B,MAAM,CAAsB,kBAC5B,GAAG,CAACK,CAAAA,OAAQA,KAAK,MAAM;IAE5B,MAAMC,WAAuB;QACzBC,WAAG,CAAC;;;YAGA,EAAEH,QAAQ,GAAG,CAACI,CAAAA,SAAU,CAAC,OAAO,EAAEA,OAAO,IAAI,EAAE,EAAE,IAAI,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;QAsB/D,CAAC;KACJ;IAED,MAAMC,YAA8B;QAChC;YACI,GAAGL,QAAQ,MAAM,CAAoC,CAACM,KAAKC;gBACvDD,GAAG,CAACC,EAAE,IAAI,CAAC,GAAGA;gBACd,OAAOD;YACX,GAAG,CAAC,EAAE;YACN,MAAME;YACN,MAAMC;YACN,UAAUC;YACV,QAAQC;YACR,KAAKC;YACL,UAAUC;YACV,MAAMC;YACN,MAAMC;YACN,MAAMC;QACV;KACH;IAED,MAAMC,qBAAqB,IAAIC;IAG/B,MAAMC,UAAUxB,iBAAiBC;IAEjC,KAAK,MAAMwB,UAAUD,QAAS;QAC1B,MAAME,SAASD,OAAO,MAAM;QAC5B,IAAIC,OAAO,QAAQ,EACfnB,SAAS,IAAI,CAACmB,OAAO,QAAQ;QAEjC,IAAIA,OAAO,SAAS,EAChBhB,UAAU,IAAI,CAACgB,OAAO,SAAS;QAEnC,IAAIA,OAAO,kBAAkB,EACzBJ,mBAAmB,aAAa,CAACI,OAAO,kBAAkB;IAElE;IAGA,MAAMC,wBAAwB1B,QAAQ,SAAS,CAAC,OAAO,CAAC2B;IACxD,MAAMF,SAAS,MAAMC,sBAAsB,KAAK;IAEhD,IAAID,OAAO,QAAQ,EACfnB,SAAS,IAAI,CAACmB,OAAO,QAAQ;IAEjC,IAAIA,OAAO,SAAS,EAChBhB,UAAU,IAAI,CAACgB,OAAO,SAAS;IAEnC,IAAIA,OAAO,kBAAkB,EACzBJ,mBAAmB,aAAa,CAACI,OAAO,kBAAkB;IAI9D,OAAOG,qBAAqB;QACxBtB;QACA,WAAWe,mBAAmB,iBAAiB,CAACQ,eAAepB;QAC/D,gCAAgC;IACpC;AACJ"}
@@ -0,0 +1,2 @@
1
+ import type { GraphQLRequestBody } from "./types.js";
2
+ export declare const createRequestBody: (input: unknown) => GraphQLRequestBody | GraphQLRequestBody[];
@@ -0,0 +1,28 @@
1
+ import zod from "zod";
2
+ import { WebinyError } from "@webiny/error";
3
+ import { createZodError } from "@webiny/utils/createZodError.js";
4
+ const requestBodySchema = zod.looseObject({
5
+ query: zod.string(),
6
+ variables: zod.record(zod.string(), zod.any()).nullish().optional(),
7
+ operationName: zod.string().nullish().optional().transform((value)=>value || void 0)
8
+ });
9
+ const schema = zod.union([
10
+ requestBodySchema,
11
+ zod.array(requestBodySchema)
12
+ ]);
13
+ const createRequestBody = (input)=>{
14
+ const body = "string" == typeof input ? JSON.parse(input) : input;
15
+ const result = schema.safeParse(body);
16
+ if (!result.success) {
17
+ const error = createZodError(result.error);
18
+ throw new WebinyError({
19
+ message: "Invalid GraphQL request! Check your query and variables.",
20
+ code: "GRAPHQL_REQUEST_INVALID",
21
+ data: error.data
22
+ });
23
+ }
24
+ return result.data;
25
+ };
26
+ export { createRequestBody };
27
+
28
+ //# sourceMappingURL=createRequestBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRequestBody.js","sources":["../src/createRequestBody.ts"],"sourcesContent":["import zod from \"zod\";\nimport { WebinyError } from \"@webiny/error\";\nimport { createZodError } from \"@webiny/utils/createZodError.js\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\n\nconst requestBodySchema = zod.looseObject({\n query: zod.string(),\n variables: zod.record(zod.string(), zod.any()).nullish().optional(),\n operationName: zod\n .string()\n .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n })\n});\n\nconst schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);\n\nexport const createRequestBody = (input: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n const body = typeof input === \"string\" ? JSON.parse(input) : input;\n\n const result = schema.safeParse(body);\n if (!result.success) {\n const error = createZodError(result.error);\n throw new WebinyError({\n message: \"Invalid GraphQL request! Check your query and variables.\",\n code: \"GRAPHQL_REQUEST_INVALID\",\n data: error.data\n });\n }\n return result.data;\n};\n"],"names":["requestBodySchema","zod","value","undefined","schema","createRequestBody","input","body","JSON","result","error","createZodError","WebinyError"],"mappings":";;;AAKA,MAAMA,oBAAoBC,IAAI,WAAW,CAAC;IACtC,OAAOA,IAAI,MAAM;IACjB,WAAWA,IAAI,MAAM,CAACA,IAAI,MAAM,IAAIA,IAAI,GAAG,IAAI,OAAO,GAAG,QAAQ;IACjE,eAAeA,IAAAA,MACJ,GACN,OAAO,GACP,QAAQ,GACR,SAAS,CAACC,CAAAA,QACAA,SAASC;AAE5B;AAEA,MAAMC,SAASH,IAAI,KAAK,CAAC;IAACD;IAAmBC,IAAI,KAAK,CAACD;CAAmB;AAEnE,MAAMK,oBAAoB,CAACC;IAC9B,MAAMC,OAAO,AAAiB,YAAjB,OAAOD,QAAqBE,KAAK,KAAK,CAACF,SAASA;IAE7D,MAAMG,SAASL,OAAO,SAAS,CAACG;IAChC,IAAI,CAACE,OAAO,OAAO,EAAE;QACjB,MAAMC,QAAQC,eAAeF,OAAO,KAAK;QACzC,MAAM,IAAIG,YAAY;YAClB,SAAS;YACT,MAAM;YACN,MAAMF,MAAM,IAAI;QACpB;IACJ;IACA,OAAOD,OAAO,IAAI;AACtB"}
@@ -0,0 +1,2 @@
1
+ import type { ResolverDecorator } from "./types.js";
2
+ export declare const createResolverDecorator: <TSource = any, TContext = any, TArgs = any>(decorator: ResolverDecorator<TSource, TContext, TArgs>) => ResolverDecorator<TSource, TContext, TArgs>;
@@ -0,0 +1,4 @@
1
+ const createResolverDecorator = (decorator)=>decorator;
2
+ export { createResolverDecorator };
3
+
4
+ //# sourceMappingURL=createResolverDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResolverDecorator.js","sources":["../src/createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types.js\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"names":["createResolverDecorator","decorator"],"mappings":"AAEO,MAAMA,0BAA0B,CACnCC,YAEOA"}
package/debugPlugins.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { GraphQLAfterQueryPlugin } from "./types";
2
- import { Context } from "@webiny/api/types";
1
+ import type { GraphQLAfterQueryPlugin } from "./types.js";
2
+ import type { Context } from "@webiny/api/types.js";
3
3
  import { ContextPlugin } from "@webiny/api";
4
4
  interface Log {
5
5
  method: string;
@@ -10,5 +10,5 @@ interface DebugContext extends Context {
10
10
  logs?: Log[];
11
11
  };
12
12
  }
13
- declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
14
13
  export default _default;
14
+ declare function _default(): (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
package/debugPlugins.js CHANGED
@@ -1,36 +1,28 @@
1
- "use strict";
1
+ import { interceptConsole } from "./interceptConsole.js";
2
+ import { ContextPlugin } from "@webiny/api";
3
+ const debugPlugins = ()=>[
4
+ new ContextPlugin(async (context)=>{
5
+ if (!context.debug) context.debug = {};
6
+ if (!context.debug.logs) context.debug.logs = [];
7
+ interceptConsole((method, args)=>{
8
+ context.debug.logs.push({
9
+ method,
10
+ args
11
+ });
12
+ });
13
+ }),
14
+ {
15
+ type: "graphql-after-query",
16
+ apply ({ result, context }) {
17
+ result["extensions"] = {
18
+ console: [
19
+ ...context.debug.logs || []
20
+ ]
21
+ };
22
+ if (context.debug.logs) context.debug.logs.length = 0;
23
+ }
24
+ }
25
+ ];
26
+ export default debugPlugins;
2
27
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _interceptConsole = require("./interceptConsole");
8
- var _api = require("@webiny/api");
9
- var _default = () => [new _api.ContextPlugin(async context => {
10
- if (!context.debug) {
11
- context.debug = {};
12
- }
13
- if (!context.debug.logs) {
14
- context.debug.logs = [];
15
- }
16
- (0, _interceptConsole.interceptConsole)((method, args) => {
17
- context.debug.logs.push({
18
- method,
19
- args
20
- });
21
- });
22
- }), {
23
- type: "graphql-after-query",
24
- apply({
25
- result,
26
- context
27
- }) {
28
- result["extensions"] = {
29
- console: [...(context.debug.logs || [])]
30
- };
31
- if (context.debug.logs) {
32
- context.debug.logs.length = 0;
33
- }
34
- }
35
- }];
36
- exports.default = _default;
28
+ //# sourceMappingURL=debugPlugins.js.map
@@ -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;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"}
1
+ {"version":3,"file":"debugPlugins.js","sources":["../src/debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole.js\";\nimport type { GraphQLAfterQueryPlugin } from \"./types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\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"],"names":["ContextPlugin","context","interceptConsole","method","args","result"],"mappings":";;AAeA,qBAAgB,IAAK;QACjB,IAAIA,cAA4B,OAAMC;YAClC,IAAI,CAACA,QAAQ,KAAK,EACdA,QAAQ,KAAK,GAAG,CAAC;YAGrB,IAAI,CAACA,QAAQ,KAAK,CAAC,IAAI,EACnBA,QAAQ,KAAK,CAAC,IAAI,GAAG,EAAE;YAG3BC,iBAAiB,CAACC,QAAQC;gBACrBH,QAAQ,KAAK,CAAC,IAAI,CAAW,IAAI,CAAC;oBAAEE;oBAAQC;gBAAK;YACtD;QACJ;QACA;YACI,MAAM;YACN,OAAM,EAAEC,MAAM,EAAEJ,OAAO,EAAE;gBACrBI,MAAM,CAAC,aAAa,GAAG;oBAAE,SAAS;2BAAKJ,QAAQ,KAAK,CAAC,IAAI,IAAI,EAAE;qBAAE;gBAAC;gBAClE,IAAIA,QAAQ,KAAK,CAAC,IAAI,EAClBA,QAAQ,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG;YAEpC;QACJ;KACJ"}
package/errors.js CHANGED
@@ -1,14 +1,9 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.NotFoundError = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- class NotFoundError extends _error.default {
10
- constructor(message = "Not found.") {
11
- super(message, "NOT_FOUND");
12
- }
1
+ import error from "@webiny/error";
2
+ class NotFoundError extends error {
3
+ constructor(message = "Not found."){
4
+ super(message, "NOT_FOUND");
5
+ }
13
6
  }
14
- exports.NotFoundError = NotFoundError;
7
+ export { NotFoundError };
8
+
9
+ //# sourceMappingURL=errors.js.map
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,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAAC"}
1
+ {"version":3,"file":"errors.js","sources":["../src/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"],"names":["NotFoundError","WebinyError","message"],"mappings":";AAEO,MAAMA,sBAAsBC;IAC/B,YAAYC,UAAU,YAAY,CAAE;QAChC,KAAK,CAACA,SAAS;IACnB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { GraphQLSchemaFactory } from "../../graphql/abstractions.js";
2
+ export { ErrorResponse, ListResponse, Response, NotFoundResponse, ListErrorResponse } from "../../responses.js";
@@ -0,0 +1,2 @@
1
+ export { GraphQLSchemaFactory } from "../../graphql/abstractions.js";
2
+ export { ErrorResponse, ListErrorResponse, ListResponse, NotFoundResponse, Response } from "../../responses.js";
@@ -0,0 +1,16 @@
1
+ import type { GraphQLSchemaBuilder as Abstraction } from "./abstractions.js";
2
+ import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
3
+ import type { ResolverDecorator } from "../../types.js";
4
+ export declare class GraphQLSchemaBuilder implements Abstraction.Interface {
5
+ private readonly typeDefsArray;
6
+ private readonly resolvers;
7
+ private readonly resolverDecorators;
8
+ addTypeDefs(typeDefs: string): this;
9
+ addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this;
10
+ /**
11
+ * @internal This method needs revisiting, to align with DI concepts.
12
+ */
13
+ addResolverDecorator(path: string, decorator: ResolverDecorator): this;
14
+ build(): IGraphQLSchema;
15
+ private setResolverAtPath;
16
+ }