@webiny/handler-graphql 6.0.0-beta.0 → 6.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +9 -5
  2. package/ResolverDecoration.d.ts +6 -0
  3. package/ResolverDecoration.js +19 -0
  4. package/ResolverDecoration.js.map +1 -0
  5. package/builtInTypes/AnyScalar.d.ts +1 -1
  6. package/builtInTypes/AnyScalar.js +2 -8
  7. package/builtInTypes/AnyScalar.js.map +1 -1
  8. package/builtInTypes/DateScalar.d.ts +1 -1
  9. package/builtInTypes/DateScalar.js +7 -10
  10. package/builtInTypes/DateScalar.js.map +1 -1
  11. package/builtInTypes/DateTimeScalar.d.ts +1 -1
  12. package/builtInTypes/DateTimeScalar.js +7 -10
  13. package/builtInTypes/DateTimeScalar.js.map +1 -1
  14. package/builtInTypes/DateTimeZScalar.d.ts +1 -1
  15. package/builtInTypes/DateTimeZScalar.js +8 -15
  16. package/builtInTypes/DateTimeZScalar.js.map +1 -1
  17. package/builtInTypes/IconScalar.d.ts +10 -0
  18. package/builtInTypes/IconScalar.js +93 -0
  19. package/builtInTypes/IconScalar.js.map +1 -0
  20. package/builtInTypes/JsonScalar.d.ts +1 -1
  21. package/builtInTypes/JsonScalar.js +2 -8
  22. package/builtInTypes/JsonScalar.js.map +1 -1
  23. package/builtInTypes/LongScalar.d.ts +1 -1
  24. package/builtInTypes/LongScalar.js +8 -15
  25. package/builtInTypes/LongScalar.js.map +1 -1
  26. package/builtInTypes/NumberScalar.d.ts +1 -1
  27. package/builtInTypes/NumberScalar.js +9 -16
  28. package/builtInTypes/NumberScalar.js.map +1 -1
  29. package/builtInTypes/RefInputScalar.d.ts +1 -1
  30. package/builtInTypes/RefInputScalar.js +8 -8
  31. package/builtInTypes/RefInputScalar.js.map +1 -1
  32. package/builtInTypes/TimeScalar.d.ts +1 -1
  33. package/builtInTypes/TimeScalar.js +9 -16
  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/builtInTypes/index.js.map +1 -1
  38. package/createGraphQLHandler.d.ts +3 -3
  39. package/createGraphQLHandler.js +25 -35
  40. package/createGraphQLHandler.js.map +1 -1
  41. package/createGraphQLSchema.d.ts +4 -4
  42. package/createGraphQLSchema.js +68 -41
  43. package/createGraphQLSchema.js.map +1 -1
  44. package/createRequestBody.d.ts +2 -0
  45. package/createRequestBody.js +26 -0
  46. package/createRequestBody.js.map +1 -0
  47. package/createResolverDecorator.d.ts +2 -0
  48. package/createResolverDecorator.js +5 -0
  49. package/createResolverDecorator.js.map +1 -0
  50. package/debugPlugins.d.ts +2 -2
  51. package/debugPlugins.js +4 -11
  52. package/debugPlugins.js.map +1 -1
  53. package/errors.js +2 -10
  54. package/errors.js.map +1 -1
  55. package/exports/api/graphql.d.ts +2 -0
  56. package/exports/api/graphql.js +4 -0
  57. package/exports/api/graphql.js.map +1 -0
  58. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
  59. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +64 -0
  60. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
  61. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
  62. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +29 -0
  63. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
  64. package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
  65. package/features/GraphQLSchemaBuilder/abstractions.js +5 -0
  66. package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
  67. package/features/GraphQLSchemaBuilder/feature.d.ts +1 -0
  68. package/features/GraphQLSchemaBuilder/feature.js +10 -0
  69. package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
  70. package/graphql/abstractions.core.d.ts +11 -0
  71. package/graphql/abstractions.core.js +10 -0
  72. package/graphql/abstractions.core.js.map +1 -0
  73. package/graphql/abstractions.d.ts +2 -0
  74. package/graphql/abstractions.js +4 -0
  75. package/graphql/abstractions.js.map +1 -0
  76. package/graphql/abstractions.public.d.ts +19 -0
  77. package/graphql/abstractions.public.js +12 -0
  78. package/graphql/abstractions.public.js.map +1 -0
  79. package/index.d.ts +10 -6
  80. package/index.js +11 -59
  81. package/index.js.map +1 -1
  82. package/interceptConsole.js +1 -8
  83. package/interceptConsole.js.map +1 -1
  84. package/package.json +23 -26
  85. package/plugins/GraphQLSchemaPlugin.d.ts +7 -3
  86. package/plugins/GraphQLSchemaPlugin.js +11 -12
  87. package/plugins/GraphQLSchemaPlugin.js.map +1 -1
  88. package/plugins/index.d.ts +1 -1
  89. package/plugins/index.js +1 -16
  90. package/plugins/index.js.map +1 -1
  91. package/processRequestBody.d.ts +4 -4
  92. package/processRequestBody.js +10 -10
  93. package/processRequestBody.js.map +1 -1
  94. package/responses.js +5 -16
  95. package/responses.js.map +1 -1
  96. package/types.d.ts +20 -13
  97. package/types.js +1 -5
  98. package/types.js.map +1 -1
  99. package/utils/index.d.ts +1 -0
  100. package/utils/index.js +3 -0
  101. package/utils/index.js.map +1 -0
  102. package/utils/resolve.d.ts +21 -0
  103. package/utils/resolve.js +19 -0
  104. package/utils/resolve.js.map +1 -0
