@webiny/handler-graphql 6.3.0 → 6.4.0-beta.1
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.js +18 -14
- package/ResolverDecoration.js.map +1 -1
- package/builtInTypes/AnyScalar.js +7 -8
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.js +12 -18
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +12 -18
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +23 -35
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/IconScalar.js +59 -87
- package/builtInTypes/IconScalar.js.map +1 -1
- package/builtInTypes/JsonScalar.js +2 -1
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.js +30 -39
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.js +31 -38
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.js +45 -68
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +28 -41
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.js +0 -2
- package/createGraphQLHandler.js +69 -80
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.js +49 -66
- package/createGraphQLSchema.js.map +1 -1
- package/createRequestBody.js +20 -18
- package/createRequestBody.js.map +1 -1
- package/createResolverDecorator.js +2 -3
- package/createResolverDecorator.js.map +1 -1
- package/debugPlugins.js +24 -27
- package/debugPlugins.js.map +1 -1
- package/errors.js +6 -5
- package/errors.js.map +1 -1
- package/exports/api/graphql.js +1 -3
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +52 -59
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -1
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +27 -21
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -1
- package/features/GraphQLSchemaBuilder/abstractions.js +3 -2
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -1
- package/features/GraphQLSchemaBuilder/feature.js +6 -5
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -1
- package/graphql/abstractions.core.js +2 -7
- package/graphql/abstractions.core.js.map +1 -1
- package/graphql/abstractions.js +0 -2
- package/graphql/abstractions.public.js +2 -8
- package/graphql/abstractions.public.js.map +1 -1
- package/index.js +2 -3
- package/index.js.map +1 -1
- package/interceptConsole.js +30 -27
- package/interceptConsole.js.map +1 -1
- package/package.json +14 -14
- package/plugins/GraphQLSchemaPlugin.js +20 -21
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.js +0 -2
- package/processRequestBody.js +33 -36
- package/processRequestBody.js.map +1 -1
- package/responses.js +48 -65
- package/responses.js.map +1 -1
- package/types.js +0 -3
- package/utils/index.js +0 -2
- package/utils/resolve.js +15 -14
- package/utils/resolve.js.map +1 -1
- package/builtInTypes/index.js.map +0 -1
- package/exports/api/graphql.js.map +0 -1
- package/graphql/abstractions.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/index.js.map +0 -1
package/ResolverDecoration.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { composeResolvers } from "@graphql-tools/resolvers-composition";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
class ResolverDecoration {
|
|
3
|
+
addDecorators(resolverDecorators) {
|
|
4
|
+
for(const key in resolverDecorators){
|
|
5
|
+
const decorators = resolverDecorators[key];
|
|
6
|
+
if (!decorators) continue;
|
|
7
|
+
const existingDecorators = this.decorators[key] ?? [];
|
|
8
|
+
this.decorators[key] = [
|
|
9
|
+
...existingDecorators,
|
|
10
|
+
...decorators
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
decorateResolvers(resolvers) {
|
|
15
|
+
return composeResolvers(resolvers, this.decorators);
|
|
16
|
+
}
|
|
17
|
+
constructor(){
|
|
18
|
+
this.decorators = {};
|
|
12
19
|
}
|
|
13
|
-
}
|
|
14
|
-
decorateResolvers(resolvers) {
|
|
15
|
-
return composeResolvers(resolvers, this.decorators);
|
|
16
|
-
}
|
|
17
20
|
}
|
|
21
|
+
export { ResolverDecoration };
|
|
18
22
|
|
|
19
23
|
//# sourceMappingURL=ResolverDecoration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ResolverDecoration.js","sources":["../src/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"],"names":["ResolverDecoration","resolverDecorators","key","decorators","existingDecorators","resolvers","composeResolvers"],"mappings":";AAGO,MAAMA;IAGT,cAAcC,kBAAsC,EAAE;QAClD,IAAK,MAAMC,OAAOD,mBAAoB;YAClC,MAAME,aAAaF,kBAAkB,CAACC,IAAI;YAC1C,IAAI,CAACC,YACD;YAGJ,MAAMC,qBAAqB,IAAI,CAAC,UAAU,CAACF,IAAI,IAAI,EAAE;YACrD,IAAI,CAAC,UAAU,CAACA,IAAI,GAAG;mBAAIE;mBAAuBD;aAAW;QACjE;IACJ;IAEA,kBAAkBE,SAA6B,EAAE;QAC7C,OAAOC,iBAAiBD,WAAW,IAAI,CAAC,UAAU;IACtD;;aAhBQ,UAAU,GAAuB,CAAC;;AAiB9C"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
const returnValue = value
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
serialize: returnValue,
|
|
9
|
-
parseValue: returnValue
|
|
2
|
+
const returnValue = (value)=>value;
|
|
3
|
+
const AnyScalar = new GraphQLScalarType({
|
|
4
|
+
name: "Any",
|
|
5
|
+
description: "A scalar type that represents an ambiguous value.",
|
|
6
|
+
serialize: returnValue,
|
|
7
|
+
parseValue: returnValue
|
|
10
8
|
});
|
|
9
|
+
export { AnyScalar };
|
|
11
10
|
|
|
12
11
|
//# sourceMappingURL=AnyScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/AnyScalar.js","sources":["../../src/builtInTypes/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"],"names":["returnValue","value","AnyScalar","GraphQLScalarType"],"mappings":";AAEA,MAAMA,cAAc,CAACC,QACVA;AAGJ,MAAMC,YAAY,IAAIC,kBAAkB;IAC3C,MAAM;IACN,aAAa;IACb,WAAWH;IACX,YAAYA;AAChB"}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { DateResolver } from "graphql-scalars";
|
|
2
2
|
import { GraphQLScalarType } from "graphql";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const DateScalar = new GraphQLScalarType({
|
|
4
|
+
...DateResolver,
|
|
5
|
+
serialize: (value)=>{
|
|
6
|
+
if (!value) return null;
|
|
7
|
+
try {
|
|
8
|
+
const date = new Date(value);
|
|
9
|
+
return date.toISOString().slice(0, 10);
|
|
10
|
+
} catch (ex) {
|
|
11
|
+
if (value.toISOString) return value.toISOString().slice(0, 10);
|
|
12
|
+
throw ex;
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
|
-
try {
|
|
13
|
-
const date = new Date(value);
|
|
14
|
-
return date.toISOString().slice(0, 10);
|
|
15
|
-
} catch (ex) {
|
|
16
|
-
if (value.toISOString) {
|
|
17
|
-
return value.toISOString().slice(0, 10);
|
|
18
|
-
}
|
|
19
|
-
throw ex;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
15
|
});
|
|
16
|
+
export { DateScalar };
|
|
23
17
|
|
|
24
18
|
//# sourceMappingURL=DateScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/DateScalar.js","sources":["../../src/builtInTypes/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"],"names":["DateScalar","GraphQLScalarType","DateResolver","value","date","Date","ex"],"mappings":";;AAEO,MAAMA,aAAa,IAAIC,kBAAyC;IACnE,GAAGC,YAAY;IAIf,WAAW,CAACC;QACR,IAAI,CAACA,OACD,OAAO;QAEX,IAAI;YACA,MAAMC,OAAO,IAAIC,KAAKF;YACtB,OAAOC,KAAK,WAAW,GAAG,KAAK,CAAC,GAAG;QACvC,EAAE,OAAOE,IAAI;YACT,IAAIH,MAAM,WAAW,EACjB,OAAOA,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG;YAExC,MAAMG;QACV;IACJ;AACJ"}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { DateTimeResolver } from "graphql-scalars";
|
|
2
2
|
import { GraphQLScalarType } from "graphql";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const DateTimeScalar = new GraphQLScalarType({
|
|
4
|
+
...DateTimeResolver,
|
|
5
|
+
serialize: (value)=>{
|
|
6
|
+
if (!value) return null;
|
|
7
|
+
try {
|
|
8
|
+
const date = new Date(value);
|
|
9
|
+
return date.toISOString();
|
|
10
|
+
} catch (ex) {
|
|
11
|
+
if (value.toISOString) return value.toISOString();
|
|
12
|
+
throw ex;
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
|
-
try {
|
|
13
|
-
const date = new Date(value);
|
|
14
|
-
return date.toISOString();
|
|
15
|
-
} catch (ex) {
|
|
16
|
-
if (value.toISOString) {
|
|
17
|
-
return value.toISOString();
|
|
18
|
-
}
|
|
19
|
-
throw ex;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
15
|
});
|
|
16
|
+
export { DateTimeScalar };
|
|
23
17
|
|
|
24
18
|
//# sourceMappingURL=DateTimeScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/DateTimeScalar.js","sources":["../../src/builtInTypes/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"],"names":["DateTimeScalar","GraphQLScalarType","DateTimeResolver","value","date","Date","ex"],"mappings":";;AAEO,MAAMA,iBAAiB,IAAIC,kBAAkB;IAChD,GAAGC,gBAAgB;IAInB,WAAW,CAACC;QACR,IAAI,CAACA,OACD,OAAO;QAEX,IAAI;YACA,MAAMC,OAAO,IAAIC,KAAKF;YACtB,OAAOC,KAAK,WAAW;QAC3B,EAAE,OAAOE,IAAI;YACT,IAAIH,MAAM,WAAW,EACjB,OAAOA,MAAM,WAAW;YAE5B,MAAMG;QACV;IACJ;AACJ"}
|
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
import { DateTimeResolver } from "graphql-scalars";
|
|
2
2
|
import { GraphQLScalarType } from "graphql";
|
|
3
|
-
import
|
|
4
|
-
const validateTimeZone = value
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
value
|
|
3
|
+
import error from "@webiny/error";
|
|
4
|
+
const validateTimeZone = (value)=>{
|
|
5
|
+
const timeWithTimezone = value.split("T")[1];
|
|
6
|
+
if (!timeWithTimezone) throw new error("Could not extract time with timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
7
|
+
value
|
|
9
8
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
throw new WebinyError("Could not extract timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
15
|
-
value: timeWithTimezone
|
|
9
|
+
const separator = timeWithTimezone.includes("-") ? "-" : "+";
|
|
10
|
+
const zone = timeWithTimezone.split(separator)[1];
|
|
11
|
+
if (!zone) throw new error("Could not extract timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
12
|
+
value: timeWithTimezone
|
|
16
13
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new WebinyError("Could not extract hours or minutes from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
22
|
-
value: zone
|
|
14
|
+
const hoursMinutes = zone.split(":");
|
|
15
|
+
const [hours, minutes] = hoursMinutes;
|
|
16
|
+
if (void 0 === hours || void 0 === minutes || 2 !== hoursMinutes.length) throw new error("Could not extract hours or minutes from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
17
|
+
value: zone
|
|
23
18
|
});
|
|
24
|
-
}
|
|
25
19
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
DateTimeResolver.parseValue(value);
|
|
36
|
-
validateTimeZone(value);
|
|
37
|
-
return value;
|
|
38
|
-
},
|
|
39
|
-
serialize: value => {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
20
|
+
const DateTimeZScalar = new GraphQLScalarType({
|
|
21
|
+
name: "DateTimeZ",
|
|
22
|
+
description: "A custom type for dateTime with the timezone.",
|
|
23
|
+
parseValue: (value)=>{
|
|
24
|
+
DateTimeResolver.parseValue(value);
|
|
25
|
+
validateTimeZone(value);
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
serialize: (value)=>value
|
|
42
29
|
});
|
|
30
|
+
export { DateTimeZScalar };
|
|
43
31
|
|
|
44
32
|
//# sourceMappingURL=DateTimeZScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/DateTimeZScalar.js","sources":["../../src/builtInTypes/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"],"names":["validateTimeZone","value","timeWithTimezone","WebinyError","separator","zone","hoursMinutes","hours","minutes","undefined","DateTimeZScalar","GraphQLScalarType","DateTimeResolver"],"mappings":";;;AAIA,MAAMA,mBAAmB,CAACC;IACtB,MAAMC,mBAAmBD,MAAM,KAAK,CAAC,IAAI,CAAC,EAAE;IAC5C,IAAI,CAACC,kBACD,MAAM,IAAIC,MACN,oDACA,4BACA;QACIF;IACJ;IAGR,MAAMG,YAAYF,iBAAiB,QAAQ,CAAC,OAAO,MAAM;IACzD,MAAMG,OAAOH,iBAAiB,KAAK,CAACE,UAAU,CAAC,EAAE;IACjD,IAAI,CAACC,MACD,MAAM,IAAIF,MACN,0CACA,4BACA;QACI,OAAOD;IACX;IAGR,MAAMI,eAAeD,KAAK,KAAK,CAAC;IAChC,MAAM,CAACE,OAAOC,QAAQ,GAAGF;IACzB,IAAIC,AAAUE,WAAVF,SAAuBC,AAAYC,WAAZD,WAAyBF,AAAwB,MAAxBA,aAAa,MAAM,EACnE,MAAM,IAAIH,MACN,kDACA,4BACA;QACI,OAAOE;IACX;AAGZ;AAKO,MAAMK,kBAAkB,IAAIC,kBAAkB;IACjD,MAAM;IACN,aAAa;IACb,YAAYV,CAAAA;QAERW,iBAAiB,UAAU,CAACX;QAC5BD,iBAAiBC;QACjB,OAAOA;IACX;IACA,WAAWA,CAAAA,QACAA;AAEf"}
|
|
@@ -1,93 +1,65 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLError, GraphQLScalarType } from "graphql";
|
|
2
2
|
import { Kind } from "graphql/language/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
value
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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");
|
|
3
|
+
const IconScalar = new GraphQLScalarType({
|
|
4
|
+
name: "Icon",
|
|
5
|
+
description: "Icon scalar that accepts string or object {type, name, value}",
|
|
6
|
+
serialize (value) {
|
|
7
|
+
if ("string" == typeof value) return {
|
|
8
|
+
type: "icon",
|
|
9
|
+
name: value,
|
|
10
|
+
value: void 0
|
|
11
|
+
};
|
|
12
|
+
if (value && "object" == typeof value) {
|
|
13
|
+
if ("string" != typeof value.type || "string" != typeof value.name) throw new GraphQLError("Icon object must have string type and name");
|
|
14
|
+
return {
|
|
15
|
+
type: value.type,
|
|
16
|
+
name: value.name,
|
|
17
|
+
value: value.value
|
|
18
|
+
};
|
|
74
19
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
20
|
+
throw new GraphQLError("Icon must be a string or object");
|
|
21
|
+
},
|
|
22
|
+
parseValue (value) {
|
|
23
|
+
if ("string" == typeof value) return {
|
|
24
|
+
type: "icon",
|
|
25
|
+
name: value
|
|
26
|
+
};
|
|
27
|
+
if (value && "object" == typeof value) {
|
|
28
|
+
if ("string" != typeof value.type || "string" != typeof value.name) throw new GraphQLError("Icon object must have string type and name");
|
|
29
|
+
if (void 0 !== value.value && "string" != typeof value.value) throw new GraphQLError("Icon value must be a string if provided");
|
|
30
|
+
return {
|
|
31
|
+
type: value.type,
|
|
32
|
+
name: value.name,
|
|
33
|
+
...void 0 !== value.value && {
|
|
34
|
+
value: value.value
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
throw new GraphQLError("Icon must be a string or object");
|
|
39
|
+
},
|
|
40
|
+
parseLiteral (ast) {
|
|
41
|
+
if (ast.kind === Kind.STRING) return {
|
|
42
|
+
type: "icon",
|
|
43
|
+
name: ast.value
|
|
44
|
+
};
|
|
45
|
+
if (ast.kind === Kind.OBJECT) {
|
|
46
|
+
const fields = {};
|
|
47
|
+
ast.fields.forEach((field)=>{
|
|
48
|
+
if (field.value.kind === Kind.STRING) fields[field.name.value] = field.value.value;
|
|
49
|
+
else throw new GraphQLError("Icon object fields must be strings");
|
|
50
|
+
});
|
|
51
|
+
if (!fields.type || !fields.name) throw new GraphQLError("Icon object must have type and name");
|
|
52
|
+
return {
|
|
53
|
+
type: fields.type,
|
|
54
|
+
name: fields.name,
|
|
55
|
+
...fields.value && {
|
|
56
|
+
value: fields.value
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
throw new GraphQLError("Icon must be a string or object literal");
|
|
88
61
|
}
|
|
89
|
-
throw new GraphQLError("Icon must be a string or object literal");
|
|
90
|
-
}
|
|
91
62
|
});
|
|
63
|
+
export { IconScalar };
|
|
92
64
|
|
|
93
65
|
//# sourceMappingURL=IconScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/IconScalar.js","sources":["../../src/builtInTypes/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.value })\n };\n }\n\n throw new GraphQLError(\"Icon must be a string or object literal\");\n }\n});\n"],"names":["IconScalar","GraphQLScalarType","value","undefined","GraphQLError","ast","Kind","fields","field"],"mappings":";;AAGO,MAAMA,aAAa,IAAIC,kBAAkB;IAC5C,MAAM;IACN,aAAa;IAGb,WAAUC,KAAU;QAChB,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAO;YAAE,MAAM;YAAQ,MAAMA;YAAO,OAAOC;QAAU;QAGzD,IAAID,SAAS,AAAiB,YAAjB,OAAOA,OAAoB;YAEpC,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,IAAiB,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACnD,MAAM,IAAIE,aAAa;YAG3B,OAAO;gBACH,MAAMF,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;gBAChB,OAAOA,MAAM,KAAK;YACtB;QACJ;QAEA,MAAM,IAAIE,aAAa;IAC3B;IAGA,YAAWF,KAAU;QAEjB,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAO;YAAE,MAAM;YAAQ,MAAMA;QAAM;QAIvC,IAAIA,SAAS,AAAiB,YAAjB,OAAOA,OAAoB;YACpC,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,IAAiB,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACnD,MAAM,IAAIE,aAAa;YAG3B,IAAIF,AAAgBC,WAAhBD,MAAM,KAAK,IAAkB,AAAuB,YAAvB,OAAOA,MAAM,KAAK,EAC/C,MAAM,IAAIE,aAAa;YAG3B,OAAO;gBACH,MAAMF,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;gBAChB,GAAIA,AAAgBC,WAAhBD,MAAM,KAAK,IAAkB;oBAAE,OAAOA,MAAM,KAAK;gBAAC,CAAC;YAC3D;QACJ;QAEA,MAAM,IAAIE,aAAa;IAC3B;IAGA,cAAaC,GAAG;QAEZ,IAAIA,IAAI,IAAI,KAAKC,KAAK,MAAM,EACxB,OAAO;YAAE,MAAM;YAAQ,MAAMD,IAAI,KAAK;QAAC;QAI3C,IAAIA,IAAI,IAAI,KAAKC,KAAK,MAAM,EAAE;YAC1B,MAAMC,SAAiC,CAAC;YAExCF,IAAI,MAAM,CAAC,OAAO,CAACG,CAAAA;gBACf,IAAIA,MAAM,KAAK,CAAC,IAAI,KAAKF,KAAK,MAAM,EAChCC,MAAM,CAACC,MAAM,IAAI,CAAC,KAAK,CAAC,GAAGA,MAAM,KAAK,CAAC,KAAK;qBAE5C,MAAM,IAAIJ,aAAa;YAE/B;YAGA,IAAI,CAACG,OAAO,IAAI,IAAI,CAACA,OAAO,IAAI,EAC5B,MAAM,IAAIH,aAAa;YAG3B,OAAO;gBACH,MAAMG,OAAO,IAAI;gBACjB,MAAMA,OAAO,IAAI;gBACjB,GAAIA,OAAO,KAAK,IAAI;oBAAE,OAAOA,OAAO,KAAK;gBAAC,CAAC;YAC/C;QACJ;QAEA,MAAM,IAAIH,aAAa;IAC3B;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/JsonScalar.js","sources":["../../src/builtInTypes/JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"names":["JsonScalar","JSONResolver"],"mappings":";AACO,MAAMA,aAAaC"}
|
|
@@ -1,49 +1,40 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
2
|
import { Kind } from "graphql/language/index.js";
|
|
3
|
-
import
|
|
4
|
-
const parseValue = value
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
value
|
|
3
|
+
import error from "@webiny/error";
|
|
4
|
+
const parseValue = (value)=>{
|
|
5
|
+
if (String(value).includes(".")) throw new error("Value sent must be an integer.", "INVALID_VALUE", {
|
|
6
|
+
value
|
|
8
7
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (value === null || value === undefined) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if (isNaN(value) === true) {
|
|
17
|
-
throw new WebinyError("Value sent must be an integer.", "INVALID_VALUE", {
|
|
18
|
-
value
|
|
8
|
+
if ("number" == typeof value) return value;
|
|
9
|
+
if (null == value) return null;
|
|
10
|
+
if (true === isNaN(value)) throw new error("Value sent must be an integer.", "INVALID_VALUE", {
|
|
11
|
+
value
|
|
19
12
|
});
|
|
20
|
-
|
|
21
|
-
return parseInt(value);
|
|
13
|
+
return parseInt(value);
|
|
22
14
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
const LongScalar = new GraphQLScalarType({
|
|
16
|
+
name: "Long",
|
|
17
|
+
description: "A custom input type to be used for large integers (Long).",
|
|
18
|
+
serialize: (value)=>{
|
|
19
|
+
try {
|
|
20
|
+
return parseValue(value);
|
|
21
|
+
} catch {
|
|
22
|
+
console.log({
|
|
23
|
+
message: "Value sent must be an integer.",
|
|
24
|
+
code: "INVALID_VALUE",
|
|
25
|
+
data: {
|
|
26
|
+
value
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return null;
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
},
|
|
32
|
+
parseValue: parseValue,
|
|
33
|
+
parseLiteral: (ast)=>{
|
|
34
|
+
if (ast.kind === Kind.INT) return parseInt(ast.value);
|
|
35
|
+
throw new Error(`Expected type Long, found {${ast.kind}}`);
|
|
38
36
|
}
|
|
39
|
-
},
|
|
40
|
-
parseValue,
|
|
41
|
-
parseLiteral: ast => {
|
|
42
|
-
if (ast.kind === Kind.INT) {
|
|
43
|
-
return parseInt(ast.value);
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`Expected type Long, found {${ast.kind}}`);
|
|
46
|
-
}
|
|
47
37
|
});
|
|
38
|
+
export { LongScalar };
|
|
48
39
|
|
|
49
40
|
//# sourceMappingURL=LongScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/LongScalar.js","sources":["../../src/builtInTypes/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"],"names":["parseValue","value","String","WebinyError","isNaN","parseInt","LongScalar","GraphQLScalarType","console","ast","Kind","Error"],"mappings":";;;AAIA,MAAMA,aAAa,CAACC;IAChB,IAAIC,OAAOD,OAAO,QAAQ,CAAC,MACvB,MAAM,IAAIE,MAAY,kCAAkC,iBAAiB;QACrEF;IACJ;IAEJ,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAOA;IAGX,IAAIA,QAAAA,OACA,OAAO;IAGX,IAAIG,AAAiB,SAAjBA,MAAMH,QACN,MAAM,IAAIE,MAAY,kCAAkC,iBAAiB;QACrEF;IACJ;IAGJ,OAAOI,SAASJ;AACpB;AAEO,MAAMK,aAAa,IAAIC,kBAAkB;IAC5C,MAAM;IACN,aAAa;IACb,WAAW,CAACN;QACR,IAAI;YACA,OAAOD,WAAWC;QACtB,EAAE,OAAM;YACJO,QAAQ,GAAG,CAAC;gBACR,SAAS;gBACT,MAAM;gBACN,MAAM;oBACFP;gBACJ;YACJ;YACA,OAAO;QACX;IACJ;IACAD,YAAAA;IACA,cAAcS,CAAAA;QACV,IAAIA,IAAI,IAAI,KAAKC,KAAK,GAAG,EACrB,OAAOL,SAASI,IAAI,KAAK;QAG7B,MAAM,IAAIE,MAAM,CAAC,2BAA2B,EAAEF,IAAI,IAAI,CAAC,CAAC,CAAC;IAC7D;AACJ"}
|