@webiny/handler-graphql 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60e968001a
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 -1
- package/builtInTypes/DateScalar.js +3 -7
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +3 -7
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +11 -7
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +3 -3
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +1 -1
- package/createGraphQLHandler.d.ts +1 -1
- package/createGraphQLHandler.js +30 -8
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.js +16 -15
- package/createGraphQLSchema.js.map +1 -1
- package/errors.js +1 -1
- package/index.d.ts +1 -11
- package/index.js +17 -14
- package/index.js.map +1 -1
- package/package.json +14 -13
- package/plugins/GraphQLSchemaPlugin.js +1 -1
- package/processRequestBody.js +6 -5
- package/processRequestBody.js.map +1 -1
- package/responses.js +1 -1
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["returnValue","value","
|
|
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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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;
|
|
@@ -1 +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
|
|
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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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;
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isMongoId","value","test","Error","
|
|
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,0BAAJ,CAAsB;EAChDC,IAAI,EAAE,UAD0C;EAEhDC,WAAW,EACP,oGAH4C;EAIhDC,SAAS,EAAEP,KAAK,IAAI;IAChB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,OAAO,OAAOR,KAAP,KAAiB,QAAjB,GAA4BA,KAA5B,GAAoCA,KAAK,CAACQ,EAAjD;EACH,CAV+C;EAWhDC,UAAU,EAAET,KAAK,IAAI;IACjB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,IAAI,OAAOR,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOD,SAAS,CAACC,KAAD,CAAhB;IACH;;IAED,IAAI,QAAQA,KAAZ,EAAmB;MACf,OAAOD,SAAS,CAACC,KAAK,CAACQ,EAAP,CAAhB;IACH;;IAED,MAAM,IAAIN,KAAJ,CAAU,yBAAV,CAAN;EACH,CAzB+C;EA0BhDQ,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,OAAOb,SAAS,CAACY,GAAG,CAACX,KAAL,CAAhB;IACH;;IAED,IAAIW,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,GAAG,CAACG,MAAJ,CAAWC,MAA/B,EAAuCF,CAAC,EAAxC,EAA4C;QACxC,MAAM;UAAER,IAAF;UAAQL;QAAR,IAAkBW,GAAG,CAACG,MAAJ,CAAWD,CAAX,CAAxB;;QACA,IAAIR,IAAI,CAACL,KAAL,KAAe,IAAnB,EAAyB;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAP,CAAhB;QACH;MACJ;IACJ;;IAED,MAAM,IAAIE,KAAJ,CAAU,yBAAV,CAAN;EACH;AA1C+C,CAAtB,CAAvB"}
|
package/createGraphQLHandler.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
|
|
@@ -9,24 +9,42 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _boolean = require("boolean");
|
|
11
11
|
|
|
12
|
+
var _handler = require("@webiny/handler");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
12
16
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
13
17
|
|
|
14
18
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
15
19
|
|
|
16
20
|
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
17
21
|
|
|
18
|
-
var _handler = require("@webiny/handler");
|
|
19
|
-
|
|
20
22
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
21
23
|
|
|
22
|
-
/**
|
|
23
|
-
* TODO Until we figure out how to better convert incoming body, we will leave it as any.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
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
|
+
*/
|
|
27
29
|
return typeof body === "string" ? JSON.parse(body) : body;
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
const formatErrorPayload = error => {
|
|
33
|
+
if (error instanceof _error.default) {
|
|
34
|
+
return {
|
|
35
|
+
message: error.message,
|
|
36
|
+
code: error.code,
|
|
37
|
+
data: error.data
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
name: error.name,
|
|
43
|
+
message: error.message,
|
|
44
|
+
stack: error.stack
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
30
48
|
var _default = (options = {}) => {
|
|
31
49
|
let schema = undefined;
|
|
32
50
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
@@ -43,7 +61,11 @@ var _default = (options = {}) => {
|
|
|
43
61
|
});
|
|
44
62
|
onPost(path, async (request, reply) => {
|
|
45
63
|
if (!schema) {
|
|
46
|
-
|
|
64
|
+
try {
|
|
65
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
68
|
+
}
|
|
47
69
|
}
|
|
48
70
|
|
|
49
71
|
const body = createRequestBody(request.body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","ex","result","processRequestBody","debugPlugins","type"],"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) => {\n if (error instanceof WebinyError) {\n return {\n message: error.message,\n code: error.code,\n data: error.data\n };\n }\n\n return {\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 });\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 const body = createRequestBody(request.body);\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\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,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAExC,MAAMC,iBAAiB,GAAIC,IAAD,IAA8D;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAND;;AAQA,MAAMG,kBAAkB,GAAIC,KAAD,IAAkB;EACzC,IAAIA,KAAK,YAAYC,cAArB,EAAkC;IAC9B,OAAO;MACHC,OAAO,EAAEF,KAAK,CAACE,OADZ;MAEHC,IAAI,EAAEH,KAAK,CAACG,IAFT;MAGHC,IAAI,EAAEJ,KAAK,CAACI;IAHT,CAAP;EAKH;;EAED,OAAO;IACHC,IAAI,EAAEL,KAAK,CAACK,IADT;IAEHH,OAAO,EAAEF,KAAK,CAACE,OAFZ;IAGHI,KAAK,EAAEN,KAAK,CAACM;EAHV,CAAP;AAKH,CAdD;;eAgBe,CAACC,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQJ,OAAO,CAACG,KAAhB,CAAd;EAEA,MAAME,IAAI,GAAG,CAAAL,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEK,IAAT,KAAiB,UAA9B;EAEA,MAAMC,KAAK,GAAG,IAAIC,oBAAJ,CAAgB,OAAO;IAAEC,MAAF;IAAUC,SAAV;IAAqBC;EAArB,CAAP,KAA0C;IACpED,SAAS,CAACJ,IAAD,EAAO,OAAOM,CAAP,EAAUC,KAAV,KAAoB;MAChC,OAAOA,KAAK,CACPC,MADE,CACK,GADL,EAEFC,OAFE,CAEM;QACL,iBAAkB,mBAAkB3B,qBAAsB;MADrD,CAFN,EAKF4B,IALE,CAKG,EALH,CAAP;IAMH,CAPQ,CAAT;IAQAP,MAAM,CAACH,IAAD,EAAO,OAAOW,OAAP,EAAgBJ,KAAhB,KAA0B;MACnC,IAAI,CAACX,MAAL,EAAa;QACT,IAAI;UACAA,MAAM,GAAG,IAAAgB,wCAAA,EAAoBP,OAApB,CAAT;QACH,CAFD,CAEE,OAAOQ,EAAP,EAAW;UACT,OAAON,KAAK,CAAChB,IAAN,CAAW,GAAX,EAAgBmB,IAAhB,CAAqBvB,kBAAkB,CAAC0B,EAAD,CAAvC,CAAP;QACH;MACJ;;MACD,MAAM7B,IAAI,GAAGD,iBAAiB,CAAC4B,OAAO,CAAC3B,IAAT,CAA9B;MACA,MAAM8B,MAAM,GAAG,MAAM,IAAAC,2BAAA,EAAmB/B,IAAnB,EAAyBY,MAAzB,EAAiCS,OAAjC,CAArB;MACA,OAAOE,KAAK,CAACC,MAAN,CAAa,GAAb,EAAkBE,IAAlB,CAAuBI,MAAvB,CAAP;IACH,CAXK,CAAN;EAYH,CArBa,CAAd;EAuBAb,KAAK,CAACR,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIK,KAAK,GAAG,IAAAkB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACIC,IAAI,EAAE;EADV,CAFG,EAKHhB,KALG,CAAP;AAOH,C"}
|
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); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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,30 +31,33 @@ 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");
|
|
51
54
|
|
|
52
|
-
for (
|
|
53
|
-
const plugin = gqlPlugins[i];
|
|
55
|
+
for (const plugin of plugins) {
|
|
54
56
|
/**
|
|
55
57
|
* TODO @ts-refactor
|
|
56
58
|
* Figure out correct types on typeDefs and resolvers
|
|
57
59
|
*/
|
|
58
60
|
// @ts-ignore
|
|
59
|
-
|
|
60
61
|
typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
|
|
61
62
|
|
|
62
63
|
resolvers.push(plugin.schema.resolvers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","
|
|
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/errors.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { HandlerGraphQLOptions } from "./types";
|
|
2
|
-
import { Context } from "@webiny/api/types";
|
|
3
|
-
import { GraphQLFieldResolver } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Can be anything.
|
|
6
|
-
* TODO: Figure out if required at all.
|
|
7
|
-
*/
|
|
8
|
-
interface Callable {
|
|
9
|
-
(params: any): any;
|
|
10
|
-
}
|
|
11
2
|
export * from "./errors";
|
|
12
3
|
export * from "./responses";
|
|
4
|
+
export * from "./plugins";
|
|
13
5
|
declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
|
|
14
6
|
export default _default;
|
|
15
|
-
export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
|
|
16
|
-
export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["options","createGraphQLHandler"
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.60e968001a",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,27 +14,28 @@
|
|
|
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/api": "0.0.0-unstable.
|
|
20
|
-
"@webiny/error": "0.0.0-unstable.
|
|
21
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
22
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.60e968001a",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.60e968001a",
|
|
21
|
+
"@webiny/handler": "0.0.0-unstable.60e968001a",
|
|
22
|
+
"@webiny/plugins": "0.0.0-unstable.60e968001a",
|
|
23
23
|
"boolean": "3.2.0",
|
|
24
24
|
"graphql": "15.8.0",
|
|
25
25
|
"graphql-scalars": "1.12.0",
|
|
26
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-unstable.
|
|
33
|
-
"@webiny/handler-aws": "^0.0.0-unstable.
|
|
34
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
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.60e968001a",
|
|
33
|
+
"@webiny/handler-aws": "^0.0.0-unstable.60e968001a",
|
|
34
|
+
"@webiny/project-utils": "^0.0.0-unstable.60e968001a",
|
|
35
35
|
"jest": "^28.1.0",
|
|
36
36
|
"jest-mock-console": "^1.0.0",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
38
|
+
"ttypescript": "^1.5.15",
|
|
38
39
|
"typescript": "4.7.4"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"build": "yarn webiny run build",
|
|
46
47
|
"watch": "yarn webiny run watch"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "60e968001a7897edd990fe7d7eecf7dd0a1c2977"
|
|
49
50
|
}
|
package/processRequestBody.js
CHANGED
|
@@ -31,14 +31,15 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
var _default = async (requestBody, schema, context) => {
|
|
34
|
-
if (Array.isArray(requestBody)
|
|
35
|
-
const
|
|
34
|
+
if (Array.isArray(requestBody)) {
|
|
35
|
+
const results = [];
|
|
36
36
|
|
|
37
|
-
for (
|
|
38
|
-
result
|
|
37
|
+
for (const body of requestBody) {
|
|
38
|
+
const result = await processRequestBody(body, schema, context);
|
|
39
|
+
results.push(result);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
return
|
|
42
|
+
return results;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
return await processRequestBody(requestBody, schema, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","
|
|
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.js
CHANGED