@@ -1,36 +1,29 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.TimeScalar = void 0;
8
- var _graphql = require("graphql");
9
- var _error = _interopRequireDefault(require("@webiny/error"));
1
+ import { GraphQLScalarType } from "graphql";
2
+ import WebinyError from "@webiny/error";
10
3
  const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
11
4
  const parseTime = value => {
12
- if (!value || value.match(re) === null) {
13
- throw new _error.default("Value does not look like time.", "TIME_VALIDATION_ERROR", {
5
+ if (typeof value !== "string" || !value || value.match(re) === null) {
6
+ throw new WebinyError("Value does not look like time.", "TIME_VALIDATION_ERROR", {
14
7
  value
15
8
  });
16
9
  }
17
10
  const parsed = value.split(":").map(Number);
18
11
  if (parsed.length < 2) {
19
- throw new _error.default(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
12
+ throw new WebinyError(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
20
13
  value
21
14
  });
22
15
  }
23
16
  const [hours, minutes, seconds = 0] = parsed;
24
17
  if (hours >= 24) {
25
- throw new _error.default(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
18
+ throw new WebinyError(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
26
19
  value
27
20
  });
28
21
  } else if (minutes >= 60) {
29
- throw new _error.default(`There cannot be more than 59 minutes.`, "TIME_VALIDATION_ERROR", {
22
+ throw new WebinyError(`There cannot be more than 59 minutes.`, "TIME_VALIDATION_ERROR", {
30
23
  value
31
24
  });
32
25
  } else if (seconds >= 60) {
33
- throw new _error.default(`There cannot be more than 59 seconds.`, "TIME_VALIDATION_ERROR", {
26
+ throw new WebinyError(`There cannot be more than 59 seconds.`, "TIME_VALIDATION_ERROR", {
34
27
  value
35
28
  });
36
29
  }
@@ -48,7 +41,7 @@ const convertToTime = value => {
48
41
  } = parseTime(value);
49
42
  return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
50
43
  };
51
- const TimeScalar = exports.TimeScalar = new _graphql.GraphQLScalarType({
44
+ export const TimeScalar = new GraphQLScalarType({
52
45
  name: "Time",
53
46
  description: "A custom type to support time-only input.",
54
47
  // sending to client
@@ -1 +1 @@
1
- {"version":3,"names":["_graphql","require","_error","_interopRequireDefault","re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","exports","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: string) => {\n if (!value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: string): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAc,IAAK;EAClC,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACpC,MAAM,IAAII,cAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEF;IAAM,CAAC,CAAC;EAC/F;EACA,MAAMG,MAAM,GAAGH,KAAK,CAACI,KAAK,CA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AE,2CAA2C;EACxD;EACAC,SAAS,EAAER,aAAa;EACxB;EACAS,UAAU,EAAET;AAChB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["GraphQLScalarType","WebinyError","re","parseTime","value","match","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: unknown) => {\n if (typeof value !== \"string\" || !value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: unknown): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,EAAE,GAAG,uCAAuC;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,CAAC,IAAID,MAAM,CAACH,OAAO,CAAC,CAACI,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAID,MAAM,CAClFF,OACJ,CAAC,CAACG,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;AACxB,CAAC;AAED,OAAO,MAAMC,UAAU,GAAG,IAAIjB,iBAAiB,CAAC;EAC5CkB,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2CAA2C;EACxD;EACAC,SAAS,EAAEN,aAAa;EACxB;EACAO,UAAU,EAAEP;AAChB,CAAC,CAAC","ignoreList":[]}
@@ -1,9 +1,10 @@
1
- export * from "./AnyScalar";
2
- export * from "./DateScalar";
3
- export * from "./DateTimeScalar";
4
- export * from "./DateTimeZScalar";
5
- export * from "./JsonScalar";
6
- export * from "./LongScalar";
7
- export * from "./NumberScalar";
8
- export * from "./RefInputScalar";
9
- export * from "./TimeScalar";
1
+ export * from "./AnyScalar.js";
2
+ export * from "./DateScalar.js";
3
+ export * from "./DateTimeScalar.js";
4
+ export * from "./DateTimeZScalar.js";
5
+ export * from "./JsonScalar.js";
6
+ export * from "./LongScalar.js";
7
+ export * from "./NumberScalar.js";
8
+ export * from "./RefInputScalar.js";
9
+ export * from "./TimeScalar.js";
10
+ export * from "./IconScalar.js";
@@ -1,106 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _AnyScalar = require("./AnyScalar");
7
- Object.keys(_AnyScalar).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _AnyScalar[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _AnyScalar[key];
14
- }
15
- });
16
- });
17
- var _DateScalar = require("./DateScalar");
18
- Object.keys(_DateScalar).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _DateScalar[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _DateScalar[key];
25
- }
26
- });
27
- });
28
- var _DateTimeScalar = require("./DateTimeScalar");
29
- Object.keys(_DateTimeScalar).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _DateTimeScalar[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _DateTimeScalar[key];
36
- }
37
- });
38
- });
39
- var _DateTimeZScalar = require("./DateTimeZScalar");
40
- Object.keys(_DateTimeZScalar).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _DateTimeZScalar[key];
47
- }
48
- });
49
- });
50
- var _JsonScalar = require("./JsonScalar");
51
- Object.keys(_JsonScalar).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _JsonScalar[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _JsonScalar[key];
58
- }
59
- });
60
- });
61
- var _LongScalar = require("./LongScalar");
62
- Object.keys(_LongScalar).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _LongScalar[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _LongScalar[key];
69
- }
70
- });
71
- });
72
- var _NumberScalar = require("./NumberScalar");
73
- Object.keys(_NumberScalar).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _NumberScalar[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _NumberScalar[key];
80
- }
81
- });
82
- });
83
- var _RefInputScalar = require("./RefInputScalar");
84
- Object.keys(_RefInputScalar).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _RefInputScalar[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _RefInputScalar[key];
91
- }
92
- });
93
- });
94
- var _TimeScalar = require("./TimeScalar");
95
- Object.keys(_TimeScalar).forEach(function (key) {
96
- if (key === "default" || key === "__esModule") return;
97
- if (key in exports && exports[key] === _TimeScalar[key]) return;
98
- Object.defineProperty(exports, key, {
99
- enumerable: true,
100
- get: function () {
101
- return _TimeScalar[key];
102
- }
103
- });
104
- });
1
+ export * from "./AnyScalar.js";
2
+ export * from "./DateScalar.js";
3
+ export * from "./DateTimeScalar.js";
4
+ export * from "./DateTimeZScalar.js";
5
+ export * from "./JsonScalar.js";
6
+ export * from "./LongScalar.js";
7
+ export * from "./NumberScalar.js";
8
+ export * from "./RefInputScalar.js";
9
+ export * from "./TimeScalar.js";
10
+ export * from "./IconScalar.js";
105
11
 
