@webiny/handler-graphql 6.0.0-alpha.5 → 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 +1 -1
  3. package/ResolverDecoration.js +3 -10
  4. package/ResolverDecoration.js.map +1 -1
  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 +2 -2
  39. package/createGraphQLHandler.js +18 -35
  40. package/createGraphQLHandler.js.map +1 -1
  41. package/createGraphQLSchema.d.ts +4 -4
  42. package/createGraphQLSchema.js +41 -36
  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 +1 -1
  48. package/createResolverDecorator.js +1 -8
  49. package/createResolverDecorator.js.map +1 -1
  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 +9 -9
  80. package/index.js +10 -96
  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 -23
  85. package/plugins/GraphQLSchemaPlugin.d.ts +2 -2
  86. package/plugins/GraphQLSchemaPlugin.js +3 -11
  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 +3 -3
  92. package/processRequestBody.js +3 -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 +6 -6
  97. package/types.js +1 -5
  98. package/types.js.map +1 -1
  99. package/utils/index.d.ts +1 -1
  100. package/utils/index.js +1 -16
  101. package/utils/index.js.map +1 -1
  102. package/utils/resolve.d.ts +2 -2
  103. package/utils/resolve.js +8 -17
  104. package/utils/resolve.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["_graphql","require","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","exports","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EAAE,oBAAoB;EACxBC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,CACJ;AAED,MAAMC,SAAS,GAAIC,KAAU,IAAa;EACtC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MA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AACf,MAAM,EAAEc,CAAC,EAAE,EAAE;QACxC,MAAM;UAAER,IAAI;UAAEP;QAAM,CAAC,GAAGa,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACP,KAAK,KAAK,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["GraphQLScalarType","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n /**\n * We can set value as any because we are handling it.\n */\n parseValue: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAE3C,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EAAE,oBAAoB;EACxBC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,CACJ;AAED,MAAMC,SAAS,GAAIC,KAAU,IAAa;EACtC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;EAClE;EACA,KAAK,MAAMC,IAAI,IAAIP,KAAK,EAAE;IACtB,IAAIO,IAAI,CAACN,EAAE,CAACM,IAAI,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC9B,MAAM,IAAIE,KAAK,CAACC,IAAI,CAACL,OAAO,CAAC;IACjC;EACJ;EACA,OAAOE,KAAK;AAChB,CAAC;AAED,OAAO,MAAMI,cAAc,GAAG,IAAIT,iBAAiB,CAAC;EAChDU,IAAI,EAAE,UAAU;EAChBC,WAAW,EACP,oGAAoG;EACxG;AACJ;AACA;EACIC,SAAS,EAAGP,KAAU,IAAK;IACvB,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACQ,EAAE,KAAK,IAAI,EAAE;MAC7B,OAAO,IAAI;IACf;IAEA,OAAO,OAAOR,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGA,KAAK,CAACQ,EAAE;EACvD,CAAC;EACD;AACJ;AACA;EACIC,UAAU,EAAGT,KAAU,IAAK;IACxB,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACQ,EAAE,KAAK,IAAI,EAAE;MAC7B,OAAO,IAAI;IACf;IAEA,IAAI,OAAOR,KAAK,KAAK,QAAQ,EAAE;MAC3B,OAAOD,SAAS,CAACC,KAAK,CAAC;IAC3B;IAEA,IAAI,IAAI,IAAIA,KAAK,EAAE;MACf,OAAOD,SAAS,CAACC,KAAK,CAACQ,EAAE,CAAC;IAC9B;IAEA,MAAM,IAAIN,KAAK,CAAC,yBAAyB,CAAC;EAC9C,CAAC;EACDQ,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,OAAOb,SAAS,CAACY,GAAG,CAACX,KAAK,CAAC;IAC/B;IAEA,IAAIW,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,GAAG,CAACG,MAAM,CAACb,MAAM,EAAEY,CAAC,EAAE,EAAE;QACxC,MAAM;UAAER,IAAI;UAAEL;QAAM,CAAC,GAAGW,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACL,KAAK,KAAK,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
1
  import { GraphQLScalarType } from "graphql";
2
- export declare const TimeScalar: GraphQLScalarType;
2
+ export declare const TimeScalar: GraphQLScalarType<string, string>;
@@ -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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Q,CAAC,GAAGX,SAAS,CAACC,KAAK,CAAC;EACpD,OAAO,GAAGY,MAAM,CAACJ,KAAK,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,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;AAEM,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5CC,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,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;AAElD,MAAMC,SAAS,GAAIC,KAAe,IAAK;EACnC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACjE,MAAM,IAAID,WAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEG;IAAM,CAAC,CAAC;EAC/F;EACA,MAAME,MAAM,GAAGF,KAAK,CAACG,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAC3C,IAAIH,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;IACnB,MAAM,IAAIT,WAAW,CAAC,4BAA4B,EAAE,uBAAuB,EAAE;MAAEG;IAAM,CAAC,CAAC;EAC3F;EACA,MAAM,CAACO,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGP,MAAM;EAC5C,IAAIK,KAAK,IAAI,EAAE,EAAE;IACb,MAAM,IAAIV,WAAW,CAAC,qCAAqC,EAAE,uBAAuB,EAAE;MAClFG;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIQ,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIX,WAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFG;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIS,OAAO,IAAI,EAAE,EAAE;IACtB,MAAM,IAAIZ,WAAW,CAAC,uCAAuC,EAAE,uBAAuB,EAAE;MACpFG;IACJ,CAAC,CAAC;EACN;EACA,OAAO;IACHO,KAAK;IACLC,OAAO;IACPC;EACJ,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAIV,KAAc,IAAa;EAC9C,MAAM;IAAEO,KAAK;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGV,SAAS,CAACC,KAAK,CAAC;EACpD,OAAO,GAAGW,MAAM,CAACJ,KAAK,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,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 *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D,GAAA,MAAAU,aAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,aAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,eAAA,GAAAf,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAa,eAAA,EAAAZ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAW,eAAA,CAAAX,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAO,eAAA,CAAAX,GAAA;IAAA;EAAA;AAAA;AACA,IAAAY,WAAA,GAAAhB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAc,WAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAY,WAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,WAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA","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 type { Plugin } from "@webiny/plugins/types";
2
- import type { HandlerGraphQLOptions } from "./types";
1
+ import type { Plugin } from "@webiny/plugins/types.js";
2
+ import type { HandlerGraphQLOptions } from "./types.js";
3
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,7 @@ 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);
88
72
  /**
89
73
  * IMPORTANT! Do not send anything if reply was already sent.
90
74
  */
