@webiny/handler-graphql 6.0.0-beta.0 → 6.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +19 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +2 -8
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.d.ts +1 -1
- package/builtInTypes/DateScalar.js +7 -10
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.d.ts +1 -1
- package/builtInTypes/DateTimeScalar.js +7 -10
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.d.ts +1 -1
- package/builtInTypes/DateTimeZScalar.js +8 -15
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +93 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -1
- package/builtInTypes/JsonScalar.js +2 -8
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +1 -1
- package/builtInTypes/LongScalar.js +8 -15
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +9 -16
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +8 -8
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.d.ts +1 -1
- package/builtInTypes/TimeScalar.js +9 -16
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.d.ts +10 -9
- package/builtInTypes/index.js +10 -104
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +25 -35
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -4
- package/createGraphQLSchema.js +68 -41
- package/createGraphQLSchema.js.map +1 -1
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +26 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +5 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +4 -11
- package/debugPlugins.js.map +1 -1
- package/errors.js +2 -10
- package/errors.js.map +1 -1
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +4 -0
- package/exports/api/graphql.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +64 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +29 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +5 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +1 -0
- package/features/GraphQLSchemaBuilder/feature.js +10 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +11 -0
- package/graphql/abstractions.core.js +10 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +4 -0
- package/graphql/abstractions.js.map +1 -0
- package/graphql/abstractions.public.d.ts +19 -0
- package/graphql/abstractions.public.js +12 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +10 -6
- package/index.js +11 -59
- package/index.js.map +1 -1
- package/interceptConsole.js +1 -8
- package/interceptConsole.js.map +1 -1
- package/package.json +23 -26
- package/plugins/GraphQLSchemaPlugin.d.ts +7 -3
- package/plugins/GraphQLSchemaPlugin.js +11 -12
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +1 -16
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -4
- package/processRequestBody.js +10 -10
- package/processRequestBody.js.map +1 -1
- package/responses.js +5 -16
- package/responses.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +19 -0
- package/utils/resolve.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# @webiny/handler-graphql
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/handler-graphql)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/handler-graphql)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { composeResolvers } from "@graphql-tools/resolvers-composition";
|
|
2
|
+
export class ResolverDecoration {
|
|
3
|
+
decorators = {};
|
|
4
|
+
addDecorators(resolverDecorators) {
|
|
5
|
+
for (const key in resolverDecorators) {
|
|
6
|
+
const decorators = resolverDecorators[key];
|
|
7
|
+
if (!decorators) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const existingDecorators = this.decorators[key] ?? [];
|
|
11
|
+
this.decorators[key] = [...existingDecorators, ...decorators];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
decorateResolvers(resolvers) {
|
|
15
|
+
return composeResolvers(resolvers, this.decorators);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=ResolverDecoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["composeResolvers","ResolverDecoration","decorators","addDecorators","resolverDecorators","key","existingDecorators","decorateResolvers","resolvers"],"sources":["ResolverDecoration.ts"],"sourcesContent":["import { composeResolvers } from \"@graphql-tools/resolvers-composition\";\nimport type { ResolverDecorators, Resolvers } from \"./types.js\";\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,SAASA,gBAAgB,QAAQ,sCAAsC;AAGvE,OAAO,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,OAAOR,gBAAgB,CAACQ,SAAS,EAAE,IAAI,CAACN,UAAU,CAAC;EACvD;AACJ","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const AnyScalar: GraphQLScalarType
|
|
2
|
+
export declare const AnyScalar: GraphQLScalarType<any, any>;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AnyScalar = void 0;
|
|
7
|
-
var _graphql = require("graphql");
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
8
2
|
const returnValue = value => {
|
|
9
3
|
return value;
|
|
10
4
|
};
|
|
11
|
-
const AnyScalar =
|
|
5
|
+
export const AnyScalar = new GraphQLScalarType({
|
|
12
6
|
name: "Any",
|
|
13
7
|
description: `A scalar type that represents an ambiguous value.`,
|
|
14
8
|
serialize: returnValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","returnValue","value","AnyScalar","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,SAASA,iBAAiB,QAAQ,SAAS;AAE3C,MAAMC,WAAW,GAAIC,KAAU,IAAU;EACrC,OAAOA,KAAK;AAChB,CAAC;AAED,OAAO,MAAMC,SAAS,GAAG,IAAIH,iBAAiB,CAAC;EAC3CI,IAAI,EAAE,KAAK;EACXC,WAAW,EAAE,mDAAmD;EAChEC,SAAS,EAAEL,WAAW;EACtBM,UAAU,EAAEN;AAChB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const DateScalar: GraphQLScalarType
|
|
2
|
+
export declare const DateScalar: GraphQLScalarType<string | Date, string>;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _graphql = require("graphql");
|
|
9
|
-
const DateScalar = exports.DateScalar = new _graphql.GraphQLScalarType({
|
|
10
|
-
..._graphqlScalars.DateResolver,
|
|
1
|
+
import { DateResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
export const DateScalar = new GraphQLScalarType({
|
|
4
|
+
...DateResolver,
|
|
5
|
+
/**
|
|
6
|
+
* We can set value as any because we are handling it.
|
|
7
|
+
*/
|
|
11
8
|
serialize: value => {
|
|
12
9
|
if (!value) {
|
|
13
10
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DateResolver","GraphQLScalarType","DateScalar","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<Date | string, string>({\n ...DateResolver,\n /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\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,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,iBAAiB,QAAQ,SAAS;AAC3C,OAAO,MAAMC,UAAU,GAAG,IAAID,iBAAiB,CAAwB;EACnE,GAAGD,YAAY;EACf;AACJ;AACA;EACIG,SAAS,EAAGC,KAAU,IAAK;IACvB,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,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const DateTimeScalar: GraphQLScalarType
|
|
2
|
+
export declare const DateTimeScalar: GraphQLScalarType<Date, any>;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _graphql = require("graphql");
|
|
9
|
-
const DateTimeScalar = exports.DateTimeScalar = new _graphql.GraphQLScalarType({
|
|
10
|
-
..._graphqlScalars.DateTimeResolver,
|
|
1
|
+
import { DateTimeResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
export const DateTimeScalar = new GraphQLScalarType({
|
|
4
|
+
...DateTimeResolver,
|
|
5
|
+
/**
|
|
6
|
+
* We can set value as any because we are handling it.
|
|
7
|
+
*/
|
|
11
8
|
serialize: value => {
|
|
12
9
|
if (!value) {
|
|
13
10
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DateTimeResolver","GraphQLScalarType","DateTimeScalar","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 /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\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,SAASA,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,iBAAiB,QAAQ,SAAS;AAC3C,OAAO,MAAMC,cAAc,GAAG,IAAID,iBAAiB,CAAC;EAChD,GAAGD,gBAAgB;EACnB;AACJ;AACA;EACIG,SAAS,EAAGC,KAAU,IAAK;IACvB,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":[]}
|
|
@@ -3,4 +3,4 @@ import { GraphQLScalarType } from "graphql";
|
|
|
3
3
|
* A custom type for dateTime with the timezone.
|
|
4
4
|
* Must be in format "YYYY-MM-ddTHH:mm:ss+HH:mm".
|
|
5
5
|
*/
|
|
6
|
-
export declare const DateTimeZScalar: GraphQLScalarType
|
|
6
|
+
export declare const DateTimeZScalar: GraphQLScalarType<unknown, unknown>;
|
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.DateTimeZScalar = void 0;
|
|
8
|
-
var _graphqlScalars = require("graphql-scalars");
|
|
9
|
-
var _graphql = require("graphql");
|
|
10
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
1
|
+
import { DateTimeResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
import WebinyError from "@webiny/error";
|
|
11
4
|
const validateTimeZone = value => {
|
|
12
5
|
const timeWithTimezone = value.split("T")[1];
|
|
13
6
|
if (!timeWithTimezone) {
|
|
14
|
-
throw new
|
|
7
|
+
throw new WebinyError("Could not extract time with timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
15
8
|
value
|
|
16
9
|
});
|
|
17
10
|
}
|
|
18
11
|
const separator = timeWithTimezone.includes("-") ? "-" : "+";
|
|
19
12
|
const zone = timeWithTimezone.split(separator)[1];
|
|
20
13
|
if (!zone) {
|
|
21
|
-
throw new
|
|
14
|
+
throw new WebinyError("Could not extract timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
22
15
|
value: timeWithTimezone
|
|
23
16
|
});
|
|
24
17
|
}
|
|
25
18
|
const hoursMinutes = zone.split(":");
|
|
26
19
|
const [hours, minutes] = hoursMinutes;
|
|
27
20
|
if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {
|
|
28
|
-
throw new
|
|
21
|
+
throw new WebinyError("Could not extract hours or minutes from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
29
22
|
value: zone
|
|
30
23
|
});
|
|
31
24
|
}
|
|
@@ -34,12 +27,12 @@ const validateTimeZone = value => {
|
|
|
34
27
|
* A custom type for dateTime with the timezone.
|
|
35
28
|
* Must be in format "YYYY-MM-ddTHH:mm:ss+HH:mm".
|
|
36
29
|
*/
|
|
37
|
-
const DateTimeZScalar =
|
|
30
|
+
export const DateTimeZScalar = new GraphQLScalarType({
|
|
38
31
|
name: "DateTimeZ",
|
|
39
32
|
description: "A custom type for dateTime with the timezone.",
|
|
40
33
|
parseValue: value => {
|
|
41
34
|
// this serves as validator
|
|
42
|
-
|
|
35
|
+
DateTimeResolver.parseValue(value);
|
|
43
36
|
validateTimeZone(value);
|
|
44
37
|
return value;
|
|
45
38
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DateTimeResolver","GraphQLScalarType","WebinyError","validateTimeZone","value","timeWithTimezone","split","separator","includes","zone","hoursMinutes","hours","minutes","undefined","length","DateTimeZScalar","name","description","parseValue","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 as string);\n return value;\n },\n serialize: value => {\n return value;\n }\n});\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,iBAAiB,QAAQ,SAAS;AAC3C,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,gBAAgB,GAAIC,KAAa,IAAW;EAC9C,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAC5C,IAAI,CAACD,gBAAgB,EAAE;IACnB,MAAM,IAAIH,WAAW,CACjB,kDAAkD,EAClD,0BAA0B,EAC1B;MACIE;IACJ,CACJ,CAAC;EACL;EACA,MAAMG,SAAS,GAAGF,gBAAgB,CAACG,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG;EAC5D,MAAMC,IAAI,GAAGJ,gBAAgB,CAACC,KAAK,CAACC,SAAS,CAAC,CAAC,CAAC,CAAC;EACjD,IAAI,CAACE,IAAI,EAAE;IACP,MAAM,IAAIP,WAAW,CACjB,wCAAwC,EACxC,0BAA0B,EAC1B;MACIE,KAAK,EAAEC;IACX,CACJ,CAAC;EACL;EACA,MAAMK,YAAY,GAAGD,IAAI,CAACH,KAAK,CAAC,GAAG,CAAC;EACpC,MAAM,CAACK,KAAK,EAAEC,OAAO,CAAC,GAAGF,YAAY;EACrC,IAAIC,KAAK,KAAKE,SAAS,IAAID,OAAO,KAAKC,SAAS,IAAIH,YAAY,CAACI,MAAM,KAAK,CAAC,EAAE;IAC3E,MAAM,IAAIZ,WAAW,CACjB,gDAAgD,EAChD,0BAA0B,EAC1B;MACIE,KAAK,EAAEK;IACX,CACJ,CAAC;EACL;AACJ,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMM,eAAe,GAAG,IAAId,iBAAiB,CAAC;EACjDe,IAAI,EAAE,WAAW;EACjBC,WAAW,EAAE,+CAA+C;EAC5DC,UAAU,EAAEd,KAAK,IAAI;IACjB;IACAJ,gBAAgB,CAACkB,UAAU,CAACd,KAAK,CAAC;IAClCD,gBAAgB,CAACC,KAAe,CAAC;IACjC,OAAOA,KAAK;EAChB,CAAC;EACDe,SAAS,EAAEf,KAAK,IAAI;IAChB,OAAOA,KAAK;EAChB;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { GraphQLScalarType, GraphQLError } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
3
|
+
export const IconScalar = new GraphQLScalarType({
|
|
4
|
+
name: "Icon",
|
|
5
|
+
description: "Icon scalar that accepts string or object {type, name, value}",
|
|
6
|
+
// Serialize for output - always return object structure
|
|
7
|
+
serialize(value) {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return {
|
|
10
|
+
type: "icon",
|
|
11
|
+
name: value,
|
|
12
|
+
value: undefined
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (value && typeof value === "object") {
|
|
16
|
+
// Validate structure
|
|
17
|
+
if (typeof value.type !== "string" || typeof value.name !== "string") {
|
|
18
|
+
throw new GraphQLError("Icon object must have string type and name");
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
type: value.type,
|
|
22
|
+
name: value.name,
|
|
23
|
+
value: value.value
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
throw new GraphQLError("Icon must be a string or object");
|
|
27
|
+
},
|
|
28
|
+
// Parse from variables (JSON input)
|
|
29
|
+
parseValue(value) {
|
|
30
|
+
// String input → convert to object
|
|
31
|
+
if (typeof value === "string") {
|
|
32
|
+
return {
|
|
33
|
+
type: "icon",
|
|
34
|
+
name: value
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Object input → validate and return
|
|
39
|
+
if (value && typeof value === "object") {
|
|
40
|
+
if (typeof value.type !== "string" || typeof value.name !== "string") {
|
|
41
|
+
throw new GraphQLError("Icon object must have string type and name");
|
|
42
|
+
}
|
|
43
|
+
if (value.value !== undefined && typeof value.value !== "string") {
|
|
44
|
+
throw new GraphQLError("Icon value must be a string if provided");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: value.type,
|
|
48
|
+
name: value.name,
|
|
49
|
+
...(value.value !== undefined && {
|
|
50
|
+
value: value.value
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
throw new GraphQLError("Icon must be a string or object");
|
|
55
|
+
},
|
|
56
|
+
// Parse from inline query literals
|
|
57
|
+
parseLiteral(ast) {
|
|
58
|
+
// String literal
|
|
59
|
+
if (ast.kind === Kind.STRING) {
|
|
60
|
+
return {
|
|
61
|
+
type: "icon",
|
|
62
|
+
name: ast.value
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Object literal
|
|
67
|
+
if (ast.kind === Kind.OBJECT) {
|
|
68
|
+
const fields = {};
|
|
69
|
+
ast.fields.forEach(field => {
|
|
70
|
+
if (field.value.kind === Kind.STRING) {
|
|
71
|
+
fields[field.name.value] = field.value.value;
|
|
72
|
+
} else {
|
|
73
|
+
throw new GraphQLError("Icon object fields must be strings");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Validate required fields
|
|
78
|
+
if (!fields.type || !fields.name) {
|
|
79
|
+
throw new GraphQLError("Icon object must have type and name");
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
type: fields.type,
|
|
83
|
+
name: fields.name,
|
|
84
|
+
...(fields.value && {
|
|
85
|
+
value: fields.value
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
throw new GraphQLError("Icon must be a string or object literal");
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=IconScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","GraphQLError","Kind","IconScalar","name","description","serialize","value","type","undefined","parseValue","parseLiteral","ast","kind","STRING","OBJECT","fields","forEach","field"],"sources":["IconScalar.ts"],"sourcesContent":["import { GraphQLScalarType, GraphQLError } from \"graphql\";\nimport { Kind } from \"graphql/language/index.js\";\n\nexport const IconScalar = new GraphQLScalarType({\n name: \"Icon\",\n description: \"Icon scalar that accepts string or object {type, name, value}\",\n\n // Serialize for output - always return object structure\n serialize(value: any) {\n if (typeof value === \"string\") {\n return { type: \"icon\", name: value, value: undefined };\n }\n\n if (value && typeof value === \"object\") {\n // Validate structure\n if (typeof value.type !== \"string\" || typeof value.name !== \"string\") {\n throw new GraphQLError(\"Icon object must have string type and name\");\n }\n\n return {\n type: value.type,\n name: value.name,\n value: value.value\n };\n }\n\n throw new GraphQLError(\"Icon must be a string or object\");\n },\n\n // Parse from variables (JSON input)\n parseValue(value: any) {\n // String input → convert to object\n if (typeof value === \"string\") {\n return { type: \"icon\", name: value };\n }\n\n // Object input → validate and return\n if (value && typeof value === \"object\") {\n if (typeof value.type !== \"string\" || typeof value.name !== \"string\") {\n throw new GraphQLError(\"Icon object must have string type and name\");\n }\n\n if (value.value !== undefined && typeof value.value !== \"string\") {\n throw new GraphQLError(\"Icon value must be a string if provided\");\n }\n\n return {\n type: value.type,\n name: value.name,\n ...(value.value !== undefined && { value: value.value })\n };\n }\n\n throw new GraphQLError(\"Icon must be a string or object\");\n },\n\n // Parse from inline query literals\n parseLiteral(ast) {\n // String literal\n if (ast.kind === Kind.STRING) {\n return { type: \"icon\", name: ast.value };\n }\n\n // Object literal\n if (ast.kind === Kind.OBJECT) {\n const fields: Record<string, string> = {};\n\n ast.fields.forEach(field => {\n if (field.value.kind === Kind.STRING) {\n fields[field.name.value] = field.value.value;\n } else {\n throw new GraphQLError(\"Icon object fields must be strings\");\n }\n });\n\n // Validate required fields\n if (!fields.type || !fields.name) {\n throw new GraphQLError(\"Icon object must have type and name\");\n }\n\n return {\n type: fields.type,\n name: fields.name,\n ...(fields.value && { value: fields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M,CAACZ,IAAI;QACjB,IAAIY,MAAM,CAACT,KAAK,IAAI;UAAEA,KAAK,EAAES,MAAM,CAACT;QAAM,CAAC;MAC/C,CAAC;IACL;IAEA,MAAM,IAAIN,YAAY,CAAC,yCAAyC,CAAC;EACrE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const JsonScalar: import("graphql").GraphQLScalarType
|
|
1
|
+
export declare const JsonScalar: import("graphql").GraphQLScalarType<any, any>;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.JsonScalar = void 0;
|
|
7
|
-
var _graphqlScalars = require("graphql-scalars");
|
|
8
|
-
const JsonScalar = exports.JsonScalar = _graphqlScalars.JSONResolver;
|
|
1
|
+
import { JSONResolver } from "graphql-scalars";
|
|
2
|
+
export const JsonScalar = JSONResolver;
|
|
9
3
|
|
|
10
4
|
//# sourceMappingURL=JsonScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["JSONResolver","JsonScalar"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,OAAO,MAAMC,UAAU,GAAGD,YAAY","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const LongScalar: GraphQLScalarType
|
|
2
|
+
export declare const LongScalar: GraphQLScalarType<number | null, number | null>;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.LongScalar = void 0;
|
|
8
|
-
var _graphql = require("graphql");
|
|
9
|
-
var _language = require("graphql/language");
|
|
10
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
3
|
+
import WebinyError from "@webiny/error";
|
|
11
4
|
const parseValue = value => {
|
|
12
5
|
if (String(value).includes(".")) {
|
|
13
|
-
throw new
|
|
6
|
+
throw new WebinyError("Value sent must be an integer.", "INVALID_VALUE", {
|
|
14
7
|
value
|
|
15
8
|
});
|
|
16
9
|
}
|
|
@@ -21,19 +14,19 @@ const parseValue = value => {
|
|
|
21
14
|
return null;
|
|
22
15
|
}
|
|
23
16
|
if (isNaN(value) === true) {
|
|
24
|
-
throw new
|
|
17
|
+
throw new WebinyError("Value sent must be an integer.", "INVALID_VALUE", {
|
|
25
18
|
value
|
|
26
19
|
});
|
|
27
20
|
}
|
|
28
21
|
return parseInt(value);
|
|
29
22
|
};
|
|
30
|
-
const LongScalar =
|
|
23
|
+
export const LongScalar = new GraphQLScalarType({
|
|
31
24
|
name: "Long",
|
|
32
25
|
description: "A custom input type to be used for large integers (Long).",
|
|
33
26
|
serialize: value => {
|
|
34
27
|
try {
|
|
35
28
|
return parseValue(value);
|
|
36
|
-
} catch
|
|
29
|
+
} catch {
|
|
37
30
|
console.log({
|
|
38
31
|
message: "Value sent must be an integer.",
|
|
39
32
|
code: "INVALID_VALUE",
|
|
@@ -46,7 +39,7 @@ const LongScalar = exports.LongScalar = new _graphql.GraphQLScalarType({
|
|
|
46
39
|
},
|
|
47
40
|
parseValue,
|
|
48
41
|
parseLiteral: ast => {
|
|
49
|
-
if (ast.kind ===
|
|
42
|
+
if (ast.kind === Kind.INT) {
|
|
50
43
|
return parseInt(ast.value);
|
|
51
44
|
}
|
|
52
45
|
throw new Error(`Expected type Long, found {${ast.kind}}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","Kind","WebinyError","parseValue","value","String","includes","undefined","isNaN","parseInt","LongScalar","name","description","serialize","console","log","message","code","data","parseLiteral","ast","kind","INT","Error"],"sources":["LongScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language/index.js\";\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 {\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,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,SAASC,IAAI,QAAQ,2BAA2B;AAChD,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC7B,MAAM,IAAIJ,WAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEE;IACJ,CAAC,CAAC;EACN;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB;EAEA,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKG,SAAS,EAAE;IACvC,OAAO,IAAI;EACf;EAEA,IAAIC,KAAK,CAACJ,KAAK,CAAC,KAAK,IAAI,EAAE;IACvB,MAAM,IAAIF,WAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEE;IACJ,CAAC,CAAC;EACN;EAEA,OAAOK,QAAQ,CAACL,KAAK,CAAC;AAC1B,CAAC;AAED,OAAO,MAAMM,UAAU,GAAG,IAAIV,iBAAiB,CAAC;EAC5CW,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2DAA2D;EACxEC,SAAS,EAAGT,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,MAAM;MACJU,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,gCAAgC;QACzCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFd;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVgB,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKpB,IAAI,CAACqB,GAAG,EAAE;MACvB,OAAOb,QAAQ,CAACW,GAAG,CAAChB,KAAK,CAAC;IAC9B;IAEA,MAAM,IAAImB,KAAK,CAAC,8BAA8BH,GAAG,CAACC,IAAI,GAAG,CAAC;EAC9D;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const NumberScalar: GraphQLScalarType
|
|
2
|
+
export declare const NumberScalar: GraphQLScalarType<number | null, number | null>;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.NumberScalar = void 0;
|
|
8
|
-
var _graphql = require("graphql");
|
|
9
|
-
var _language = require("graphql/language");
|
|
10
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
3
|
+
import WebinyError from "@webiny/error";
|
|
11
4
|
const parseValue = value => {
|
|
12
5
|
if (String(value).match(/^0x/) !== null) {
|
|
13
|
-
throw new
|
|
6
|
+
throw new WebinyError("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
14
7
|
value
|
|
15
8
|
});
|
|
16
9
|
} else if (typeof value === "number") {
|
|
@@ -18,19 +11,19 @@ const parseValue = value => {
|
|
|
18
11
|
} else if (value === null || value === undefined) {
|
|
19
12
|
return null;
|
|
20
13
|
} else if (isNaN(value) === true) {
|
|
21
|
-
throw new
|
|
14
|
+
throw new WebinyError("Value sent must be a number.", "INVALID_VALUE", {
|
|
22
15
|
value
|
|
23
16
|
});
|
|
24
17
|
}
|
|
25
18
|
return parseFloat(value);
|
|
26
19
|
};
|
|
27
|
-
const NumberScalar =
|
|
20
|
+
export const NumberScalar = new GraphQLScalarType({
|
|
28
21
|
name: "Number",
|
|
29
22
|
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
30
23
|
serialize: value => {
|
|
31
24
|
try {
|
|
32
25
|
return parseValue(value);
|
|
33
|
-
} catch
|
|
26
|
+
} catch {
|
|
34
27
|
console.log({
|
|
35
28
|
message: "Value sent must be a number.",
|
|
36
29
|
code: "INVALID_VALUE",
|
|
@@ -43,9 +36,9 @@ const NumberScalar = exports.NumberScalar = new _graphql.GraphQLScalarType({
|
|
|
43
36
|
},
|
|
44
37
|
parseValue,
|
|
45
38
|
parseLiteral: ast => {
|
|
46
|
-
if (ast.kind ===
|
|
39
|
+
if (ast.kind === Kind.INT) {
|
|
47
40
|
return Number(ast.value);
|
|
48
|
-
} else if (ast.kind ===
|
|
41
|
+
} else if (ast.kind === Kind.FLOAT) {
|
|
49
42
|
return parseFloat(ast.value);
|
|
50
43
|
}
|
|
51
44
|
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","Kind","WebinyError","parseValue","value","String","match","undefined","isNaN","parseFloat","NumberScalar","name","description","serialize","console","log","message","code","data","parseLiteral","ast","kind","INT","Number","FLOAT","Error"],"sources":["NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language/index.js\";\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 {\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,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,SAASC,IAAI,QAAQ,2BAA2B;AAChD,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;IACrC,MAAM,IAAIJ,WAAW,CAAC,sCAAsC,EAAE,eAAe,EAAE;MAC3EE;IACJ,C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2
|
-
export declare const RefInputScalar: GraphQLScalarType
|
|
2
|
+
export declare const RefInputScalar: GraphQLScalarType<string | null, any>;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RefInputScalar = void 0;
|
|
7
|
-
var _graphql = require("graphql");
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
8
2
|
const tests = [{
|
|
9
3
|
re: /^([0-9a-zA-Z_-]+)$/,
|
|
10
4
|
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
@@ -32,15 +26,21 @@ const isValidId = value => {
|
|
|
32
26
|
}
|
|
33
27
|
return value;
|
|
34
28
|
};
|
|
35
|
-
const RefInputScalar =
|
|
29
|
+
export const RefInputScalar = new GraphQLScalarType({
|
|
36
30
|
name: "RefInput",
|
|
37
31
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
32
|
+
/**
|
|
33
|
+
* We can set value as any because we are handling it.
|
|
34
|
+
*/
|
|
38
35
|
serialize: value => {
|
|
39
36
|
if (!value || value.id === null) {
|
|
40
37
|
return null;
|
|
41
38
|
}
|
|
42
39
|
return typeof value === "string" ? value : value.id;
|
|
43
40
|
},
|
|
41
|
+
/**
|
|
42
|
+
* We can set value as any because we are handling it.
|
|
43
|
+
*/
|
|
44
44
|
parseValue: value => {
|
|
45
45
|
if (!value || value.id === null) {
|
|
46
46
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n /**\n * We can set value as any because we are handling it.\n */\n parseValue: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAE3C,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EAAE,oBAAoB;EACxBC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAA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AAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,OAAOb,SAAS,CAACY,GAAG,CAACX,KAAK,CAAC;IAC/B;IAEA,IAAIW,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,GAAG,CAACG,MAAM,CAACb,MAAM,EAAEY,CAAC,EAAE,EAAE;QACxC,MAAM;UAAER,IAAI;UAAEL;QAAM,CAAC,GAAGW,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACL,KAAK,KAAK,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const TimeScalar: GraphQLScalarType
|
|
2
|
+
export declare const TimeScalar: GraphQLScalarType<string, string>;
|