106
12
  //# sourceMappingURL=index.js.map
@@ -1 +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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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","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar.js\";\nexport * from \"./DateScalar.js\";\nexport * from \"./DateTimeScalar.js\";\nexport * from \"./DateTimeZScalar.js\";\nexport * from \"./JsonScalar.js\";\nexport * from \"./LongScalar.js\";\nexport * from \"./NumberScalar.js\";\nexport * from \"./RefInputScalar.js\";\nexport * from \"./TimeScalar.js\";\nexport * from \"./IconScalar.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { PluginCollection } from "@webiny/plugins/types";
2
- import { HandlerGraphQLOptions } from "./types";
3
- declare const _default: (options?: HandlerGraphQLOptions) => PluginCollection;
1
+ import type { Plugin } from "@webiny/plugins/types.js";
2
+ import type { HandlerGraphQLOptions } from "./types.js";
3
+ declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
4
4
  export default _default;
@@ -1,46 +1,30 @@
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 = require("./processRequestBody");
1
+ import { boolean } from "boolean";
2
+ import { RoutePlugin } from "@webiny/handler";
3
+ import WebinyError 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";
14
8
  const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
15
9
 
16
10
  const createCacheKey = context => {
17
- const plugins = (0, _createGraphQLSchema.getSchemaPlugins)(context);
11
+ const plugins = getSchemaPlugins(context);
18
12
  // TODO: in the near future, we have to assign a fixed name to every
19
13
  // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
20
14
 
21
15
  // TODO: `getCurrentTenant` should be injected as a parameter.
22
16
  // @ts-expect-error TODO: We should not be accessing `context` like this here.
23
17
  const tenant = context.tenancy?.getCurrentTenant();
24
-
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;
18
+ return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()].filter(Boolean).join("#");
36
19
  };