@@ -101,10 +85,9 @@ var _default = (options = {}) => {
101
85
  });
102
86
  });
103
87
  route.name = "handler.graphql.route.default";
104
- return [...(debug ? (0, _debugPlugins.default)() : []), {
88
+ return [...(debug ? debugPlugins() : []), {
105
89
  type: "wcp-telemetry-tracker"
106
90
  }, route];
107
91
  };
108
- exports.default = _default;
109
92
 
110
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","sent","warn","debugPlugins","exports","default"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type { Context } from \"@webiny/handler\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin } from \"@webiny/plugins/types\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler-graphql).\");\n return reply;\n }\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AAEA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAMG,MAAM,GAAGH,OAAO,CAACI,OAAO,EAAEC,gBAAgB,CAAC,CAAC;;EAElD;EACA;EACA,MAAMC,aAAa,GAAGN,OAAO,CAACO,IAAI,EAAEC,gBAAgB,CAAC,CAAC;EAEtD,OAAO,CACHL,MAAM,GAAG,UAAUA,MAAM,CAACM,EAAE,EAAE,GAAG,IAAI,EACrCH,aAAa,GAAG,UAAUA,aAAa,CAACI,IAAI,EAAE,GAAG,IAAI,EACrDT,OAAO,CAACU,MAAM,CAACC,QAAQ,CAAC,CAAC,CAC5B,CACIC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAMC,iBAAiB,GAAIC,IAAa,IAAgD;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAED,MAAMG,kBAAkB,GAAI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;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAAoB,OAAA,CAAAC,OAAA,GAAA7B,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,CA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AAOA,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOH,EAAE,EAAE;QACTE,OAAO,CAAC5B,KAAK,CAAC,0CAA0C,CAAC;QACzD4B,OAAO,CAAC5B,KAAK,CAACD,kBAAkB,CAAC2B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFX,KAAK,CAACP,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIK,KAAK,GAAG9B,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACIoB,IAAI,EAAE;EACV,CAAC,EACDY,KAAK,CACR;AACL,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { Context } from "@webiny/api/types";
2
- import type { GraphQLSchemaPlugin } from "./plugins";
3
- export declare const getSchemaPlugins: (context: Context) => import("@webiny/plugins/PluginsContainer").WithName<GraphQLSchemaPlugin<Context>>[];
4
- export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
1
+ 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,16 +1,11 @@
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 _merge = require("@graphql-tools/merge");
11
- var _builtInTypes = require("./builtInTypes");
12
- var _ResolverDecoration = require("./ResolverDecoration");
13
- const getSchemaPlugins = context => {
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 => {
14
9
  return context.plugins.byType("graphql-schema").filter(pl => {
15
10
  if (typeof pl.isApplicable === "function") {
16
11
  return pl.isApplicable(context);
@@ -18,18 +13,16 @@ const getSchemaPlugins = context => {
18
13
  return true;
19
14
  });
20
15
  };
21
- exports.getSchemaPlugins = getSchemaPlugins;
22
- const createGraphQLSchema = context => {
16
+ export const createGraphQLSchema = async context => {
17
+ GraphQLSchemaComposerFeature.register(context.container);
23
18
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
24
-
25
- // TODO: once the API packages are more closed, we'll have the opportunity
26
- // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
27
- const typeDefs = [(0, _graphqlTag.default)`
19
+ const typeDefs = [gql`
28
20
  type Query
29
21
  type Mutation
30
22
  ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
31
23
  scalar JSON
32
24
  scalar Long
25
+ scalar Icon
33
26
  scalar RefInput
34
27
  scalar Number
35
28
  scalar Any
@@ -37,11 +30,6 @@ const createGraphQLSchema = context => {
37
30
  scalar DateTime
38
31
  scalar Time
39
32
 
40
- # This directive doesn't do anything on the GraphQL resolution level. It just serves
41
- # as a way to tell the Prerendering Service whether the GraphQL query needs to be
42
- # cached or not.
43
- directive @ps(cache: Boolean) on QUERY
44
-
45
33
  type Error {
46
34
  code: String
47
35
  message: String
@@ -59,16 +47,19 @@ const createGraphQLSchema = context => {
59
47
  acc[s.name] = s;
60
48
  return acc;
61
49
  }, {}),
62
- JSON: _builtInTypes.JsonScalar,
63
- Long: _builtInTypes.LongScalar,
64
- RefInput: _builtInTypes.RefInputScalar,
65
- Number: _builtInTypes.NumberScalar,
66
- Any: _builtInTypes.AnyScalar,
67
- DateTime: _builtInTypes.DateTimeScalar,
68
- Date: _builtInTypes.DateScalar,
69
- 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
70
59
  }];
71
- const resolverDecoration = new _ResolverDecoration.ResolverDecoration();
60
+ const resolverDecoration = new ResolverDecoration();
61
+
62
+ // Process legacy plugins
72
63
  const plugins = getSchemaPlugins(context);
73
64
  for (const plugin of plugins) {
74
65
  const schema = plugin.schema;
@@ -82,12 +73,26 @@ const createGraphQLSchema = context => {
82
73
  resolverDecoration.addDecorators(schema.resolverDecorators);
83
74
  }
84
75
  }
85
- 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({
86
92
  typeDefs,
87
- resolvers: resolverDecoration.decorateResolvers((0, _merge.mergeResolvers)(resolvers)),
93
+ resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
88
94
  inheritResolversFromInterfaces: true
89
95
  });
90
96
  };
91
- exports.createGraphQLSchema = createGraphQLSchema;
92
97
 
93
98
  //# sourceMappingURL=createGraphQLSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_merge","_builtInTypes","_ResolverDecoration","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","resolverDecoration","ResolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","makeExecutableSchema","decorateResolvers","mergeResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport type { GraphQLScalarType } from \"graphql/type/definition\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types\";\nimport type { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { ResolverDecoration } from \"./ResolverDecoration\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\").filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n};\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages are more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs: TypeDefs[] = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n\n type Error {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type BooleanResponse {\n data: Boolean\n error: Error\n }\n `\n ];\n\n const resolvers: Resolvers<any>[] = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n const plugins = getSchemaPlugins(context);\n\n for (const plugin of plugins) {\n const schema = plugin.schema;\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAIA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AAGO,MAAMK,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC,CAACC,MAAM,CAACC,EAAE,IAAI;IAC9E,IAAI,OAAOA,EAAE,CAACC,YAAY,KAAK,UAAU,EAAE;MACvC,OAAOD,EAAE,CAACC,YAAY,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AM,GAAGD,MAAM,CAACC,MAAM;IAC5B,IAAIA,MAAM,CAAC3B,QAAQ,EAAE;MACjBA,QAAQ,CAAC4B,IAAI,CAACD,MAAM,CAAC3B,QAAQ,CAAC;IAClC;IACA,IAAI2B,MAAM,CAACvB,SAAS,EAAE;MAClBA,SAAS,CAACwB,IAAI,CAACD,MAAM,CAACvB,SAAS,CAAC;IACpC;IACA,IAAIuB,MAAM,CAACE,kBAAkB,EAAE;MAC3BL,kBAAkB,CAACM,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;IAC/D;EACJ;EAEA,OAAO,IAAAE,4BAAoB,EAAC;IACxB/B,QAAQ;IACRI,SAAS,EAAEoB,kBAAkB,CAACQ,iBAAiB,CAAC,IAAAC,qBAAc,EAAC7B,SAAS,CAAC,CAAC;IAC1E8B,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAACxC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
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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pC;IACA,IAAIe,MAAM,CAACE,kBAAkB,EAAE;MAC3BJ,kBAAkB,CAACK,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;IAC/D;EACJ;;EAEA;EACA,MAAME,qBAAqB,GAAGnC,OAAO,CAACQ,SAAS,CAAC4B,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