@webiny/handler-graphql 0.0.0-unstable.e3f4727c56 → 0.0.0-unstable.e53eceafb5
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/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +26 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.js +3 -2
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.js +5 -5
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +5 -5
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +3 -2
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/JsonScalar.js +3 -2
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +50 -3
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.js +6 -6
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.js +33 -11
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +3 -2
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.js +3 -1
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +35 -9
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +3 -1
- package/createGraphQLSchema.js +47 -19
- package/createGraphQLSchema.js.map +1 -1
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +12 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +3 -1
- package/debugPlugins.js.map +1 -1
- package/errors.js +3 -1
- package/errors.js.map +1 -1
- package/index.d.ts +7 -2
- package/index.js +54 -2
- package/index.js.map +1 -1
- package/interceptConsole.js +8 -6
- package/interceptConsole.js.map +1 -1
- package/package.json +19 -22
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +16 -6
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.js +3 -1
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +16 -7
- package/processRequestBody.js.map +1 -1
- package/responses.js +3 -13
- package/responses.js.map +1 -1
- package/types.d.ts +17 -10
- package/types.js +3 -1
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +28 -0
- package/utils/resolve.js.map +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ResolverDecoration = void 0;
|
|
7
|
+
var _resolversComposition = require("@graphql-tools/resolvers-composition");
|
|
8
|
+
class ResolverDecoration {
|
|
9
|
+
decorators = {};
|
|
10
|
+
addDecorators(resolverDecorators) {
|
|
11
|
+
for (const key in resolverDecorators) {
|
|
12
|
+
const decorators = resolverDecorators[key];
|
|
13
|
+
if (!decorators) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const existingDecorators = this.decorators[key] ?? [];
|
|
17
|
+
this.decorators[key] = [...existingDecorators, ...decorators];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
decorateResolvers(resolvers) {
|
|
21
|
+
return (0, _resolversComposition.composeResolvers)(resolvers, this.decorators);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ResolverDecoration = ResolverDecoration;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=ResolverDecoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_resolversComposition","require","ResolverDecoration","decorators","addDecorators","resolverDecorators","key","existingDecorators","decorateResolvers","resolvers","composeResolvers","exports"],"sources":["ResolverDecoration.ts"],"sourcesContent":["import { composeResolvers } from \"@graphql-tools/resolvers-composition\";\nimport type { ResolverDecorators, Resolvers } from \"./types\";\n\nexport class ResolverDecoration {\n private decorators: ResolverDecorators = {};\n\n addDecorators(resolverDecorators: ResolverDecorators) {\n for (const key in resolverDecorators) {\n const decorators = resolverDecorators[key];\n if (!decorators) {\n continue;\n }\n\n const existingDecorators = this.decorators[key] ?? [];\n this.decorators[key] = [...existingDecorators, ...decorators];\n }\n }\n\n decorateResolvers(resolvers: Resolvers<unknown>) {\n return composeResolvers(resolvers, this.decorators);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAGO,MAAMC,kBAAkB,CAAC;EACpBC,UAAU,GAAuB,CAAC,CAAC;EAE3CC,aAAaA,CAACC,kBAAsC,EAAE;IAClD,KAAK,MAAMC,GAAG,IAAID,kBAAkB,EAAE;MAClC,MAAMF,UAAU,GAAGE,kBAAkB,CAACC,GAAG,CAAC;MAC1C,IAAI,CAACH,UAAU,EAAE;QACb;MACJ;MAEA,MAAMI,kBAAkB,GAAG,IAAI,CAACJ,UAAU,CAACG,GAAG,CAAC,IAAI,EAAE;MACrD,IAAI,CAACH,UAAU,CAACG,GAAG,CAAC,GAAG,CAAC,GAAGC,kBAAkB,EAAE,GAAGJ,UAAU,CAAC;IACjE;EACJ;EAEAK,iBAAiBA,CAACC,SAA6B,EAAE;IAC7C,OAAO,IAAAC,sCAAgB,EAACD,SAAS,EAAE,IAAI,CAACN,UAAU,CAAC;EACvD;AACJ;AAACQ,OAAA,CAAAT,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -8,10 +8,11 @@ var _graphql = require("graphql");
|
|
|
8
8
|
const returnValue = value => {
|
|
9
9
|
return value;
|
|
10
10
|
};
|
|
11
|
-
const AnyScalar = new _graphql.GraphQLScalarType({
|
|
11
|
+
const AnyScalar = exports.AnyScalar = new _graphql.GraphQLScalarType({
|
|
12
12
|
name: "Any",
|
|
13
13
|
description: `A scalar type that represents an ambiguous value.`,
|
|
14
14
|
serialize: returnValue,
|
|
15
15
|
parseValue: returnValue
|
|
16
16
|
});
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=AnyScalar.js.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"names":["_graphql","require","returnValue","value","AnyScalar","exports","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,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,WAAW,GAAIC,KAAU,IAAU;EACrC,OAAOA,KAAK;AAChB,CAAC;AAEM,MAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC3CC,IAAI,EAAE,KAAK;EACXC,WAAW,EAAE,mDAAmD;EAChEC,SAAS,EAAEP,WAAW;EACtBQ,UAAU,EAAER;AAChB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.DateScalar = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
10
8
|
var _graphql = require("graphql");
|
|
11
|
-
const DateScalar = new _graphql.GraphQLScalarType(
|
|
9
|
+
const DateScalar = exports.DateScalar = new _graphql.GraphQLScalarType({
|
|
10
|
+
..._graphqlScalars.DateResolver,
|
|
12
11
|
serialize: value => {
|
|
13
12
|
if (!value) {
|
|
14
13
|
return null;
|
|
@@ -23,5 +22,6 @@ const DateScalar = new _graphql.GraphQLScalarType((0, _objectSpread2.default)((0
|
|
|
23
22
|
throw ex;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
})
|
|
27
|
-
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DateScalar.js.map
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","DateScalar","exports","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,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACO,MAAME,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5C,GAAGC,4BAAY;EACfC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,KAAK,CAAC;MAC5B,OAAOC,IAAI,CAACE,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1C,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIL,KAAK,CAACG,WAAW,EAAE;QACnB,OAAOH,KAAK,CAACG,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;MAC3C;MACA,MAAMC,EAAE;IACZ;EACJ;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.DateTimeScalar = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
10
8
|
var _graphql = require("graphql");
|
|
11
|
-
const DateTimeScalar = new _graphql.GraphQLScalarType(
|
|
9
|
+
const DateTimeScalar = exports.DateTimeScalar = new _graphql.GraphQLScalarType({
|
|
10
|
+
..._graphqlScalars.DateTimeResolver,
|
|
12
11
|
serialize: value => {
|
|
13
12
|
if (!value) {
|
|
14
13
|
return null;
|
|
@@ -23,5 +22,6 @@ const DateTimeScalar = new _graphql.GraphQLScalarType((0, _objectSpread2.default
|
|
|
23
22
|
throw ex;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
})
|
|
27
|
-
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DateTimeScalar.js.map
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","DateTimeScalar","exports","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,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACO,MAAME,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAIE,0BAAiB,CAAC;EAChD,GAAGC,gCAAgB;EACnBC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,KAAK,CAAC;MAC5B,OAAOC,IAAI,CAACE,WAAW,CAAC,CAAC;IAC7B,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIJ,KAAK,CAACG,WAAW,EAAE;QACnB,OAAOH,KAAK,CAACG,WAAW,CAAC,CAAC;MAC9B;MACA,MAAMC,EAAE;IACZ;EACJ;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -34,7 +34,7 @@ const validateTimeZone = value => {
|
|
|
34
34
|
* A custom type for dateTime with the timezone.
|
|
35
35
|
* Must be in format "YYYY-MM-ddTHH:mm:ss+HH:mm".
|
|
36
36
|
*/
|
|
37
|
-
const DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
37
|
+
const DateTimeZScalar = exports.DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
38
38
|
name: "DateTimeZ",
|
|
39
39
|
description: "A custom type for dateTime with the timezone.",
|
|
40
40
|
parseValue: value => {
|
|
@@ -47,4 +47,5 @@ const DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
|
47
47
|
return value;
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=DateTimeZScalar.js.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","_error","_interopRequireDefault","validateTimeZone","value","timeWithTimezone","split","WebinyError","separator","includes","zone","hoursMinutes","hours","minutes","undefined","length","DateTimeZScalar","exports","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,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,gBAAgB,GAAIC,KAAa,IAAW;EAC9C,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAC5C,IAAI,CAACD,gBAAgB,EAAE;IACnB,MAAM,IAAIE,cAAW,CACjB,kDAAkD,EAClD,0BAA0B,EAC1B;MACIH;IACJ,CACJ,CAAC;EACL;EACA,MAAMI,SAAS,GAAGH,gBAAgB,CAACI,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG;EAC5D,MAAMC,IAAI,GAAGL,gBAAgB,CAACC,KAAK,CAACE,SAAS,CAAC,CAAC,CAAC,CAAC;EACjD,IAAI,CAACE,IAAI,EAAE;IACP,MAAM,IAAIH,cAAW,CACjB,wCAAwC,EACxC,0BAA0B,EAC1B;MACIH,KAAK,EAAEC;IACX,CACJ,CAAC;EACL;EACA,MAAMM,YAAY,GAAGD,IAAI,CAACJ,KAAK,CAAC,GAAG,CAAC;EACpC,MAAM,CAACM,KAAK,EAAEC,OAAO,CAAC,GAAGF,YAAY;EACrC,IAAIC,KAAK,KAAKE,SAAS,IAAID,OAAO,KAAKC,SAAS,IAAIH,YAAY,CAACI,MAAM,KAAK,CAAC,EAAE;IAC3E,MAAM,IAAIR,cAAW,CACjB,gDAAgD,EAChD,0BAA0B,EAC1B;MACIH,KAAK,EAAEM;IACX,CACJ,CAAC;EACL;AACJ,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMM,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,IAAIE,0BAAiB,CAAC;EACjDC,IAAI,EAAE,WAAW;EACjBC,WAAW,EAAE,+CAA+C;EAC5DC,UAAU,EAAEjB,KAAK,IAAI;IACjB;IACAkB,gCAAgB,CAACD,UAAU,CAACjB,KAAK,CAAC;IAClCD,gBAAgB,CAACC,KAAK,CAAC;IACvB,OAAOA,KAAK;EAChB,CAAC;EACDmB,SAAS,EAAEnB,KAAK,IAAI;IAChB,OAAOA,KAAK;EAChB;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -5,5 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.JsonScalar = void 0;
|
|
7
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
8
|
-
const JsonScalar = _graphqlScalars.JSONResolver;
|
|
9
|
-
|
|
8
|
+
const JsonScalar = exports.JsonScalar = _graphqlScalars.JSONResolver;
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=JsonScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["JsonScalar","JSONResolver"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":";;;;;;AAAA;AACO,
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","JsonScalar","exports","JSONResolver"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACO,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGE,4BAAY","ignoreList":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
export declare const LongScalar: GraphQLScalarType;
|
|
@@ -1,9 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.LongScalar = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var _graphql = require("graphql");
|
|
9
|
+
var _language = require("graphql/language");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
const parseValue = value => {
|
|
12
|
+
if (String(value).includes(".")) {
|
|
13
|
+
throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
|
|
14
|
+
value
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (value === null || value === undefined) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (isNaN(value) === true) {
|
|
24
|
+
throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return parseInt(value);
|
|
29
|
+
};
|
|
30
|
+
const LongScalar = exports.LongScalar = new _graphql.GraphQLScalarType({
|
|
31
|
+
name: "Long",
|
|
32
|
+
description: "A custom input type to be used for large integers (Long).",
|
|
33
|
+
serialize: value => {
|
|
34
|
+
try {
|
|
35
|
+
return parseValue(value);
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
console.log({
|
|
38
|
+
message: "Value sent must be an integer.",
|
|
39
|
+
code: "INVALID_VALUE",
|
|
40
|
+
data: {
|
|
41
|
+
value
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
parseValue,
|
|
48
|
+
parseLiteral: ast => {
|
|
49
|
+
if (ast.kind === _language.Kind.INT) {
|
|
50
|
+
return parseInt(ast.value);
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Expected type Long, found {${ast.kind}}`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=LongScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LongScalar","
|
|
1
|
+
{"version":3,"names":["_graphql","require","_language","_error","_interopRequireDefault","parseValue","value","String","includes","WebinyError","undefined","isNaN","parseInt","LongScalar","exports","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Error"],"sources":["LongScalar.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).includes(\".\")) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n if (typeof value === \"number\") {\n return value;\n }\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n\n return parseInt(value);\n};\n\nexport const LongScalar = new GraphQLScalarType({\n name: \"Long\",\n description: \"A custom input type to be used for large integers (Long).\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be an integer.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n if (ast.kind === Kind.INT) {\n return parseInt(ast.value);\n }\n\n throw new Error(`Expected type Long, found {${ast.kind}}`);\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC7B,MAAM,IAAIC,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB;EAEA,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKI,SAAS,EAAE;IACvC,OAAO,IAAI;EACf;EAEA,IAAIC,KAAK,CAACL,KAAK,CAAC,KAAK,IAAI,EAAE;IACvB,MAAM,IAAIG,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EAEA,OAAOM,QAAQ,CAACN,KAAK,CAAC;AAC1B,CAAC;AAEM,MAAMO,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5CC,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2DAA2D;EACxEC,SAAS,EAAGZ,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,OAAOa,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,gCAAgC;QACzCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFlB;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVoB,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKC,cAAI,CAACC,GAAG,EAAE;MACvB,OAAOjB,QAAQ,CAACc,GAAG,CAACpB,KAAK,CAAC;IAC9B;IAEA,MAAM,IAAIwB,KAAK,CAAC,8BAA8BJ,GAAG,CAACC,IAAI,GAAG,CAAC;EAC9D;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ const parseValue = value => {
|
|
|
24
24
|
}
|
|
25
25
|
return parseFloat(value);
|
|
26
26
|
};
|
|
27
|
-
const NumberScalar = new _graphql.GraphQLScalarType({
|
|
27
|
+
const NumberScalar = exports.NumberScalar = new _graphql.GraphQLScalarType({
|
|
28
28
|
name: "Number",
|
|
29
29
|
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
30
30
|
serialize: value => {
|
|
@@ -43,13 +43,13 @@ const NumberScalar = new _graphql.GraphQLScalarType({
|
|
|
43
43
|
},
|
|
44
44
|
parseValue,
|
|
45
45
|
parseLiteral: ast => {
|
|
46
|
-
const value = ast.value;
|
|
47
46
|
if (ast.kind === _language.Kind.INT) {
|
|
48
|
-
return Number(value);
|
|
47
|
+
return Number(ast.value);
|
|
49
48
|
} else if (ast.kind === _language.Kind.FLOAT) {
|
|
50
|
-
return parseFloat(value);
|
|
49
|
+
return parseFloat(ast.value);
|
|
51
50
|
}
|
|
52
|
-
throw new Error(`Expected type Number, found {${
|
|
51
|
+
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
53
52
|
}
|
|
54
53
|
});
|
|
55
|
-
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=NumberScalar.js.map
|
|
@@ -1 +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
|
|
1
|
+
{"version":3,"names":["_graphql","require","_language","_error","_interopRequireDefault","parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","NumberScalar","exports","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 if (ast.kind === Kind.INT) {\n return Number(ast.value);\n } else if (ast.kind === Kind.FLOAT) {\n return parseFloat(ast.value);\n }\n throw new Error(`Expected type Number, found {${ast.kind}}`);\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;IACrC,MAAM,IAAIC,cAAW,CAAC,sCAAsC,EAAE,eAAe,EAAE;MAC3EH;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,OAAOA,KAAK;EAChB,CAAC,MAAM,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKI,SAAS,EAAE;IAC9C,OAAO,IAAI;EACf,CAAC,MAAM,IAAIC,KAAK,CAACL,KAAK,CAAC,KAAK,IAAI,EAAE;IAC9B,MAAM,IAAIG,cAAW,CAAC,8BAA8B,EAAE,eAAe,EAAE;MACnEH;IACJ,CAAC,CAAC;EACN;EACA,OAAOM,UAAU,CAACN,KAAK,CAAC;AAC5B,CAAC;AAEM,MAAMO,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC9CC,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,sEAAsE;EACnFC,SAAS,EAAGZ,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,OAAOa,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,8BAA8B;QACvCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFlB;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVoB,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKC,cAAI,CAACC,GAAG,EAAE;MACvB,OAAOC,MAAM,CAACJ,GAAG,CAACpB,KAAK,CAAC;IAC5B,CAAC,MAAM,IAAIoB,GAAG,CAACC,IAAI,KAAKC,cAAI,CAACG,KAAK,EAAE;MAChC,OAAOnB,UAAU,CAACc,GAAG,CAACpB,KAAK,CAAC;IAChC;IACA,MAAM,IAAI0B,KAAK,CAAC,gCAAgCN,GAAG,CAACC,IAAI,GAAG,CAAC;EAChE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -5,13 +5,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.RefInputScalar = void 0;
|
|
7
7
|
var _graphql = require("graphql");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const tests = [{
|
|
9
|
+
re: /^([0-9a-zA-Z_-]+)$/,
|
|
10
|
+
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
11
|
+
}, {
|
|
12
|
+
re: /^-/,
|
|
13
|
+
message: "Must not start with a dash (-)!"
|
|
14
|
+
}, {
|
|
15
|
+
re: /-$/,
|
|
16
|
+
message: "Must not end with a dash (-)!"
|
|
17
|
+
}, {
|
|
18
|
+
re: /^_/,
|
|
19
|
+
message: "Must not start with an underscore (_)!"
|
|
20
|
+
}, {
|
|
21
|
+
re: /_$/,
|
|
22
|
+
message: "Must not end with an underscore (_)!"
|
|
23
|
+
}];
|
|
24
|
+
const isValidId = value => {
|
|
25
|
+
if (typeof value !== "string" || value.length < 1) {
|
|
26
|
+
throw new Error("Must be a string with at least 1 character!");
|
|
11
27
|
}
|
|
12
|
-
|
|
28
|
+
for (const test of tests) {
|
|
29
|
+
if (test.re.test(value) === null) {
|
|
30
|
+
throw new Error(test.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
13
34
|
};
|
|
14
|
-
const RefInputScalar = new _graphql.GraphQLScalarType({
|
|
35
|
+
const RefInputScalar = exports.RefInputScalar = new _graphql.GraphQLScalarType({
|
|
15
36
|
name: "RefInput",
|
|
16
37
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
17
38
|
serialize: value => {
|
|
@@ -25,16 +46,16 @@ const RefInputScalar = new _graphql.GraphQLScalarType({
|
|
|
25
46
|
return null;
|
|
26
47
|
}
|
|
27
48
|
if (typeof value === "string") {
|
|
28
|
-
return
|
|
49
|
+
return isValidId(value);
|
|
29
50
|
}
|
|
30
51
|
if ("id" in value) {
|
|
31
|
-
return
|
|
52
|
+
return isValidId(value.id);
|
|
32
53
|
}
|
|
33
54
|
throw new Error("Invalid RefInput value!");
|
|
34
55
|
},
|
|
35
56
|
parseLiteral: ast => {
|
|
36
57
|
if (ast.kind === "StringValue") {
|
|
37
|
-
return
|
|
58
|
+
return isValidId(ast.value);
|
|
38
59
|
}
|
|
39
60
|
if (ast.kind === "ObjectValue") {
|
|
40
61
|
for (let i = 0; i < ast.fields.length; i++) {
|
|
@@ -43,12 +64,13 @@ const RefInputScalar = new _graphql.GraphQLScalarType({
|
|
|
43
64
|
value
|
|
44
65
|
} = ast.fields[i];
|
|
45
66
|
if (name.value === "id") {
|
|
46
|
-
// @ts-
|
|
47
|
-
return
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
return isValidId(value.value);
|
|
48
69
|
}
|
|
49
70
|
}
|
|
50
71
|
}
|
|
51
72
|
throw new Error("Invalid RefInput value!");
|
|
52
73
|
}
|
|
53
74
|
});
|
|
54
|
-
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=RefInputScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_graphql","require","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","exports","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EA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AI,IAAIA,KAAK,EAAE;MACf,OAAOD,SAAS,CAACC,KAAK,CAACU,EAAE,CAAC;IAC9B;IAEA,MAAM,IAAIR,KAAK,CAAC,yBAAyB,CAAC;EAC9C,CAAC;EACDU,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,OAAOf,SAAS,CAACc,GAAG,CAACb,KAAK,CAAC;IAC/B;IAEA,IAAIa,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,GAAG,CAACG,MAAM,CAACf,MAAM,EAAEc,CAAC,EAAE,EAAE;QACxC,MAAM;UAAER,IAAI;UAAEP;QAAM,CAAC,GAAGa,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACP,KAAK,KAAK,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -48,7 +48,7 @@ const convertToTime = value => {
|
|
|
48
48
|
} = parseTime(value);
|
|
49
49
|
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
50
50
|
};
|
|
51
|
-
const TimeScalar = new _graphql.GraphQLScalarType({
|
|
51
|
+
const TimeScalar = exports.TimeScalar = new _graphql.GraphQLScalarType({
|
|
52
52
|
name: "Time",
|
|
53
53
|
description: "A custom type to support time-only input.",
|
|
54
54
|
// sending to client
|
|
@@ -56,4 +56,5 @@ const TimeScalar = new _graphql.GraphQLScalarType({
|
|
|
56
56
|
// received from client
|
|
57
57
|
parseValue: convertToTime
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=TimeScalar.js.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"names":["_graphql","require","_error","_interopRequireDefault","re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","exports","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: string) => {\n if (!value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: string): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAc,IAAK;EAClC,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACpC,MAAM,IAAII,cAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEF;IAAM,CAAC,CAAC;EAC/F;EACA,MAA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,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2CAA2C;EACxD;EACAC,SAAS,EAAER,aAAa;EACxB;EACAS,UAAU,EAAET;AAChB,CAAC,CAAC","ignoreList":[]}
|
package/builtInTypes/index.js
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"names":["_AnyScalar","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_DateScalar","_DateTimeScalar","_DateTimeZScalar","_JsonScalar","_LongScalar","_NumberScalar","_RefInputScalar","_TimeScalar"],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,UAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,UAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,UAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,C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AAAA;AACA,IAAAY,WAAA,GAAAhB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAc,WAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAY,WAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,WAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HandlerGraphQLOptions } from "./types";
|
|
3
|
-
declare const _default: (options?: HandlerGraphQLOptions) =>
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types";
|
|
3
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
4
4
|
export default _default;
|
package/createGraphQLHandler.js
CHANGED
|
@@ -10,9 +10,23 @@ var _handler = require("@webiny/handler");
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
12
12
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
13
|
-
var _processRequestBody =
|
|
13
|
+
var _processRequestBody = require("./processRequestBody");
|
|
14
14
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
15
15
|
|
|
16
|
+
const createCacheKey = context => {
|
|
17
|
+
const plugins = (0, _createGraphQLSchema.getSchemaPlugins)(context);
|
|
18
|
+
// TODO: in the near future, we have to assign a fixed name to every
|
|
19
|
+
// TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
|
|
20
|
+
|
|
21
|
+
// TODO: `getCurrentTenant` should be injected as a parameter.
|
|
22
|
+
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
23
|
+
const tenant = context.tenancy?.getCurrentTenant();
|
|
24
|
+
|
|
25
|
+
// TODO: `getContentLocale` should be injected as a parameter.
|
|
26
|
+
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
27
|
+
const contentLocale = context.i18n?.getContentLocale();
|
|
28
|
+
return [tenant ? `tenant:${tenant.id}` : null, contentLocale ? `locale:${contentLocale.code}` : null, plugins.length.toString()].filter(Boolean).join("#");
|
|
29
|
+
};
|
|
16
30
|
const createRequestBody = body => {
|
|
17
31
|
/**
|
|
18
32
|
* We are trusting that the body payload is correct.
|
|
@@ -38,8 +52,9 @@ const formatErrorPayload = error => {
|
|
|
38
52
|
};
|
|
39
53
|
var _default = (options = {}) => {
|
|
40
54
|
let schema = undefined;
|
|
55
|
+
let cacheKey = undefined;
|
|
41
56
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
42
|
-
const path =
|
|
57
|
+
const path = options?.path || "/graphql";
|
|
43
58
|
const route = new _handler.RoutePlugin(async ({
|
|
44
59
|
onPost,
|
|
45
60
|
onOptions,
|
|
@@ -51,9 +66,11 @@ var _default = (options = {}) => {
|
|
|
51
66
|
}).send({}).hijack();
|
|
52
67
|
});
|
|
53
68
|
onPost(path, async (request, reply) => {
|
|
54
|
-
|
|
69
|
+
const contextCacheKey = createCacheKey(context);
|
|
70
|
+
if (!schema || cacheKey !== contextCacheKey) {
|
|
55
71
|
try {
|
|
56
72
|
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
73
|
+
cacheKey = contextCacheKey;
|
|
57
74
|
} catch (ex) {
|
|
58
75
|
return reply.code(500).send(formatErrorPayload(ex));
|
|
59
76
|
}
|
|
@@ -62,16 +79,23 @@ var _default = (options = {}) => {
|
|
|
62
79
|
try {
|
|
63
80
|
body = createRequestBody(request.body);
|
|
64
81
|
} catch (ex) {
|
|
65
|
-
console.
|
|
66
|
-
console.
|
|
82
|
+
console.error(`Error while creating the body request.`);
|
|
83
|
+
console.error(formatErrorPayload(ex));
|
|
67
84
|
throw ex;
|
|
68
85
|
}
|
|
69
86
|
try {
|
|
70
|
-
const result = await (0, _processRequestBody.
|
|
87
|
+
const result = await (0, _processRequestBody.processRequestBody)(body, schema, context);
|
|
88
|
+
/**
|
|
89
|
+
* IMPORTANT! Do not send anything if reply was already sent.
|
|
90
|
+
*/
|
|
91
|
+
if (reply.sent) {
|
|
92
|
+
console.warn("Reply already sent, cannot send the result (handler-graphql).");
|
|
93
|
+
return reply;
|
|
94
|
+
}
|
|
71
95
|
return reply.status(200).send(result);
|
|
72
96
|
} catch (ex) {
|
|
73
|
-
console.
|
|
74
|
-
console.
|
|
97
|
+
console.error(`Error while processing the body request.`);
|
|
98
|
+
console.error(formatErrorPayload(ex));
|
|
75
99
|
throw ex;
|
|
76
100
|
}
|
|
77
101
|
});
|
|
@@ -81,4 +105,6 @@ var _default = (options = {}) => {
|
|
|
81
105
|
type: "wcp-telemetry-tracker"
|
|
82
106
|
}, route];
|
|
83
107
|
};
|
|
84
|
-
exports.default = _default;
|
|
108
|
+
exports.default = _default;
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=createGraphQLHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","
|
|
1
|
+
{"version":3,"names":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","tenancy","getCurrentTenant","contentLocale","i18n","getContentLocale","id","code","length","toString","filter","Boolean","join","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","data","name","stack","_default","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","sent","warn","debugPlugins","exports","default"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type { Context } from \"@webiny/handler\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin } from \"@webiny/plugins/types\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler-graphql).\");\n return reply;\n }\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AAEA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA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