37
20
  const formatErrorPayload = error => {
38
- if (error instanceof _error.default) {
21
+ if (error instanceof WebinyError) {
39
22
  return JSON.stringify({
40
23
  type: "CoreGraphQLWebinyError",
41
24
  message: error.message,
42
25
  code: error.code,
43
- data: error.data
26
+ data: error.data,
27
+ stack: error.stack
44
28
  });
45
29
  }
46
30
  return JSON.stringify({
@@ -50,12 +34,12 @@ const formatErrorPayload = error => {
50
34
  stack: error.stack
51
35
  });
52
36
  };
53
- var _default = (options = {}) => {
37
+ export default (options = {}) => {
54
38
  let schema = undefined;
55
39
  let cacheKey = undefined;
56
- const debug = (0, _boolean.boolean)(options.debug);
40
+ const debug = boolean(options.debug);
57
41
  const path = options?.path || "/graphql";
58
- const route = new _handler.RoutePlugin(async ({
42
+ const route = new RoutePlugin(async ({
59
43
  onPost,
60
44
  onOptions,
61
45
  context
@@ -69,7 +53,7 @@ var _default = (options = {}) => {
69
53
  const contextCacheKey = createCacheKey(context);
70
54
  if (!schema || cacheKey !== contextCacheKey) {
71
55
  try {
72
- schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
56
+ schema = await createGraphQLSchema(context);
73
57
  cacheKey = contextCacheKey;
74
58
  } catch (ex) {
75
59
  return reply.code(500).send(formatErrorPayload(ex));
@@ -84,7 +68,14 @@ var _default = (options = {}) => {
84
68
  throw ex;
85
69
  }
86
70
  try {
87
- const result = await (0, _processRequestBody.processRequestBody)(body, schema, context);
71
+ const result = await processRequestBody(body, schema, context);
72
+ /**
73
+ * IMPORTANT! Do not send anything if reply was already sent.
74
+ */
75
+ if (reply.sent) {
76
+ console.warn("Reply already sent, cannot send the result (handler-graphql).");
77
+ return reply;
78
+ }
88
79
  return reply.status(200).send(result);
89
80
  } catch (ex) {
90
81
  console.error(`Error while processing the body request.`);
@@ -94,10 +85,9 @@ var _default = (options = {}) => {
94
85
  });
95
86
  });
96
87
  route.name = "handler.graphql.route.default";
97
- return [...(debug ? (0, _debugPlugins.default)() : []), {
88
+ return [...(debug ? debugPlugins() : []), {
98
89
  type: "wcp-telemetry-tracker"
99
90
  }, route];
100
91
  };
101
- exports.default = _default;
102
92
 
103
93
  //# sourceMappingURL=createGraphQLHandler.js.map
@@ -1 +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","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 { Context } from \"@webiny/handler\";\nimport { 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 = {}): 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;AAIA,IAAA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CAAC+B,OAAO,CAAC9B,IAAI,CAAC;MAC1C,CAAC,CAAC,OAAOiC,EAAE,EAAE;QACTC,OAAO,CAAC9B,KAAK,CAAE,wCAAuC,CAAC;QACvD8B,OAAO,CAAC9B,KAAK,CAACD,kBAAkB,CAAC8B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;MACA,IAAI;QACA,MAAME,MAAM,GAAG,MAAM,IAAAC,sCAAkB,EAACpC,IAAI,EAAEc,MAAM,EAAE/B,OAAO,CAAC;QAC9D,OAAO0C,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC9B,KAAK,CAAE,0CAAyC,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,IAAAoB,qBAAY,EAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACI9B,IAAI,EAAE;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAAkB,OAAA,CAAAC,OAAA,GAAA3B,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["boolean","RoutePlugin","WebinyError","createGraphQLSchema","getSchemaPlugins","debugPlugins","processRequestBody","createRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","tenant","tenancy","getCurrentTenant","id","length","toString","filter","Boolean","join","formatErrorPayload","error","JSON","stringify","type","message","code","data","stack","name","options","schema","undefined","cacheKey","debug","path","route","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","ex","body","console","result","sent","warn"],"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.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 = 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 = 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"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAGjC,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,mBAAmB,EAAEC,gBAAgB;AAC9C,OAAOC,YAAY;AACnB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAE1B,MAAMC,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAGP,gBAAgB,CAACM,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAME,MAAM,GAAGF,OAAO,CAACG,OAAO,EAAEC,gBAAgB,CAAC,CAAC;EAElD,OAAO,CAACF,MAAM,GAAG,UAAUA,MAAM,CAACG,EAAE,EAAE,GAAG,IAAI,EAAEJ,OAAO,CAACK,MAAM,CAACC,QAAQ,CAAC,CAAC,CAAC,CACpEC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAMC,kBAAkB,GAAIC,KAAY,IAAa;EACjD,IAAIA,KAAK,YAAYpB,WAAW,EA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List":[]}
@@ -1,4 +1,4 @@
1
- import { GraphQLSchemaPlugin } from "./types";
2
- import { Context } from "@webiny/api/types";
3
- export declare const getSchemaPlugins: (context: Context) => GraphQLSchemaPlugin<Context>[];
4
- 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,28 +1,28 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
8
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
- var _schema = require("@graphql-tools/schema");
10
- var _builtInTypes = require("./builtInTypes");
11
- const getSchemaPlugins = context => {
12
- return context.plugins.byType("graphql-schema");
1
+ import gql from "graphql-tag";
2
+ import { makeExecutableSchema } from "@graphql-tools/schema";
3
+ import { mergeResolvers } from "@graphql-tools/merge";
4
+ import { RefInputScalar, NumberScalar, AnyScalar, DateScalar, DateTimeScalar, JsonScalar, TimeScalar, LongScalar, IconScalar } 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
+ export const getSchemaPlugins = context => {
9
+ return context.plugins.byType("graphql-schema").filter(pl => {
10
+ if (typeof pl.isApplicable === "function") {
11
+ return pl.isApplicable(context);
12
+ }
13
+ return true;
14
+ });
13
15
  };
14
- exports.getSchemaPlugins = getSchemaPlugins;
15
- const createGraphQLSchema = context => {
16
+ export const createGraphQLSchema = async context => {
17
+ GraphQLSchemaComposerFeature.register(context.container);
16
18
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
17
-
18
- // TODO: once the API packages more closed, we'll have the opportunity
19
- // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
20
- const typeDefs = [(0, _graphqlTag.default)`
19
+ const typeDefs = [gql`
21
20
  type Query
22
21
  type Mutation
23
22
  ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
24
23
  scalar JSON
25
24
  scalar Long
25
+ scalar Icon
26
26
  scalar RefInput
27
27
  scalar Number
28
28
  scalar Any
@@ -30,42 +30,69 @@ const createGraphQLSchema = context => {
30
30
  scalar DateTime
31
31
  scalar Time
32
32
 
33
- # This directive doesn't do anything on the GraphQL resolution level. It just serves
34
- # as a way to tell the Prerendering Service whether the GraphQL query needs to be
35
- # cached or not.
36
- directive @ps(cache: Boolean) on QUERY
33
+ type Error {
34
+ code: String
35
+ message: String
36
+ data: JSON
37
+ stack: String
38
+ }
39
+
40
+ type BooleanResponse {
41
+ data: Boolean
42
+ error: Error
43
+ }
37
44
  `];
38
45
  const resolvers = [{
39
46
  ...scalars.reduce((acc, s) => {
40
47
  acc[s.name] = s;
41
48
  return acc;
42
49
  }, {}),
43
- JSON: _builtInTypes.JsonScalar,
44
- Long: _builtInTypes.LongScalar,
45
- RefInput: _builtInTypes.RefInputScalar,
46
- Number: _builtInTypes.NumberScalar,
47
- Any: _builtInTypes.AnyScalar,
48
- DateTime: _builtInTypes.DateTimeScalar,
49
- Date: _builtInTypes.DateScalar,
50
- Time: _builtInTypes.TimeScalar
50
+ JSON: JsonScalar,
51
+ Long: LongScalar,
52
+ RefInput: RefInputScalar,
53
+ Number: NumberScalar,
54
+ Any: AnyScalar,
55
+ DateTime: DateTimeScalar,
56
+ Date: DateScalar,
57
+ Time: TimeScalar,
58
+ Icon: IconScalar
51
59
  }];
60
+ const resolverDecoration = new ResolverDecoration();
61
+
62
+ // Process legacy plugins
52
63
  const plugins = getSchemaPlugins(context);
53
64
  for (const plugin of plugins) {
54
- /**
55
- * TODO @ts-refactor
56
- * Figure out correct types on typeDefs and resolvers
57
- */
58
- // @ts-expect-error
59
- typeDefs.push(plugin.schema.typeDefs);
60
- // @ts-expect-error
61
- resolvers.push(plugin.schema.resolvers);
65
+ const schema = plugin.schema;
66
+ if (schema.typeDefs) {
67
+ typeDefs.push(schema.typeDefs);
68
+ }
69
+ if (schema.resolvers) {
70
+ resolvers.push(schema.resolvers);
71
+ }
72
+ if (schema.resolverDecorators) {
73
+ resolverDecoration.addDecorators(schema.resolverDecorators);
74
+ }
62
75
  }
63
- return (0, _schema.makeExecutableSchema)({
76
+
77
+ // Process new DI implementations
78
+ const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);
79
+ const schema = await graphQLSchemaComposer.build();
80
+ if (schema.typeDefs) {
81
+ typeDefs.push(schema.typeDefs);
82
+ }
83
+ if (schema.resolvers) {
84
+ resolvers.push(schema.resolvers);
85
+ }
86
+ if (schema.resolverDecorators) {
87
+ resolverDecoration.addDecorators(schema.resolverDecorators);
88
+ }
89
+
90
+ // Create executable schema
91
+ return makeExecutableSchema({
64
92
  typeDefs,
65
- resolvers,
93
+ resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
66
94
  inheritResolversFromInterfaces: true
67
95
  });
68
96
  };
69
- exports.createGraphQLSchema = createGraphQLSchema;
70
97
 
71
98
  //# sourceMappingURL=createGraphQLSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_builtInTypes","getSchemaPlugins","context","plugins","byType","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","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-expect-error\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-expect-error\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n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,gBAAgB,CAACC,OAAO,CAAC;EACzC,KAAK,MAAMiC,MAAM,IAAIhC,OAAO,EAAE;IAC1B;AACR;AACA;AACA;IACQ;IACAQ,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;AAAClC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["gql","makeExecutableSchema","mergeResolvers","RefInputScalar","NumberScalar","AnyScalar","DateScalar","DateTimeScalar","JsonScalar","TimeScalar","LongScalar","IconScalar","ResolverDecoration","GraphQLSchemaComposer","GraphQLSchemaComposerFeature","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","createGraphQLSchema","register","container","scalars","map","item","scalar","typeDefs","name","join","resolvers","reduce","acc","s","JSON","Long","RefInput","Number","Any","DateTime","Date","Time","Icon","resolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","graphQLSchemaComposer","resolve","build","decorateResolvers","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.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"],"mappings":"AAAA,OAAOA,GAAG,MAAM,aAAa;AAC7B,SAASC,oBAAoB,QAAQ,uBAAuB;AAC5D,SAASC,cAAc,QAAQ,sBAAsB;AAIrD,SACIC,cAAc,EACdC,YAAY,EACZC,SAAS,EACTC,UAAU,EACVC,cAAc,EACdC,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,UAAU;AAEd,SAASC,kBAAkB;AAE3B,SAASC,qBAAqB;AAC9B,SAASC,4BAA4B;AAErC,OAAO,MAAMC,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,OAAOD,EAAE,CAACC,YAAY,CAACL,OAAO,CAAC;IACnC;IACA,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMM,mBAAmB,GAAG,MAAON,OAAgB,IAAK;EAC3DF,4BAA4B,CAACS,QAAQ,CAACP,OAAO,CAACQ,SAAS,CAAC;EAExD,MAAMC,OAAO,GAAGT,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CQ,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;EAE7B,MAAMC,QAAoB,GAAG,CACzB7B,GAAG;AACX;AACA;AACA,cAAcyB,OAAO,CAACC,GAAG,CAACE,MAAM,IAAI,UAAUA,MAAM,CAACE,IAAI,EA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,OAAO,CAACvC,qBAAqB,CAAC;EAC9E,MAAMkC,MAAM,GAAG,MAAMI,qBAAqB,CAACE,KAAK,CAAC,CAAC;EAElD,IAAIN,MAAM,CAAClB,QAAQ,EAAE;IACjBA,QAAQ,CAACmB,IAAI,CAACD,MAAM,CAAClB,QAAQ,CAAC;EAClC;EACA,IAAIkB,MAAM,CAACf,SAAS,EAAE;IAClBA,SAAS,CAACgB,IAAI,CAACD,MAAM,CAACf,SAAS,CAAC;EACpC;EACA,IAAIe,MAAM,CAACE,kBAAkB,EAAE;IAC3BJ,kBAAkB,CAACK,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;EAC/D;;EAEA;EACA,OAAOhD,oBAAoB,CAAC;IACxB4B,QAAQ;IACRG,SAAS,EAAEa,kBAAkB,CAACS,iBAAiB,CAACpD,cAAc,CAAC8B,SAAS,CAAC,CAAC;IAC1EuB,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { GraphQLRequestBody } from "./types.js";
2
+ export declare const createRequestBody: (input: unknown) => GraphQLRequestBody | GraphQLRequestBody[];
@@ -0,0 +1,26 @@
1
+ import zod from "zod";
2
+ import { WebinyError } from "@webiny/error";
3
+ import { createZodError } from "@webiny/utils/createZodError.js";
4
+ const requestBodySchema = zod.object({
5
+ query: zod.string(),
6
+ variables: zod.record(zod.any()).nullish().optional(),
7
+ operationName: zod.string().nullish().optional().transform(value => {
8
+ return value || undefined;
9
+ })
10
+ }).passthrough();
11
+ const schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);
12
+ export const createRequestBody = input => {
13
+ const body = typeof input === "string" ? JSON.parse(input) : input;
14
+ const result = schema.safeParse(body);
15
+ if (!result.success) {
16
+ const error = createZodError(result.error);
17
+ throw new WebinyError({
18
+ message: "Invalid GraphQL request! Check your query and variables.",
19
+ code: "GRAPHQL_REQUEST_INVALID",
20
+ data: error.data
21
+ });
22
+ }
23
+ return result.data;
24
+ };
25
+
26
+ //# sourceMappingURL=createRequestBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["zod","WebinyError","createZodError","requestBodySchema","object","query","string","variables","record","any","nullish","optional","operationName","transform","value","undefined","passthrough","schema","union","array","createRequestBody","input","body","JSON","parse","result","safeParse","success","error","message","code","data"],"sources":["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\n .object({\n query: zod.string(),\n variables: zod.record(zod.any()).nullish().optional(),\n operationName: zod\n .string()\n .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n })\n })\n .passthrough();\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"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,cAAc,QAAQ,iCAAiC;AAGhE,MAAMC,iBAAiB,GAAGH,GAAG,CACxBI,MAAM,CAAC;EACJC,KAAK,EAAEL,GAAG,CAACM,MAAM,CAAC,CAAC;EACnBC,SAAS,EAAEP,GAAG,CAACQ,MAAM,CAACR,GAAG,CAACS,GAAG,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACrDC,aAAa,EAAEZ,GAAG,CACbM,MAAM,CAAC,CAAC,CACRI,OAAO,CAAC,CAAC,CACTC,QAAQ,CAAC,CAAC,CACVE,SAAS,CAACC,KAAK,I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