@webiny/api-graphql 0.0.0-unstable.0d717d18dd
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/LICENSE +21 -0
- package/README.md +11 -0
- package/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +23 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +2 -0
- package/builtInTypes/AnyScalar.js +11 -0
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.d.ts +2 -0
- package/builtInTypes/DateScalar.js +23 -0
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.d.ts +2 -0
- package/builtInTypes/DateTimeScalar.js +18 -0
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.d.ts +6 -0
- package/builtInTypes/DateTimeZScalar.js +32 -0
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +65 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -0
- package/builtInTypes/JsonScalar.js +5 -0
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +2 -0
- package/builtInTypes/LongScalar.js +40 -0
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +2 -0
- package/builtInTypes/NumberScalar.js +41 -0
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +2 -0
- package/builtInTypes/RefInputScalar.js +53 -0
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.d.ts +2 -0
- package/builtInTypes/TimeScalar.js +40 -0
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.d.ts +10 -0
- package/builtInTypes/index.js +10 -0
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +28 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +4 -0
- package/createResolverDecorator.js.map +1 -0
- package/engine/GraphQLContextEnhancer.d.ts +12 -0
- package/engine/GraphQLContextEnhancer.js +5 -0
- package/engine/GraphQLContextEnhancer.js.map +1 -0
- package/engine/GraphQLContextualSchema.d.ts +14 -0
- package/engine/GraphQLContextualSchema.js +5 -0
- package/engine/GraphQLContextualSchema.js.map +1 -0
- package/engine/GraphQLEngine.d.ts +21 -0
- package/engine/GraphQLEngine.js +95 -0
- package/engine/GraphQLEngine.js.map +1 -0
- package/engine/GraphQLEngineFeature.d.ts +4 -0
- package/engine/GraphQLEngineFeature.js +15 -0
- package/engine/GraphQLEngineFeature.js.map +1 -0
- package/engine/GraphQLRoute.d.ts +14 -0
- package/engine/GraphQLRoute.js +28 -0
- package/engine/GraphQLRoute.js.map +1 -0
- package/engine/abstractions.d.ts +7 -0
- package/engine/abstractions.js +5 -0
- package/engine/abstractions.js.map +1 -0
- package/engine/index.d.ts +5 -0
- package/engine/index.js +5 -0
- package/errors.d.ts +4 -0
- package/errors.js +9 -0
- package/errors.js.map +1 -0
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +2 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +17 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +71 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +12 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +26 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +39 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +6 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +4 -0
- package/features/GraphQLSchemaBuilder/feature.js +11 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +15 -0
- package/graphql/abstractions.core.js +5 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +2 -0
- package/graphql/abstractions.public.d.ts +18 -0
- package/graphql/abstractions.public.js +5 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +12 -0
- package/index.js +14 -0
- package/index.js.map +1 -0
- package/package.json +50 -0
- package/plugins/GraphQLSchemaPlugin.d.ts +21 -0
- package/plugins/GraphQLSchemaPlugin.js +25 -0
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +1 -0
- package/processRequestBody.d.ts +4 -0
- package/processRequestBody.js +26 -0
- package/processRequestBody.js.map +1 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.d.ts +12 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.js +21 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.js.map +1 -0
- package/responses.d.ts +51 -0
- package/responses.js +59 -0
- package/responses.js.map +1 -0
- package/types.d.ts +50 -0
- package/types.js +0 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +20 -0
- package/utils/resolve.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-graphql
|
|
2
|
+
|
|
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,23 @@
|
|
|
1
|
+
import { composeResolvers } from "@graphql-tools/resolvers-composition";
|
|
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 = {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export { ResolverDecoration };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=ResolverDecoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
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
|
|
8
|
+
});
|
|
9
|
+
export { AnyScalar };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=AnyScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DateResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
4
|
+
const DateScalar = new GraphQLScalarType({
|
|
5
|
+
...DateResolver,
|
|
6
|
+
parseValue: (value)=>{
|
|
7
|
+
if ("string" != typeof value || !DATE_RE.test(value)) throw new TypeError(`Date cannot represent an invalid date-string ${String(value)}. Expected format: YYYY-MM-DD.`);
|
|
8
|
+
return DateResolver.parseValue(value);
|
|
9
|
+
},
|
|
10
|
+
serialize: (value)=>{
|
|
11
|
+
if (!value) return null;
|
|
12
|
+
try {
|
|
13
|
+
const date = new Date(value);
|
|
14
|
+
return date.toISOString().slice(0, 10);
|
|
15
|
+
} catch (ex) {
|
|
16
|
+
if (value.toISOString) return value.toISOString().slice(0, 10);
|
|
17
|
+
throw ex;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export { DateScalar };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=DateScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtInTypes/DateScalar.js","sources":["../../src/builtInTypes/DateScalar.ts"],"sourcesContent":["import { DateResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\n\nconst DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const DateScalar = new GraphQLScalarType<Date | string, string>({\n ...DateResolver,\n parseValue: (value: unknown) => {\n if (typeof value !== \"string\" || !DATE_RE.test(value)) {\n throw new TypeError(\n `Date cannot represent an invalid date-string ${String(value)}. Expected format: YYYY-MM-DD.`\n );\n }\n return DateResolver.parseValue(value);\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":["DATE_RE","DateScalar","GraphQLScalarType","DateResolver","value","TypeError","String","date","Date","ex"],"mappings":";;AAGA,MAAMA,UAAU;AAET,MAAMC,aAAa,IAAIC,kBAAyC;IACnE,GAAGC,YAAY;IACf,YAAY,CAACC;QACT,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,CAACJ,QAAQ,IAAI,CAACI,QAC3C,MAAM,IAAIC,UACN,CAAC,6CAA6C,EAAEC,OAAOF,OAAO,8BAA8B,CAAC;QAGrG,OAAOD,aAAa,UAAU,CAACC;IACnC;IACA,WAAW,CAACA;QACR,IAAI,CAACA,OACD,OAAO;QAEX,IAAI;YACA,MAAMG,OAAO,IAAIC,KAAKJ;YACtB,OAAOG,KAAK,WAAW,GAAG,KAAK,CAAC,GAAG;QACvC,EAAE,OAAOE,IAAI;YACT,IAAIL,MAAM,WAAW,EACjB,OAAOA,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG;YAExC,MAAMK;QACV;IACJ;AACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DateTimeResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
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
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export { DateTimeScalar };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=DateTimeScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DateTimeResolver } from "graphql-scalars";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
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
|
|
8
|
+
});
|
|
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
|
|
13
|
+
});
|
|
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
|
|
18
|
+
});
|
|
19
|
+
};
|
|
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
|
|
29
|
+
});
|
|
30
|
+
export { DateTimeZScalar };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=DateTimeZScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GraphQLError, GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
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
|
+
};
|
|
19
|
+
}
|
|
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");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
export { IconScalar };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=IconScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const JsonScalar: import("graphql").GraphQLScalarType<any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
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
|
|
7
|
+
});
|
|
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
|
|
12
|
+
});
|
|
13
|
+
return parseInt(value);
|
|
14
|
+
};
|
|
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;
|
|
30
|
+
}
|
|
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}}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export { LongScalar };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=LongScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
3
|
+
import error from "@webiny/error";
|
|
4
|
+
const parseValue = (value)=>{
|
|
5
|
+
if (null !== String(value).match(/^0x/)) throw new error("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
6
|
+
value
|
|
7
|
+
});
|
|
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 a number.", "INVALID_VALUE", {
|
|
11
|
+
value
|
|
12
|
+
});
|
|
13
|
+
return parseFloat(value);
|
|
14
|
+
};
|
|
15
|
+
const NumberScalar = new GraphQLScalarType({
|
|
16
|
+
name: "Number",
|
|
17
|
+
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
18
|
+
serialize: (value)=>{
|
|
19
|
+
try {
|
|
20
|
+
return parseValue(value);
|
|
21
|
+
} catch {
|
|
22
|
+
console.log({
|
|
23
|
+
message: "Value sent must be a number.",
|
|
24
|
+
code: "INVALID_VALUE",
|
|
25
|
+
data: {
|
|
26
|
+
value
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
parseValue: parseValue,
|
|
33
|
+
parseLiteral: (ast)=>{
|
|
34
|
+
if (ast.kind === Kind.INT) return Number(ast.value);
|
|
35
|
+
if (ast.kind === Kind.FLOAT) return parseFloat(ast.value);
|
|
36
|
+
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
export { NumberScalar };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=NumberScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtInTypes/NumberScalar.js","sources":["../../src/builtInTypes/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"],"names":["parseValue","value","String","WebinyError","isNaN","parseFloat","NumberScalar","GraphQLScalarType","console","ast","Kind","Number","Error"],"mappings":";;;AAIA,MAAMA,aAAa,CAACC;IAChB,IAAIC,AAA+B,SAA/BA,OAAOD,OAAO,KAAK,CAAC,QACpB,MAAM,IAAIE,MAAY,wCAAwC,iBAAiB;QAC3EF;IACJ;IACG,IAAI,AAAiB,YAAjB,OAAOA,OACd,OAAOA;IACJ,IAAIA,QAAAA,OACP,OAAO;IACJ,IAAIG,AAAiB,SAAjBA,MAAMH,QACb,MAAM,IAAIE,MAAY,gCAAgC,iBAAiB;QACnEF;IACJ;IAEJ,OAAOI,WAAWJ;AACtB;AAEO,MAAMK,eAAe,IAAIC,kBAAkB;IAC9C,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,OAAOC,OAAOF,IAAI,KAAK;QACpB,IAAIA,IAAI,IAAI,KAAKC,KAAK,KAAK,EAC9B,OAAOL,WAAWI,IAAI,KAAK;QAE/B,MAAM,IAAIG,MAAM,CAAC,6BAA6B,EAAEH,IAAI,IAAI,CAAC,CAAC,CAAC;IAC/D;AACJ"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
const tests = [
|
|
3
|
+
{
|
|
4
|
+
re: /^([0-9a-zA-Z_-]+)$/,
|
|
5
|
+
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
re: /^-/,
|
|
9
|
+
message: "Must not start with a dash (-)!"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
re: /-$/,
|
|
13
|
+
message: "Must not end with a dash (-)!"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
re: /^_/,
|
|
17
|
+
message: "Must not start with an underscore (_)!"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
re: /_$/,
|
|
21
|
+
message: "Must not end with an underscore (_)!"
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
const isValidId = (value)=>{
|
|
25
|
+
if ("string" != typeof value || value.length < 1) throw new Error("Must be a string with at least 1 character!");
|
|
26
|
+
for (const test of tests)if (null === test.re.test(value)) throw new Error(test.message);
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
const RefInputScalar = new GraphQLScalarType({
|
|
30
|
+
name: "RefInput",
|
|
31
|
+
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
32
|
+
serialize: (value)=>{
|
|
33
|
+
if (!value || null === value.id) return null;
|
|
34
|
+
return "string" == typeof value ? value : value.id;
|
|
35
|
+
},
|
|
36
|
+
parseValue: (value)=>{
|
|
37
|
+
if (!value || null === value.id) return null;
|
|
38
|
+
if ("string" == typeof value) return isValidId(value);
|
|
39
|
+
if ("id" in value) return isValidId(value.id);
|
|
40
|
+
throw new Error("Invalid RefInput value!");
|
|
41
|
+
},
|
|
42
|
+
parseLiteral: (ast)=>{
|
|
43
|
+
if ("StringValue" === ast.kind) return isValidId(ast.value);
|
|
44
|
+
if ("ObjectValue" === ast.kind) for(let i = 0; i < ast.fields.length; i++){
|
|
45
|
+
const { name, value } = ast.fields[i];
|
|
46
|
+
if ("id" === name.value) return isValidId(value.value);
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Invalid RefInput value!");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export { RefInputScalar };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=RefInputScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtInTypes/RefInputScalar.js","sources":["../../src/builtInTypes/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"],"names":["tests","isValidId","value","Error","test","RefInputScalar","GraphQLScalarType","ast","i","name"],"mappings":";AAEA,MAAMA,QAAQ;IACV;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;CACH;AAED,MAAMC,YAAY,CAACC;IACf,IAAI,AAAiB,YAAjB,OAAOA,SAAsBA,MAAM,MAAM,GAAG,GAC5C,MAAM,IAAIC,MAAM;IAEpB,KAAK,MAAMC,QAAQJ,MACf,IAAII,AAAwB,SAAxBA,KAAK,EAAE,CAAC,IAAI,CAACF,QACb,MAAM,IAAIC,MAAMC,KAAK,OAAO;IAGpC,OAAOF;AACX;AAEO,MAAMG,iBAAiB,IAAIC,kBAAkB;IAChD,MAAM;IACN,aACI;IAIJ,WAAW,CAACJ;QACR,IAAI,CAACA,SAASA,AAAa,SAAbA,MAAM,EAAE,EAClB,OAAO;QAGX,OAAO,AAAiB,YAAjB,OAAOA,QAAqBA,QAAQA,MAAM,EAAE;IACvD;IAIA,YAAY,CAACA;QACT,IAAI,CAACA,SAASA,AAAa,SAAbA,MAAM,EAAE,EAClB,OAAO;QAGX,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAOD,UAAUC;QAGrB,IAAI,QAAQA,OACR,OAAOD,UAAUC,MAAM,EAAE;QAG7B,MAAM,IAAIC,MAAM;IACpB;IACA,cAAcI,CAAAA;QACV,IAAIA,AAAa,kBAAbA,IAAI,IAAI,EACR,OAAON,UAAUM,IAAI,KAAK;QAG9B,IAAIA,AAAa,kBAAbA,IAAI,IAAI,EACR,IAAK,IAAIC,IAAI,GAAGA,IAAID,IAAI,MAAM,CAAC,MAAM,EAAEC,IAAK;YACxC,MAAM,EAAEC,IAAI,EAAEP,KAAK,EAAE,GAAGK,IAAI,MAAM,CAACC,EAAE;YACrC,IAAIC,AAAe,SAAfA,KAAK,KAAK,EAEV,OAAOR,UAAUC,MAAM,KAAK;QAEpC;QAGJ,MAAM,IAAIC,MAAM;IACpB;AACJ"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import error from "@webiny/error";
|
|
3
|
+
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
4
|
+
const parseTime = (value)=>{
|
|
5
|
+
if ("string" != typeof value || !value || null === value.match(re)) throw new error("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
6
|
+
value
|
|
7
|
+
});
|
|
8
|
+
const parsed = value.split(":").map(Number);
|
|
9
|
+
if (parsed.length < 2) throw new error("Could not parse the value.", "TIME_VALIDATION_ERROR", {
|
|
10
|
+
value
|
|
11
|
+
});
|
|
12
|
+
const [hours, minutes, seconds = 0] = parsed;
|
|
13
|
+
if (hours >= 24) throw new error("There cannot be more than 24 hours.", "TIME_VALIDATION_ERROR", {
|
|
14
|
+
value
|
|
15
|
+
});
|
|
16
|
+
if (minutes >= 60) throw new error("There cannot be more than 59 minutes.", "TIME_VALIDATION_ERROR", {
|
|
17
|
+
value
|
|
18
|
+
});
|
|
19
|
+
if (seconds >= 60) throw new error("There cannot be more than 59 seconds.", "TIME_VALIDATION_ERROR", {
|
|
20
|
+
value
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
hours,
|
|
24
|
+
minutes,
|
|
25
|
+
seconds
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const convertToTime = (value)=>{
|
|
29
|
+
const { hours, minutes, seconds } = parseTime(value);
|
|
30
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
31
|
+
};
|
|
32
|
+
const TimeScalar = new GraphQLScalarType({
|
|
33
|
+
name: "Time",
|
|
34
|
+
description: "A custom type to support time-only input.",
|
|
35
|
+
serialize: convertToTime,
|
|
36
|
+
parseValue: convertToTime
|
|
37
|
+
});
|
|
38
|
+
export { TimeScalar };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=TimeScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtInTypes/TimeScalar.js","sources":["../../src/builtInTypes/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?: unknown) => {\n if (typeof value !== \"string\" || !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: unknown): 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"],"names":["re","parseTime","value","WebinyError","parsed","Number","hours","minutes","seconds","convertToTime","String","TimeScalar","GraphQLScalarType"],"mappings":";;AAGA,MAAMA,KAAK;AAEX,MAAMC,YAAY,CAACC;IACf,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,CAACA,SAASA,AAAoB,SAApBA,MAAM,KAAK,CAACF,KACnD,MAAM,IAAIG,MAAY,kCAAkC,yBAAyB;QAAED;IAAM;IAE7F,MAAME,SAASF,MAAM,KAAK,CAAC,KAAK,GAAG,CAACG;IACpC,IAAID,OAAO,MAAM,GAAG,GAChB,MAAM,IAAID,MAAY,8BAA8B,yBAAyB;QAAED;IAAM;IAEzF,MAAM,CAACI,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGJ;IACtC,IAAIE,SAAS,IACT,MAAM,IAAIH,MAAY,uCAAuC,yBAAyB;QAClFD;IACJ;IACG,IAAIK,WAAW,IAClB,MAAM,IAAIJ,MAAY,yCAAyC,yBAAyB;QACpFD;IACJ;IACG,IAAIM,WAAW,IAClB,MAAM,IAAIL,MAAY,yCAAyC,yBAAyB;QACpFD;IACJ;IAEJ,OAAO;QACHI;QACAC;QACAC;IACJ;AACJ;AAEA,MAAMC,gBAAgB,CAACP;IACnB,MAAM,EAAEI,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGP,UAAUC;IAC9C,OAAO,GAAGQ,OAAOJ,OAAO,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAEI,OAAOH,SAAS,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAEG,OAC5EF,SACF,QAAQ,CAAC,GAAG,MAAM;AACxB;AAEO,MAAMG,aAAa,IAAIC,kBAAkB;IAC5C,MAAM;IACN,aAAa;IAEb,WAAWH;IAEX,YAAYA;AAChB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { WebinyError } from "@webiny/error";
|
|
3
|
+
import { createZodError } from "@webiny/utils/createZodError.js";
|
|
4
|
+
const requestBodySchema = zod.looseObject({
|
|
5
|
+
query: zod.string(),
|
|
6
|
+
variables: zod.record(zod.string(), zod.any()).nullish().optional(),
|
|
7
|
+
operationName: zod.string().nullish().optional().transform((value)=>value || void 0)
|
|
8
|
+
});
|
|
9
|
+
const schema = zod.union([
|
|
10
|
+
requestBodySchema,
|
|
11
|
+
zod.array(requestBodySchema)
|
|
12
|
+
]);
|
|
13
|
+
const createRequestBody = (input)=>{
|
|
14
|
+
const body = "string" == typeof input ? JSON.parse(input) : input;
|
|
15
|
+
const result = schema.safeParse(body);
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
const error = createZodError(result.error);
|
|
18
|
+
throw new WebinyError({
|
|
19
|
+
message: "Invalid GraphQL request! Check your query and variables.",
|
|
20
|
+
code: "GRAPHQL_REQUEST_INVALID",
|
|
21
|
+
data: error.data
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return result.data;
|
|
25
|
+
};
|
|
26
|
+
export { createRequestBody };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=createRequestBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRequestBody.js","sources":["../src/createRequestBody.ts"],"sourcesContent":["import zod from \"zod\";\nimport { WebinyError } from \"@webiny/error\";\nimport { createZodError } from \"@webiny/utils/createZodError.js\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\n\nconst requestBodySchema = zod.looseObject({\n query: zod.string(),\n variables: zod.record(zod.string(), zod.any()).nullish().optional(),\n operationName: zod\n .string()\n .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n })\n});\n\nconst schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);\n\nexport const createRequestBody = (input: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n const body = typeof input === \"string\" ? JSON.parse(input) : input;\n\n const result = schema.safeParse(body);\n if (!result.success) {\n const error = createZodError(result.error);\n throw new WebinyError({\n message: \"Invalid GraphQL request! Check your query and variables.\",\n code: \"GRAPHQL_REQUEST_INVALID\",\n data: error.data\n });\n }\n return result.data;\n};\n"],"names":["requestBodySchema","zod","value","undefined","schema","createRequestBody","input","body","JSON","result","error","createZodError","WebinyError"],"mappings":";;;AAKA,MAAMA,oBAAoBC,IAAI,WAAW,CAAC;IACtC,OAAOA,IAAI,MAAM;IACjB,WAAWA,IAAI,MAAM,CAACA,IAAI,MAAM,IAAIA,IAAI,GAAG,IAAI,OAAO,GAAG,QAAQ;IACjE,eAAeA,IAAAA,MACJ,GACN,OAAO,GACP,QAAQ,GACR,SAAS,CAACC,CAAAA,QACAA,SAASC;AAE5B;AAEA,MAAMC,SAASH,IAAI,KAAK,CAAC;IAACD;IAAmBC,IAAI,KAAK,CAACD;CAAmB;AAEnE,MAAMK,oBAAoB,CAACC;IAC9B,MAAMC,OAAO,AAAiB,YAAjB,OAAOD,QAAqBE,KAAK,KAAK,CAACF,SAASA;IAE7D,MAAMG,SAASL,OAAO,SAAS,CAACG;IAChC,IAAI,CAACE,OAAO,OAAO,EAAE;QACjB,MAAMC,QAAQC,eAAeF,OAAO,KAAK;QACzC,MAAM,IAAIG,YAAY;YAClB,SAAS;YACT,MAAM;YACN,MAAMF,MAAM,IAAI;QACpB;IACJ;IACA,OAAOD,OAAO,IAAI;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createResolverDecorator.js","sources":["../src/createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types.js\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"names":["createResolverDecorator","decorator"],"mappings":"AAEO,MAAMA,0BAA0B,CACnCC,YAEOA"}
|