@webiny/handler-graphql 0.0.0-mt-3 → 0.0.0-unstable.3386f66516
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.
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +3 -3
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.js +5 -9
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.js +3 -7
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.js +1 -1
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +11 -7
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +3 -3
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.js +1 -1
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.js.map +1 -0
- package/createGraphQLHandler.d.ts +1 -1
- package/createGraphQLHandler.js +68 -46
- package/createGraphQLHandler.js.map +1 -0
- package/createGraphQLSchema.d.ts +2 -3
- package/createGraphQLSchema.js +23 -15
- package/createGraphQLSchema.js.map +1 -0
- package/debugPlugins.d.ts +10 -8
- package/debugPlugins.js +17 -20
- package/debugPlugins.js.map +1 -0
- package/errors.d.ts +2 -2
- package/errors.js +1 -1
- package/errors.js.map +1 -0
- package/index.d.ts +1 -4
- package/index.js +17 -14
- package/index.js.map +1 -0
- package/interceptConsole.d.ts +5 -1
- package/interceptConsole.js +6 -2
- package/interceptConsole.js.map +1 -0
- package/package.json +19 -18
- package/plugins/GraphQLSchemaPlugin.d.ts +2 -2
- package/plugins/GraphQLSchemaPlugin.js +1 -1
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.js.map +1 -0
- package/processRequestBody.d.ts +4 -1
- package/processRequestBody.js +7 -8
- package/processRequestBody.js.map +1 -0
- package/responses.d.ts +20 -18
- package/responses.js +24 -5
- package/responses.js.map +1 -0
- package/types.d.ts +7 -5
- package/types.js.map +1 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const AnyScalar: GraphQLScalarType;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.AnyScalar = void 0;
|
|
7
7
|
|
|
8
8
|
var _graphql = require("graphql");
|
|
9
9
|
|
|
@@ -11,10 +11,10 @@ const returnValue = value => {
|
|
|
11
11
|
return value;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const AnyScalar = new _graphql.GraphQLScalarType({
|
|
15
15
|
name: "Any",
|
|
16
16
|
description: `A scalar type that represents an ambiguous value.`,
|
|
17
17
|
serialize: returnValue,
|
|
18
18
|
parseValue: returnValue
|
|
19
19
|
});
|
|
20
|
-
exports.
|
|
20
|
+
exports.AnyScalar = AnyScalar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["returnValue","value","AnyScalar","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["AnyScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst returnValue = (value: any): any => {\n return value;\n};\n\nexport const AnyScalar = new GraphQLScalarType({\n name: \"Any\",\n description: `A scalar type that represents an ambiguous value.`,\n serialize: returnValue,\n parseValue: returnValue\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,WAAW,GAAIC,KAAD,IAAqB;EACrC,OAAOA,KAAP;AACH,CAFD;;AAIO,MAAMC,SAAS,GAAG,IAAIC,0BAAJ,CAAsB;EAC3CC,IAAI,EAAE,KADqC;EAE3CC,WAAW,EAAG,mDAF6B;EAG3CC,SAAS,EAAEN,WAHgC;EAI3CO,UAAU,EAAEP;AAJ+B,CAAtB,CAAlB"}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.DateScalar = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _graphqlScalars = require("graphql-scalars");
|
|
13
13
|
|
|
14
14
|
var _graphql = require("graphql");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateResolver), {}, {
|
|
16
|
+
const DateScalar = new _graphql.GraphQLScalarType((0, _objectSpread2.default)((0, _objectSpread2.default)({}, _graphqlScalars.DateResolver), {}, {
|
|
21
17
|
serialize: value => {
|
|
22
18
|
if (!value) {
|
|
23
19
|
return null;
|
|
@@ -25,10 +21,10 @@ const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}
|
|
|
25
21
|
|
|
26
22
|
try {
|
|
27
23
|
const date = new Date(value);
|
|
28
|
-
return date.toISOString().
|
|
24
|
+
return date.toISOString().slice(0, 10);
|
|
29
25
|
} catch (ex) {
|
|
30
26
|
if (value.toISOString) {
|
|
31
|
-
return value.toISOString().
|
|
27
|
+
return value.toISOString().slice(0, 10);
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
throw ex;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DateScalar","GraphQLScalarType","DateResolver","serialize","value","date","Date","toISOString","slice","ex"],"sources":["DateScalar.ts"],"sourcesContent":["import { DateResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateScalar = new GraphQLScalarType({\n ...DateResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString().slice(0, 10);\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString().slice(0, 10);\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACO,MAAMA,UAAU,GAAG,IAAIC,0BAAJ,6DACnBC,4BADmB;EAEtBC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAL,EAAY;MACR,OAAO,IAAP;IACH;;IACD,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAJ,CAASF,KAAT,CAAb;MACA,OAAOC,IAAI,CAACE,WAAL,GAAmBC,KAAnB,CAAyB,CAAzB,EAA4B,EAA5B,CAAP;IACH,CAHD,CAGE,OAAOC,EAAP,EAAW;MACT,IAAIL,KAAK,CAACG,WAAV,EAAuB;QACnB,OAAOH,KAAK,CAACG,WAAN,GAAoBC,KAApB,CAA0B,CAA1B,EAA6B,EAA7B,CAAP;MACH;;MACD,MAAMC,EAAN;IACH;EACJ;AAfqB,GAAnB"}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.DateTimeScalar = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _graphqlScalars = require("graphql-scalars");
|
|
13
13
|
|
|
14
14
|
var _graphql = require("graphql");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
const DateTimeScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateTimeResolver), {}, {
|
|
16
|
+
const DateTimeScalar = new _graphql.GraphQLScalarType((0, _objectSpread2.default)((0, _objectSpread2.default)({}, _graphqlScalars.DateTimeResolver), {}, {
|
|
21
17
|
serialize: value => {
|
|
22
18
|
if (!value) {
|
|
23
19
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DateTimeScalar","GraphQLScalarType","DateTimeResolver","serialize","value","date","Date","toISOString","ex"],"sources":["DateTimeScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateTimeScalar = new GraphQLScalarType({\n ...DateTimeResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString();\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString();\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACO,MAAMA,cAAc,GAAG,IAAIC,0BAAJ,6DACvBC,gCADuB;EAE1BC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAL,EAAY;MACR,OAAO,IAAP;IACH;;IACD,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAJ,CAASF,KAAT,CAAb;MACA,OAAOC,IAAI,CAACE,WAAL,EAAP;IACH,CAHD,CAGE,OAAOC,EAAP,EAAW;MACT,IAAIJ,KAAK,CAACG,WAAV,EAAuB;QACnB,OAAOH,KAAK,CAACG,WAAN,EAAP;MACH;;MACD,MAAMC,EAAN;IACH;EACJ;AAfyB,GAAvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["validateTimeZone","value","timeWithTimezone","split","WebinyError","separator","includes","zone","hoursMinutes","hours","minutes","undefined","length","DateTimeZScalar","GraphQLScalarType","name","description","parseValue","DateTimeResolver","serialize"],"sources":["DateTimeZScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst validateTimeZone = (value: string): void => {\n const timeWithTimezone = value.split(\"T\")[1];\n if (!timeWithTimezone) {\n throw new WebinyError(\n \"Could not extract time with timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value\n }\n );\n }\n const separator = timeWithTimezone.includes(\"-\") ? \"-\" : \"+\";\n const zone = timeWithTimezone.split(separator)[1];\n if (!zone) {\n throw new WebinyError(\n \"Could not extract timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: timeWithTimezone\n }\n );\n }\n const hoursMinutes = zone.split(\":\");\n const [hours, minutes] = hoursMinutes;\n if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {\n throw new WebinyError(\n \"Could not extract hours or minutes from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: zone\n }\n );\n }\n};\n/**\n * A custom type for dateTime with the timezone.\n * Must be in format \"YYYY-MM-ddTHH:mm:ss+HH:mm\".\n */\nexport const DateTimeZScalar = new GraphQLScalarType({\n name: \"DateTimeZ\",\n description: \"A custom type for dateTime with the timezone.\",\n parseValue: value => {\n // this serves as validator\n DateTimeResolver.parseValue(value);\n validateTimeZone(value);\n return value;\n },\n serialize: value => {\n return value;\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,gBAAgB,GAAIC,KAAD,IAAyB;EAC9C,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,KAAN,CAAY,GAAZ,EAAiB,CAAjB,CAAzB;;EACA,IAAI,CAACD,gBAAL,EAAuB;IACnB,MAAM,IAAIE,cAAJ,CACF,kDADE,EAEF,0BAFE,EAGF;MACIH;IADJ,CAHE,CAAN;EAOH;;EACD,MAAMI,SAAS,GAAGH,gBAAgB,CAACI,QAAjB,CAA0B,GAA1B,IAAiC,GAAjC,GAAuC,GAAzD;EACA,MAAMC,IAAI,GAAGL,gBAAgB,CAACC,KAAjB,CAAuBE,SAAvB,EAAkC,CAAlC,CAAb;;EACA,IAAI,CAACE,IAAL,EAAW;IACP,MAAM,IAAIH,cAAJ,CACF,wCADE,EAEF,0BAFE,EAGF;MACIH,KAAK,EAAEC;IADX,CAHE,CAAN;EAOH;;EACD,MAAMM,YAAY,GAAGD,IAAI,CAACJ,KAAL,CAAW,GAAX,CAArB;EACA,MAAM,CAACM,KAAD,EAAQC,OAAR,IAAmBF,YAAzB;;EACA,IAAIC,KAAK,KAAKE,SAAV,IAAuBD,OAAO,KAAKC,SAAnC,IAAgDH,YAAY,CAACI,MAAb,KAAwB,CAA5E,EAA+E;IAC3E,MAAM,IAAIR,cAAJ,CACF,gDADE,EAEF,0BAFE,EAGF;MACIH,KAAK,EAAEM;IADX,CAHE,CAAN;EAOH;AACJ,CAjCD;AAkCA;AACA;AACA;AACA;;;AACO,MAAMM,eAAe,GAAG,IAAIC,0BAAJ,CAAsB;EACjDC,IAAI,EAAE,WAD2C;EAEjDC,WAAW,EAAE,+CAFoC;EAGjDC,UAAU,EAAEhB,KAAK,IAAI;IACjB;IACAiB,gCAAA,CAAiBD,UAAjB,CAA4BhB,KAA5B;;IACAD,gBAAgB,CAACC,KAAD,CAAhB;IACA,OAAOA,KAAP;EACH,CARgD;EASjDkB,SAAS,EAAElB,KAAK,IAAI;IAChB,OAAOA,KAAP;EACH;AAXgD,CAAtB,CAAxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["JsonScalar","JSONResolver"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":";;;;;;;AAAA;;AACO,MAAMA,UAAU,GAAGC,4BAAnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LongScalar","LongResolver"],"sources":["LongScalar.ts"],"sourcesContent":["import { LongResolver } from \"graphql-scalars\";\nexport const LongScalar = LongResolver;\n"],"mappings":";;;;;;;AAAA;;AACO,MAAMA,UAAU,GAAGC,4BAAnB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const NumberScalar: GraphQLScalarType;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.NumberScalar = void 0;
|
|
9
9
|
|
|
10
10
|
var _graphql = require("graphql");
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ const parseValue = value => {
|
|
|
31
31
|
return parseFloat(value);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const NumberScalar = new _graphql.GraphQLScalarType({
|
|
35
35
|
name: "Number",
|
|
36
36
|
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
37
37
|
serialize: value => {
|
|
@@ -50,11 +50,15 @@ const Number = new _graphql.GraphQLScalarType({
|
|
|
50
50
|
},
|
|
51
51
|
parseValue,
|
|
52
52
|
parseLiteral: ast => {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const value = ast.value;
|
|
54
|
+
|
|
55
|
+
if (ast.kind === _language.Kind.INT) {
|
|
56
|
+
return Number(value);
|
|
57
|
+
} else if (ast.kind === _language.Kind.FLOAT) {
|
|
58
|
+
return parseFloat(value);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
throw new Error(`Expected type Number, found {${
|
|
61
|
+
throw new Error(`Expected type Number, found {${value}}`);
|
|
58
62
|
}
|
|
59
63
|
});
|
|
60
|
-
exports.
|
|
64
|
+
exports.NumberScalar = NumberScalar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","NumberScalar","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Number","FLOAT","Error"],"sources":["NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).match(/^0x/) !== null) {\n throw new WebinyError(\"Value sent must be a non-hex number.\", \"INVALID_VALUE\", {\n value\n });\n } else if (typeof value === \"number\") {\n return value;\n } else if (value === null || value === undefined) {\n return null;\n } else if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be a number.\", \"INVALID_VALUE\", {\n value\n });\n }\n return parseFloat(value);\n};\n\nexport const NumberScalar = new GraphQLScalarType({\n name: \"Number\",\n description: \"A custom input type to be used with numbers. Supports Int and Float.\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be a number.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n const value = (ast as any).value;\n if (ast.kind === Kind.INT) {\n return Number(value);\n } else if (ast.kind === Kind.FLOAT) {\n return parseFloat(value);\n }\n throw new Error(`Expected type Number, found {${value}}`);\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,UAAU,GAAIC,KAAD,IAAgB;EAC/B,IAAIC,MAAM,CAACD,KAAD,CAAN,CAAcE,KAAd,CAAoB,KAApB,MAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIC,cAAJ,CAAgB,sCAAhB,EAAwD,eAAxD,EAAyE;MAC3EH;IAD2E,CAAzE,CAAN;EAGH,CAJD,MAIO,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAClC,OAAOA,KAAP;EACH,CAFM,MAEA,IAAIA,KAAK,KAAK,IAAV,IAAkBA,KAAK,KAAKI,SAAhC,EAA2C;IAC9C,OAAO,IAAP;EACH,CAFM,MAEA,IAAIC,KAAK,CAACL,KAAD,CAAL,KAAiB,IAArB,EAA2B;IAC9B,MAAM,IAAIG,cAAJ,CAAgB,8BAAhB,EAAgD,eAAhD,EAAiE;MACnEH;IADmE,CAAjE,CAAN;EAGH;;EACD,OAAOM,UAAU,CAACN,KAAD,CAAjB;AACH,CAfD;;AAiBO,MAAMO,YAAY,GAAG,IAAIC,0BAAJ,CAAsB;EAC9CC,IAAI,EAAE,QADwC;EAE9CC,WAAW,EAAE,sEAFiC;EAG9CC,SAAS,EAAGX,KAAD,IAAgB;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAD,CAAjB;IACH,CAFD,CAEE,OAAOY,EAAP,EAAW;MACTC,OAAO,CAACC,GAAR,CAAY;QACRC,OAAO,EAAE,8BADD;QAERC,IAAI,EAAE,eAFE;QAGRC,IAAI,EAAE;UACFjB;QADE;MAHE,CAAZ;MAOA,OAAO,IAAP;IACH;EACJ,CAhB6C;EAiB9CD,UAjB8C;EAkB9CmB,YAAY,EAAEC,GAAG,IAAI;IACjB,MAAMnB,KAAK,GAAImB,GAAD,CAAanB,KAA3B;;IACA,IAAImB,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKC,GAAtB,EAA2B;MACvB,OAAOC,MAAM,CAACvB,KAAD,CAAb;IACH,CAFD,MAEO,IAAImB,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKG,KAAtB,EAA6B;MAChC,OAAOlB,UAAU,CAACN,KAAD,CAAjB;IACH;;IACD,MAAM,IAAIyB,KAAJ,CAAW,gCAA+BzB,KAAM,GAAhD,CAAN;EACH;AA1B6C,CAAtB,CAArB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const RefInputScalar: GraphQLScalarType;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.RefInputScalar = void 0;
|
|
7
7
|
|
|
8
8
|
var _graphql = require("graphql");
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ const isMongoId = value => {
|
|
|
15
15
|
throw new Error("Must be a valid Mongo ID!");
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const RefInputScalar = new _graphql.GraphQLScalarType({
|
|
19
19
|
name: "RefInput",
|
|
20
20
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
21
21
|
serialize: value => {
|
|
@@ -62,4 +62,4 @@ const RefInput = new _graphql.GraphQLScalarType({
|
|
|
62
62
|
throw new Error("Invalid RefInput value!");
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
exports.
|
|
65
|
+
exports.RefInputScalar = RefInputScalar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isMongoId","value","test","Error","RefInputScalar","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields","length"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst isMongoId = (value: any): string => {\n if (/^[0-9a-fA-F]{24}$/.test(value)) {\n return value;\n }\n\n throw new Error(\"Must be a valid Mongo ID!\");\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 isMongoId(value);\n }\n\n if (\"id\" in value) {\n return isMongoId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isMongoId(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-ignore\n return isMongoId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,SAAS,GAAIC,KAAD,IAAwB;EACtC,IAAI,oBAAoBC,IAApB,CAAyBD,KAAzB,CAAJ,EAAqC;IACjC,OAAOA,KAAP;EACH;;EAED,MAAM,IAAIE,KAAJ,CAAU,2BAAV,CAAN;AACH,CAND;;AAQO,MAAMC,cAAc,GAAG,IAAIC,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AAN;EACH;AA1C+C,CAAtB,CAAvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","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;;AACA;;AAEA,MAAMA,EAAE,GAAG,uCAAX;;AAEA,MAAMC,SAAS,GAAIC,KAAD,IAAoB;EAClC,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACC,KAAN,CAAY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GAA5B,CAAiC,IAAGD,MAAM,CAClFF,OADkF,CAAN,CAE9EG,QAF8E,CAErE,CAFqE,EAElE,GAFkE,CAE7D,EAFnB;AAGH,CALD;;AAOO,MAAMC,UAAU,GAAG,IAAIC,0BAAJ,CAAsB;EAC5CC,IAAI,EAAE,MADsC;EAE5CC,WAAW,EAAE,2CAF+B;EAG5C;EACAC,SAAS,EAAEP,aAJiC;EAK5C;EACAQ,UAAU,EAAER;AANgC,CAAtB,CAAnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/createGraphQLHandler.js
CHANGED
|
@@ -1,77 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
10
|
var _boolean = require("boolean");
|
|
13
11
|
|
|
12
|
+
var _handler = require("@webiny/handler");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
14
16
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
15
17
|
|
|
16
18
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
17
19
|
|
|
18
20
|
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
const createRequestBody = body => {
|
|
25
|
+
/**
|
|
26
|
+
* We are trusting that the body payload is correct.
|
|
27
|
+
* The `processRequestBody` will fail if it is not.
|
|
28
|
+
*/
|
|
29
|
+
return typeof body === "string" ? JSON.parse(body) : body;
|
|
30
|
+
};
|
|
23
31
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const formatErrorPayload = error => {
|
|
33
|
+
if (error instanceof _error.default) {
|
|
34
|
+
return JSON.stringify({
|
|
35
|
+
type: "CoreGraphQLWebinyError",
|
|
36
|
+
message: error.message,
|
|
37
|
+
code: error.code,
|
|
38
|
+
data: error.data
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return JSON.stringify({
|
|
43
|
+
type: "Error",
|
|
44
|
+
name: error.name,
|
|
45
|
+
message: error.message,
|
|
46
|
+
stack: error.stack
|
|
47
|
+
});
|
|
29
48
|
};
|
|
30
|
-
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
31
49
|
|
|
32
50
|
var _default = (options = {}) => {
|
|
33
|
-
let schema;
|
|
51
|
+
let schema = undefined;
|
|
34
52
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
|
|
54
|
+
const route = new _handler.RoutePlugin(async ({
|
|
55
|
+
onPost,
|
|
56
|
+
onOptions,
|
|
57
|
+
context
|
|
58
|
+
}) => {
|
|
59
|
+
onOptions(path, async (_, reply) => {
|
|
60
|
+
return reply.status(204).headers({
|
|
61
|
+
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
62
|
+
}).send({}).hijack();
|
|
63
|
+
});
|
|
64
|
+
onPost(path, async (request, reply) => {
|
|
65
|
+
if (!schema) {
|
|
66
|
+
try {
|
|
67
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
68
|
+
} catch (ex) {
|
|
69
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
|
|
48
|
-
|
|
49
|
-
return http.response({
|
|
50
|
-
statusCode: 204,
|
|
51
|
-
headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
|
|
52
|
-
"Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
|
|
53
|
-
})
|
|
54
|
-
});
|
|
55
|
-
}
|
|
73
|
+
let body;
|
|
56
74
|
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
try {
|
|
76
|
+
body = createRequestBody(request.body);
|
|
77
|
+
} catch (ex) {
|
|
78
|
+
console.log(`Error while creating the body request.`);
|
|
79
|
+
console.log(formatErrorPayload(ex));
|
|
80
|
+
throw ex;
|
|
59
81
|
}
|
|
60
82
|
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
try {
|
|
84
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
85
|
+
return reply.status(200).send(result);
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
console.log(`Error while processing the body request.`);
|
|
88
|
+
console.log(formatErrorPayload(ex));
|
|
89
|
+
throw ex;
|
|
63
90
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
headers: DEFAULT_HEADERS
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}];
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
route.name = "handler.graphql.route.default";
|
|
94
|
+
return [...(debug ? (0, _debugPlugins.default)() : []), {
|
|
95
|
+
type: "wcp-telemetry-tracker"
|
|
96
|
+
}, route];
|
|
75
97
|
};
|
|
76
98
|
|
|
77
99
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","hijack","request","createGraphQLSchema","ex","console","log","result","processRequestBody","debugPlugins"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n if (!schema) {\n try {\n schema = createGraphQLSchema(context);\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.log(`Error while creating the body request.`);\n console.log(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.log(`Error while processing the body request.`);\n console.log(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;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AAEA,MAAMA,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 -1,3 +1,2 @@
|
|
|
1
|
-
import { Context } from "@webiny/
|
|
2
|
-
|
|
3
|
-
export declare const createGraphQLSchema: (context: Context<HttpContext>) => import("graphql").GraphQLSchema;
|
|
1
|
+
import { Context } from "@webiny/api/types";
|
|
2
|
+
export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
|
package/createGraphQLSchema.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createGraphQLSchema = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
13
|
|
|
@@ -15,12 +15,10 @@ var _schema = require("@graphql-tools/schema");
|
|
|
15
15
|
|
|
16
16
|
var _builtInTypes = require("./builtInTypes");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
-
|
|
22
18
|
const createGraphQLSchema = context => {
|
|
23
|
-
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
19
|
+
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar); // TODO: once the API packages more closed, we'll have the opportunity
|
|
20
|
+
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
21
|
+
|
|
24
22
|
const typeDefs = [(0, _graphqlTag.default)`
|
|
25
23
|
type Query
|
|
26
24
|
type Mutation
|
|
@@ -33,25 +31,35 @@ const createGraphQLSchema = context => {
|
|
|
33
31
|
scalar Date
|
|
34
32
|
scalar DateTime
|
|
35
33
|
scalar Time
|
|
34
|
+
|
|
35
|
+
# This directive doesn't do anything on the GraphQL resolution level. It just serves
|
|
36
|
+
# as a way to tell the Prerendering Service whether the GraphQL query needs to be
|
|
37
|
+
# cached or not.
|
|
38
|
+
directive @ps(cache: Boolean) on QUERY
|
|
36
39
|
`];
|
|
37
|
-
const resolvers = [
|
|
40
|
+
const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
|
|
38
41
|
acc[s.name] = s;
|
|
39
42
|
return acc;
|
|
40
43
|
}, {})), {}, {
|
|
41
44
|
JSON: _builtInTypes.JsonScalar,
|
|
42
45
|
Long: _builtInTypes.LongScalar,
|
|
43
|
-
RefInput: _builtInTypes.
|
|
44
|
-
Number: _builtInTypes.
|
|
45
|
-
Any: _builtInTypes.
|
|
46
|
+
RefInput: _builtInTypes.RefInputScalar,
|
|
47
|
+
Number: _builtInTypes.NumberScalar,
|
|
48
|
+
Any: _builtInTypes.AnyScalar,
|
|
46
49
|
DateTime: _builtInTypes.DateTimeScalar,
|
|
47
50
|
Date: _builtInTypes.DateScalar,
|
|
48
51
|
Time: _builtInTypes.TimeScalar
|
|
49
52
|
})];
|
|
50
|
-
const
|
|
53
|
+
const plugins = context.plugins.byType("graphql-schema");
|
|
54
|
+
|
|
55
|
+
for (const plugin of plugins) {
|
|
56
|
+
/**
|
|
57
|
+
* TODO @ts-refactor
|
|
58
|
+
* Figure out correct types on typeDefs and resolvers
|
|
59
|
+
*/
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
|
|
51
62
|
|
|
52
|
-
for (let i = 0; i < gqlPlugins.length; i++) {
|
|
53
|
-
const plugin = gqlPlugins[i];
|
|
54
|
-
typeDefs.push(plugin.schema.typeDefs);
|
|
55
63
|
resolvers.push(plugin.schema.resolvers);
|
|
56
64
|
}
|
|
57
65
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n `\n ];\n\n const resolvers = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const plugins = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AAYO,MAAMA,mBAAmB,GAAIC,OAAD,IAAsB;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAR,CACXC,MADW,CACiB,gBADjB,EAEXC,GAFW,CAEPC,IAAI,IAAIA,IAAI,CAACC,MAFN,CAAhB,CADqD,CAKrD;EACA;;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAA,CAAI;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAR,CAAYE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAA5C,EAA+CC,IAA/C,CAAoD,GAApD,CAAyD;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAlBqB,CAAjB;EAqBA,MAAMC,SAAS,GAAG,6DAEPV,OAAO,CAACW,MAAR,CAAkD,CAACC,GAAD,EAAMC,CAAN,KAAY;IAC7DD,GAAG,CAACC,CAAC,CAACL,IAAH,CAAH,GAAcK,CAAd;IACA,OAAOD,GAAP;EACH,CAHE,EAGA,EAHA,CAFO;IAMVE,IAAI,EAAEC,wBANI;IAOVC,IAAI,EAAEC,wBAPI;IAQVC,QAAQ,EAAEC,4BARA;IASVC,MAAM,EAAEC,0BATE;IAUVC,GAAG,EAAEC,uBAVK;IAWVC,QAAQ,EAAEC,4BAXA;IAYVC,IAAI,EAAEC,wBAZI;IAaVC,IAAI,EAAEC;EAbI,GAAlB;EAiBA,MAAM5B,OAAO,GAAGF,OAAO,CAACE,OAAR,CAAgBC,MAAhB,CAA4C,gBAA5C,CAAhB;;EACA,KAAK,MAAM4B,MAAX,IAAqB7B,OAArB,EAA8B;IAC1B;AACR;AACA;AACA;IACQ;IACAK,QAAQ,CAACyB,IAAT,CAAcD,MAAM,CAACE,MAAP,CAAc1B,QAA5B,EAN0B,CAO1B;;IACAI,SAAS,CAACqB,IAAV,CAAeD,MAAM,CAACE,MAAP,CAActB,SAA7B;EACH;;EAED,OAAO,IAAAuB,4BAAA,EAAqB;IACxB3B,QADwB;IAExBI,SAFwB;IAGxBwB,8BAA8B,EAAE;EAHR,CAArB,CAAP;AAKH,CA9DM"}
|
package/debugPlugins.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { GraphQLAfterQueryPlugin
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
+
import { Context } from "@webiny/api/types";
|
|
3
|
+
import { ContextPlugin } from "@webiny/api";
|
|
4
|
+
interface Log {
|
|
5
|
+
method: string;
|
|
6
|
+
args: any;
|
|
7
|
+
}
|
|
8
|
+
interface DebugContext extends Context {
|
|
4
9
|
debug: {
|
|
5
|
-
logs?:
|
|
6
|
-
method: string;
|
|
7
|
-
args: any;
|
|
8
|
-
}[];
|
|
10
|
+
logs?: Log[];
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
|
-
declare const _default: () => (ContextPlugin<DebugContext
|
|
13
|
+
declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
|
|
12
14
|
export default _default;
|
package/debugPlugins.js
CHANGED
|
@@ -7,31 +7,24 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _interceptConsole = require("./interceptConsole");
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
type: "context",
|
|
10
|
+
var _api = require("@webiny/api");
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
context.debug
|
|
16
|
-
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
17
|
-
context.debug.logs.push({
|
|
18
|
-
method,
|
|
19
|
-
args
|
|
20
|
-
});
|
|
21
|
-
});
|
|
12
|
+
var _default = () => [new _api.ContextPlugin(async context => {
|
|
13
|
+
if (!context.debug) {
|
|
14
|
+
context.debug = {};
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
type: "graphql-before-query",
|
|
26
|
-
|
|
27
|
-
apply({
|
|
28
|
-
context
|
|
29
|
-
}) {
|
|
30
|
-
// Empty logs
|
|
17
|
+
if (!context.debug.logs) {
|
|
31
18
|
context.debug.logs = [];
|
|
32
19
|
}
|
|
33
20
|
|
|
34
|
-
|
|
21
|
+
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
22
|
+
context.debug.logs.push({
|
|
23
|
+
method,
|
|
24
|
+
args
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}), {
|
|
35
28
|
type: "graphql-after-query",
|
|
36
29
|
|
|
37
30
|
apply({
|
|
@@ -39,8 +32,12 @@ var _default = () => [{
|
|
|
39
32
|
context
|
|
40
33
|
}) {
|
|
41
34
|
result["extensions"] = {
|
|
42
|
-
console: context.debug.logs || []
|
|
35
|
+
console: [...(context.debug.logs || [])]
|
|
43
36
|
};
|
|
37
|
+
|
|
38
|
+
if (context.debug.logs) {
|
|
39
|
+
context.debug.logs.length = 0;
|
|
40
|
+
}
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;;AAAA;;AAGA;;eAYe,MAAM,CACjB,IAAIA,kBAAJ,CAAgC,MAAMC,OAAN,IAAiB;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAb,EAAoB;IAChBD,OAAO,CAACC,KAAR,GAAgB,EAAhB;EACH;;EAED,IAAI,CAACD,OAAO,CAACC,KAAR,CAAcC,IAAnB,EAAyB;IACrBF,OAAO,CAACC,KAAR,CAAcC,IAAd,GAAqB,EAArB;EACH;;EAED,IAAAC,kCAAA,EAAiB,CAACC,MAAD,EAASC,IAAT,KAAkB;IAC9BL,OAAO,CAACC,KAAR,CAAcC,IAAf,CAA8BI,IAA9B,CAAmC;MAAEF,MAAF;MAAUC;IAAV,CAAnC;EACH,CAFD;AAGH,CAZD,CADiB,EAcjB;EACIE,IAAI,EAAE,qBADV;;EAEIC,KAAK,CAAC;IAAEC,MAAF;IAAUT;EAAV,CAAD,EAAsB;IACvBS,MAAM,CAAC,YAAD,CAAN,GAAuB;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAR,CAAcC,IAAd,IAAsB,EAA1B,CAAD;IAAX,CAAvB;;IACA,IAAIF,OAAO,CAACC,KAAR,CAAcC,IAAlB,EAAwB;MACpBF,OAAO,CAACC,KAAR,CAAcC,IAAd,CAAmBS,MAAnB,GAA4B,CAA5B;IACH;EACJ;;AAPL,CAdiB,C"}
|
package/errors.d.ts
CHANGED
package/errors.js
CHANGED
package/errors.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEO,MAAMA,aAAN,SAA4BC,cAA5B,CAAwC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAX,EAAyB;IAChC,MAAMA,OAAN,EAAe,WAAf;EACH;;AAH0C"}
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { HandlerGraphQLOptions } from "./types";
|
|
2
|
-
import { Context } from "@webiny/handler/types";
|
|
3
|
-
import { GraphQLFieldResolver } from "./types";
|
|
4
2
|
export * from "./errors";
|
|
5
3
|
export * from "./responses";
|
|
4
|
+
export * from "./plugins";
|
|
6
5
|
declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
|
|
7
6
|
export default _default;
|
|
8
|
-
export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
|
|
9
|
-
export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
|
package/index.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
var _exportNames = {
|
|
9
|
-
|
|
10
|
-
compose: true
|
|
11
|
-
};
|
|
12
|
-
exports.pipe = exports.default = exports.compose = void 0;
|
|
8
|
+
var _exportNames = {};
|
|
9
|
+
exports.default = void 0;
|
|
13
10
|
|
|
14
11
|
var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
|
|
15
12
|
|
|
@@ -41,14 +38,20 @@ Object.keys(_responses).forEach(function (key) {
|
|
|
41
38
|
});
|
|
42
39
|
});
|
|
43
40
|
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
exports.default = _default;
|
|
47
|
-
|
|
48
|
-
const pipe = (...fns) => resolver => fns.reduce((v, f) => f(v), resolver);
|
|
41
|
+
var _plugins = require("./plugins");
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
44
|
+
if (key === "default" || key === "__esModule") return;
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
46
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
47
|
+
Object.defineProperty(exports, key, {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return _plugins[key];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
|
|
53
56
|
|
|
54
|
-
exports.
|
|
57
|
+
exports.default = _default;
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["options","createGraphQLHandler"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n"],"mappings":";;;;;;;;;;AACA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C"}
|
package/interceptConsole.d.ts
CHANGED
package/interceptConsole.js
CHANGED
|
@@ -10,19 +10,23 @@ const skipOriginal = ["table"];
|
|
|
10
10
|
|
|
11
11
|
const restoreOriginalMethods = () => {
|
|
12
12
|
for (const method of consoleMethods) {
|
|
13
|
+
// @ts-ignore
|
|
13
14
|
console[method] = originalMethods[method];
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
const interceptConsole = callback => {
|
|
19
|
+
// @ts-ignore
|
|
18
20
|
if (console["__WEBINY__"] === true) {
|
|
19
21
|
restoreOriginalMethods();
|
|
20
|
-
}
|
|
22
|
+
} // @ts-ignore
|
|
23
|
+
|
|
21
24
|
|
|
22
25
|
console["__WEBINY__"] = true;
|
|
23
26
|
|
|
24
27
|
for (const method of consoleMethods) {
|
|
25
|
-
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
originalMethods[method] = console[method]; // @ts-ignore
|
|
26
30
|
|
|
27
31
|
console[method] = (...args) => {
|
|
28
32
|
callback(method, args);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-ignore\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QADmB,EAEnB,OAFmB,EAGnB,KAHmB,EAInB,OAJmB,EAKnB,OALmB,EAMnB,gBANmB,EAOnB,UAPmB,EAQnB,MARmB,EASnB,KATmB,EAUnB,OAVmB,EAWnB,MAXmB,CAAvB;AAcA,MAAMC,eAAoC,GAAG,EAA7C;AACA,MAAMC,YAAsB,GAAG,CAAC,OAAD,CAA/B;;AAEA,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAK,OAAO,CAACD,MAAD,CAAP,GAAkBH,eAAe,CAACG,MAAD,CAAjC;EACH;AACJ,CALD;;AAWO,MAAME,gBAAgB,GAAIC,QAAD,IAAwC;EACpE;EACA,IAAIF,OAAO,CAAC,YAAD,CAAP,KAA0B,IAA9B,EAAoC;IAChCF,sBAAsB;EACzB,CAJmE,CAMpE;;;EACAE,OAAO,CAAC,YAAD,CAAP,GAAwB,IAAxB;;EAEA,KAAK,MAAMD,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAC,eAAe,CAACG,MAAD,CAAf,GAA0BC,OAAO,CAACD,MAAD,CAAjC,CAFiC,CAGjC;;IACAC,OAAO,CAACD,MAAD,CAAP,GAAkB,CAAC,GAAGI,IAAJ,KAAa;MAC3BD,QAAQ,CAACH,MAAD,EAASI,IAAT,CAAR;;MACA,IAAIN,YAAY,CAACO,QAAb,CAAsBL,MAAtB,CAAJ,EAAmC;QAC/B;MACH;;MACDH,eAAe,CAACG,MAAD,CAAf,CAAwB,GAAGI,IAA3B;IACH,CAND;EAOH;AACJ,CArBM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.3386f66516",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,28 +14,29 @@
|
|
|
14
14
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "7.
|
|
17
|
+
"@babel/runtime": "7.19.0",
|
|
18
18
|
"@graphql-tools/schema": "7.1.5",
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/handler
|
|
22
|
-
"@webiny/plugins": "0.0.0-
|
|
23
|
-
"boolean": "3.
|
|
24
|
-
"graphql": "
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.3386f66516",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.3386f66516",
|
|
21
|
+
"@webiny/handler": "0.0.0-unstable.3386f66516",
|
|
22
|
+
"@webiny/plugins": "0.0.0-unstable.3386f66516",
|
|
23
|
+
"boolean": "3.2.0",
|
|
24
|
+
"graphql": "15.8.0",
|
|
25
25
|
"graphql-scalars": "1.12.0",
|
|
26
|
-
"graphql-tag": "2.12.
|
|
26
|
+
"graphql-tag": "2.12.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/cli": "^7.
|
|
30
|
-
"@babel/core": "^7.
|
|
31
|
-
"@babel/preset-env": "^7.
|
|
32
|
-
"@webiny/cli": "^0.0.0-
|
|
33
|
-
"@webiny/handler-
|
|
34
|
-
"@webiny/project-utils": "^0.0.0-
|
|
35
|
-
"jest": "^
|
|
29
|
+
"@babel/cli": "^7.19.3",
|
|
30
|
+
"@babel/core": "^7.19.3",
|
|
31
|
+
"@babel/preset-env": "^7.19.4",
|
|
32
|
+
"@webiny/cli": "^0.0.0-unstable.3386f66516",
|
|
33
|
+
"@webiny/handler-aws": "^0.0.0-unstable.3386f66516",
|
|
34
|
+
"@webiny/project-utils": "^0.0.0-unstable.3386f66516",
|
|
35
|
+
"jest": "^28.1.0",
|
|
36
36
|
"jest-mock-console": "^1.0.0",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
38
|
-
"
|
|
38
|
+
"ttypescript": "^1.5.15",
|
|
39
|
+
"typescript": "4.7.4"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"build": "yarn webiny run build",
|
|
46
47
|
"watch": "yarn webiny run watch"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3386f66516b16fe54e2508243b91dfff1a0156f9"
|
|
49
50
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
|
|
3
|
-
import { Context } from "@webiny/
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
4
|
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
5
5
|
typeDefs?: Types;
|
|
6
6
|
resolvers?: Resolvers<TContext>;
|
|
7
7
|
}
|
|
8
8
|
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
9
|
-
static readonly type
|
|
9
|
+
static readonly type: string;
|
|
10
10
|
private config;
|
|
11
11
|
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
12
12
|
get schema(): GraphQLSchemaDefinition<TContext>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context> extends Plugin {\n public static override readonly type: string = \"graphql-schema\";\n private config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,mBAAN,SAAsDC,eAAtD,CAA6D;EAIhEC,WAAW,CAACC,MAAD,EAA8C;IACrD;IADqD;IAErD,KAAKA,MAAL,GAAcA,MAAd;EACH;;EAES,IAANC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,KAAKF,MAAL,CAAYE,QAAZ,IAAwB,EAD/B;MAEHC,SAAS,EAAE,KAAKH,MAAL,CAAYG;IAFpB,CAAP;EAIH;;AAd+D;;;8BAAvDN,mB,UACsC,gB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/processRequestBody.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
+
import { GraphQLRequestBody } from "./types";
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
declare const _default: (requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult[] | ExecutionResult>;
|
|
2
5
|
export default _default;
|
package/processRequestBody.js
CHANGED
|
@@ -31,19 +31,18 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
var _default = async (requestBody, schema, context) => {
|
|
34
|
-
let result;
|
|
35
|
-
|
|
36
34
|
if (Array.isArray(requestBody)) {
|
|
37
|
-
|
|
35
|
+
const results = [];
|
|
38
36
|
|
|
39
|
-
for (
|
|
40
|
-
result
|
|
37
|
+
for (const body of requestBody) {
|
|
38
|
+
const result = await processRequestBody(body, schema, context);
|
|
39
|
+
results.push(result);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
|
|
42
|
+
return results;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
return
|
|
45
|
+
return await processRequestBody(requestBody, schema, context);
|
|
47
46
|
};
|
|
48
47
|
|
|
49
48
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","results","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import { ExecutionResult, graphql, GraphQLSchema } from \"graphql\";\nimport { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin, GraphQLRequestBody } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nconst processRequestBody = async (\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n) => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql(schema, query, {}, context, variables, operationName);\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result;\n};\n\nexport default async (\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult[] | ExecutionResult> => {\n if (Array.isArray(requestBody)) {\n const results: ExecutionResult[] = [];\n for (const body of requestBody) {\n const result = await processRequestBody(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await processRequestBody(requestBody, schema, context);\n};\n"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,kBAAkB,GAAG,OACvBC,IADuB,EAEvBC,MAFuB,EAGvBC,OAHuB,KAItB;EACD,MAAM;IAAEC,KAAF;IAASC,SAAT;IAAoBC;EAApB,IAAsCL,IAA5C;EAEAE,OAAO,CAACI,OAAR,CACKC,MADL,CACsC,sBADtC,EAEKC,OAFL,CAEaC,EAAE,IAAIA,EAAE,CAACC,KAAH,CAAS;IAAEV,IAAF;IAAQC,MAAR;IAAgBC;EAAhB,CAAT,CAFnB;EAIA,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAA,EAAQX,MAAR,EAAgBE,KAAhB,EAAuB,EAAvB,EAA2BD,OAA3B,EAAoCE,SAApC,EAA+CC,aAA/C,CAArB;EAEAH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAAgD,qBAAhD,EAAuEC,OAAvE,CAA+EC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAH,CAAS;MAAEC,MAAF;MAAUX,IAAV;MAAgBC,MAAhB;MAAwBC;IAAxB,CAAT;EACH,CAFD;EAIA,OAAOS,MAAP;AACH,CAlBD;;eAoBe,OACXE,WADW,EAEXZ,MAFW,EAGXC,OAHW,KAIoC;EAC/C,IAAIY,KAAK,CAACC,OAAN,CAAcF,WAAd,CAAJ,EAAgC;IAC5B,MAAMG,OAA0B,GAAG,EAAnC;;IACA,KAAK,MAAMhB,IAAX,IAAmBa,WAAnB,EAAgC;MAC5B,MAAMF,MAAM,GAAG,MAAMZ,kBAAkB,CAACC,IAAD,EAAOC,MAAP,EAAeC,OAAf,CAAvC;MACAc,OAAO,CAACC,IAAR,CAAaN,MAAb;IACH;;IACD,OAAOK,OAAP;EACH;;EACD,OAAO,MAAMjB,kBAAkB,CAACc,WAAD,EAAcZ,MAAd,EAAsBC,OAAtB,CAA/B;AACH,C"}
|
package/responses.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
export interface ErrorResponseParams {
|
|
2
|
+
message: string;
|
|
2
3
|
code?: string;
|
|
3
|
-
message?: string;
|
|
4
4
|
data?: any;
|
|
5
|
-
|
|
5
|
+
stack?: string | null;
|
|
6
|
+
}
|
|
6
7
|
export declare class ErrorResponse {
|
|
7
|
-
data:
|
|
8
|
-
error: {
|
|
8
|
+
readonly data: null;
|
|
9
|
+
readonly error: {
|
|
9
10
|
code: string;
|
|
10
11
|
message: string;
|
|
11
|
-
data
|
|
12
|
+
data: any;
|
|
13
|
+
stack: string | null;
|
|
12
14
|
};
|
|
13
15
|
constructor(params: ErrorResponseParams);
|
|
14
16
|
}
|
|
@@ -16,24 +18,24 @@ export declare class NotFoundResponse extends ErrorResponse {
|
|
|
16
18
|
constructor(message: string);
|
|
17
19
|
}
|
|
18
20
|
export declare class ListErrorResponse {
|
|
19
|
-
data: null;
|
|
20
|
-
meta: null;
|
|
21
|
-
error: {
|
|
21
|
+
readonly data: null;
|
|
22
|
+
readonly meta: null;
|
|
23
|
+
readonly error: {
|
|
22
24
|
code: string;
|
|
23
25
|
message: string;
|
|
24
|
-
data
|
|
26
|
+
data: any;
|
|
27
|
+
stack: string | null;
|
|
25
28
|
};
|
|
26
29
|
constructor(params: ErrorResponseParams);
|
|
27
30
|
}
|
|
28
|
-
export declare class Response<T
|
|
29
|
-
data: T;
|
|
30
|
-
error: null;
|
|
31
|
+
export declare class Response<T = any> {
|
|
32
|
+
readonly data: T;
|
|
33
|
+
readonly error: null;
|
|
31
34
|
constructor(data: T);
|
|
32
35
|
}
|
|
33
|
-
export declare class ListResponse<T
|
|
34
|
-
data: Array<T>;
|
|
35
|
-
meta: M;
|
|
36
|
-
error: null;
|
|
36
|
+
export declare class ListResponse<T, M> {
|
|
37
|
+
readonly data: Array<T>;
|
|
38
|
+
readonly meta: M;
|
|
39
|
+
readonly error: null;
|
|
37
40
|
constructor(data: Array<T>, meta?: M);
|
|
38
41
|
}
|
|
39
|
-
export {};
|
package/responses.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -12,7 +12,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
12
12
|
const defaultParams = {
|
|
13
13
|
code: "",
|
|
14
14
|
message: "",
|
|
15
|
-
data: null
|
|
15
|
+
data: null,
|
|
16
|
+
stack: null
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
class ErrorResponse {
|
|
@@ -20,10 +21,19 @@ class ErrorResponse {
|
|
|
20
21
|
(0, _defineProperty2.default)(this, "data", void 0);
|
|
21
22
|
(0, _defineProperty2.default)(this, "error", void 0);
|
|
22
23
|
this.data = null;
|
|
24
|
+
const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
|
|
25
|
+
|
|
26
|
+
let stack = defaultParams.stack;
|
|
27
|
+
|
|
28
|
+
if (debug && params.stack) {
|
|
29
|
+
stack = params.stack;
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
this.error = {
|
|
24
33
|
code: params.code || defaultParams.code,
|
|
25
34
|
message: params.message || defaultParams.message,
|
|
26
|
-
data: params.data || defaultParams.data
|
|
35
|
+
data: params.data || defaultParams.data,
|
|
36
|
+
stack: stack
|
|
27
37
|
};
|
|
28
38
|
}
|
|
29
39
|
|
|
@@ -48,12 +58,21 @@ class ListErrorResponse {
|
|
|
48
58
|
(0, _defineProperty2.default)(this, "data", void 0);
|
|
49
59
|
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
50
60
|
(0, _defineProperty2.default)(this, "error", void 0);
|
|
51
|
-
this.data = null;
|
|
52
61
|
this.meta = null;
|
|
62
|
+
this.data = null;
|
|
63
|
+
const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
|
|
64
|
+
|
|
65
|
+
let stack = defaultParams.stack;
|
|
66
|
+
|
|
67
|
+
if (debug && params.stack) {
|
|
68
|
+
stack = params.stack;
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
this.error = {
|
|
54
72
|
code: params.code || defaultParams.code,
|
|
55
73
|
message: params.message || defaultParams.message,
|
|
56
|
-
data: params.data || defaultParams.data
|
|
74
|
+
data: params.data || defaultParams.data,
|
|
75
|
+
stack: stack
|
|
57
76
|
};
|
|
58
77
|
}
|
|
59
78
|
|
package/responses.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA,MAAMA,aAA4C,GAAG;EACjD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AAf;IACH;;IAED,KAAKQ,KAAL,GAAa;MACTX,IAAI,EAAEM,MAAM,CAACN,IAAP,IAAeD,aAAa,CAACC,IAD1B;MAETC,OAAO,EAAEK,MAAM,CAACL,OAAP,IAAkBF,aAAa,CAACE,OAFhC;MAGTC,IAAI,EAAEI,MAAM,CAACJ,IAAP,IAAeH,aAAa,CAACG,IAH1B;MAITC,KAAK,EAAEA;IAJE,CAAb;EAMH;;AA5B0B;;;;AA+BxB,MAAMY,QAAN,CAAwB;EAI3BV,WAAW,CAACH,IAAD,EAAU;IAAA;IAAA;IACjB,KAAKA,IAAL,GAAYA,IAAZ;IACA,KAAKS,KAAL,GAAa,IAAb;EACH;;AAP0B;;;;AAUxB,MAAMK,YAAN,CAAyB;EAK5BX,WAAW,CAACH,IAAD,EAAiBY,IAAjB,EAA2B;IAAA;IAAA;IAAA;IAClC,KAAKZ,IAAL,GAAYe,KAAK,CAACC,OAAN,CAAchB,IAAd,IAAsBA,IAAtB,GAA6B,EAAzC;IACA,KAAKY,IAAL,GAAYA,IAAI,IAAK,EAArB;IACA,KAAKH,KAAL,GAAa,IAAb;EACH;;AAT2B"}
|
package/types.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
|
|
2
2
|
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
-
import {
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
import { RouteMethodPath } from "@webiny/handler/types";
|
|
4
5
|
export interface GraphQLScalarPlugin extends Plugin {
|
|
5
6
|
type: "graphql-scalar";
|
|
6
7
|
scalar: GraphQLScalarType;
|
|
7
8
|
}
|
|
8
9
|
export interface HandlerGraphQLOptions {
|
|
10
|
+
path?: RouteMethodPath;
|
|
9
11
|
debug?: boolean | string;
|
|
10
12
|
}
|
|
11
|
-
export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext =
|
|
13
|
+
export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
|
|
12
14
|
export declare type Types = string | (() => string | Promise<string>);
|
|
13
15
|
export interface GraphQLSchemaPluginTypeArgs {
|
|
14
16
|
context?: any;
|
|
@@ -22,7 +24,7 @@ export interface GraphQLSchemaDefinition<TContext> {
|
|
|
22
24
|
typeDefs: Types;
|
|
23
25
|
resolvers?: Resolvers<TContext>;
|
|
24
26
|
}
|
|
25
|
-
export interface GraphQLSchemaPlugin<TContext extends
|
|
27
|
+
export interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {
|
|
26
28
|
type: "graphql-schema";
|
|
27
29
|
schema: GraphQLSchemaDefinition<TContext>;
|
|
28
30
|
}
|
|
@@ -31,7 +33,7 @@ export interface GraphQLRequestBody {
|
|
|
31
33
|
variables: Record<string, any>;
|
|
32
34
|
operationName: string;
|
|
33
35
|
}
|
|
34
|
-
export interface GraphQLBeforeQueryPlugin<TContext extends
|
|
36
|
+
export interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {
|
|
35
37
|
type: "graphql-before-query";
|
|
36
38
|
apply(params: {
|
|
37
39
|
body: GraphQLRequestBody;
|
|
@@ -39,7 +41,7 @@ export interface GraphQLBeforeQueryPlugin<TContext extends ContextInterface = Co
|
|
|
39
41
|
context: TContext;
|
|
40
42
|
}): void;
|
|
41
43
|
}
|
|
42
|
-
export interface GraphQLAfterQueryPlugin<TContext extends
|
|
44
|
+
export interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {
|
|
43
45
|
type: "graphql-after-query";
|
|
44
46
|
apply(params: {
|
|
45
47
|
result: any;
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | (() => string | Promise<string>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> };\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":""}
|