@webiny/handler-graphql 6.4.12-beta.5 → 6.5.0-beta.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/builtInTypes/DateScalar.js +5 -0
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/IconScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +4 -4
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +2 -2
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/createGraphQLHandler.d.ts +1 -1
- package/debugPlugins.d.ts +1 -1
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +4 -3
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -1
- package/index.d.ts +1 -1
- package/package.json +19 -19
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { DateResolver } from "graphql-scalars";
|
|
2
2
|
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
3
4
|
const DateScalar = new GraphQLScalarType({
|
|
4
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
|
+
},
|
|
5
10
|
serialize: (value)=>{
|
|
6
11
|
if (!value) return null;
|
|
7
12
|
try {
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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"}
|
|
@@ -5,9 +5,9 @@ const parseValue = (value)=>{
|
|
|
5
5
|
if (null !== String(value).match(/^0x/)) throw new error("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
6
6
|
value
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
value
|
|
12
12
|
});
|
|
13
13
|
return parseFloat(value);
|
|
@@ -32,7 +32,7 @@ const NumberScalar = new GraphQLScalarType({
|
|
|
32
32
|
parseValue: parseValue,
|
|
33
33
|
parseLiteral: (ast)=>{
|
|
34
34
|
if (ast.kind === Kind.INT) return Number(ast.value);
|
|
35
|
-
|
|
35
|
+
if (ast.kind === Kind.FLOAT) return parseFloat(ast.value);
|
|
36
36
|
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -13,10 +13,10 @@ const parseTime = (value)=>{
|
|
|
13
13
|
if (hours >= 24) throw new error("There cannot be more than 24 hours.", "TIME_VALIDATION_ERROR", {
|
|
14
14
|
value
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
if (minutes >= 60) throw new error("There cannot be more than 59 minutes.", "TIME_VALIDATION_ERROR", {
|
|
17
17
|
value
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
if (seconds >= 60) throw new error("There cannot be more than 59 seconds.", "TIME_VALIDATION_ERROR", {
|
|
20
20
|
value
|
|
21
21
|
});
|
|
22
22
|
return {
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
2
|
import type { HandlerGraphQLOptions } from "./types.js";
|
|
3
|
-
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
4
3
|
export default _default;
|
|
4
|
+
declare function _default(options?: HandlerGraphQLOptions): Plugin[];
|
package/debugPlugins.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ interface DebugContext extends Context {
|
|
|
10
10
|
logs?: Log[];
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
|
|
14
13
|
export default _default;
|
|
14
|
+
declare function _default(): (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
|
|
@@ -8,10 +8,11 @@ class GraphQLSchemaBuilder {
|
|
|
8
8
|
const pathParts = path.split(".");
|
|
9
9
|
const graphqlResolver = (parent, args, context, info)=>{
|
|
10
10
|
const resolvedDeps = dependencies.map((dep)=>{
|
|
11
|
-
const [abstraction] = Array.isArray(dep) ? dep : [
|
|
12
|
-
dep
|
|
11
|
+
const [abstraction, options] = Array.isArray(dep) ? dep : [
|
|
12
|
+
dep,
|
|
13
|
+
void 0
|
|
13
14
|
];
|
|
14
|
-
return context.container.resolve(abstraction);
|
|
15
|
+
return options?.multiple ? context.container.resolveAll(abstraction) : context.container.resolve(abstraction);
|
|
15
16
|
});
|
|
16
17
|
const actualResolver = resolver(...resolvedDeps);
|
|
17
18
|
return actualResolver({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js","sources":["../../../src/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.ts"],"sourcesContent":["import type { GraphQLSchemaBuilder as Abstraction } from \"./abstractions.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\nimport type { ResolverDecorator, ResolverDecorators, Resolvers } from \"~/types.js\";\nimport type { Dependency } from \"@webiny/di\";\n\nexport class GraphQLSchemaBuilder implements Abstraction.Interface {\n private readonly typeDefsArray: string[] = [];\n private readonly resolvers: Resolvers<any> = {};\n private readonly resolverDecorators: ResolverDecorators = {};\n\n addTypeDefs(typeDefs: string): this {\n this.typeDefsArray.push(typeDefs);\n return this;\n }\n\n addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this {\n const { path, dependencies = [], resolver } = config;\n\n const pathParts = path.split(\".\");\n\n const graphqlResolver = (parent: any, args: TArgs, context: any, info: any) => {\n const resolvedDeps = dependencies.map((dep: Dependency) => {\n const [abstraction] = Array.isArray(dep) ? dep : [dep];\n return context.container.resolve(abstraction);\n });\n\n const actualResolver = resolver(...resolvedDeps);\n\n return actualResolver({ parent, args, context, info });\n };\n\n this.setResolverAtPath(pathParts, graphqlResolver);\n\n return this;\n }\n\n /**\n * @internal This method needs revisiting, to align with DI concepts.\n */\n addResolverDecorator(path: string, decorator: ResolverDecorator): this {\n if (!this.resolverDecorators[path]) {\n this.resolverDecorators[path] = [];\n }\n this.resolverDecorators[path].push(decorator);\n return this;\n }\n\n build(): IGraphQLSchema {\n return {\n typeDefs: this.typeDefsArray.join(\"\\n\"),\n resolvers: this.resolvers,\n resolverDecorators: this.resolverDecorators\n };\n }\n\n private setResolverAtPath(pathParts: string[], resolver: any): void {\n let current: any = this.resolvers;\n\n for (let i = 0; i < pathParts.length - 1; i++) {\n const part = pathParts[i];\n if (!current[part]) {\n current[part] = {};\n }\n current = current[part];\n }\n\n const finalKey = pathParts[pathParts.length - 1];\n current[finalKey] = resolver;\n }\n}\n"],"names":["GraphQLSchemaBuilder","typeDefs","config","path","dependencies","resolver","pathParts","graphqlResolver","parent","args","context","info","resolvedDeps","dep","abstraction","Array","actualResolver","decorator","current","i","part","finalKey"],"mappings":"AAKO,MAAMA;IAKT,YAAYC,QAAgB,EAAQ;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,CAACA;QACxB,OAAO,IAAI;IACf;IAEA,YAAyBC,MAAiC,EAAQ;QAC9D,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAE,EAAEC,QAAQ,EAAE,GAAGH;QAE9C,MAAMI,YAAYH,KAAK,KAAK,CAAC;QAE7B,MAAMI,kBAAkB,CAACC,QAAaC,MAAaC,SAAcC;YAC7D,MAAMC,eAAeR,aAAa,GAAG,CAAC,CAACS;
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js","sources":["../../../src/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.ts"],"sourcesContent":["import type { GraphQLSchemaBuilder as Abstraction } from \"./abstractions.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\nimport type { ResolverDecorator, ResolverDecorators, Resolvers } from \"~/types.js\";\nimport type { Dependency } from \"@webiny/di\";\n\nexport class GraphQLSchemaBuilder implements Abstraction.Interface {\n private readonly typeDefsArray: string[] = [];\n private readonly resolvers: Resolvers<any> = {};\n private readonly resolverDecorators: ResolverDecorators = {};\n\n addTypeDefs(typeDefs: string): this {\n this.typeDefsArray.push(typeDefs);\n return this;\n }\n\n addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this {\n const { path, dependencies = [], resolver } = config;\n\n const pathParts = path.split(\".\");\n\n const graphqlResolver = (parent: any, args: TArgs, context: any, info: any) => {\n const resolvedDeps = dependencies.map((dep: Dependency) => {\n /*\n * `Dependency` allows `[abstraction, { multiple: true }]`, same as anywhere else in\n * the container. This used to destructure the tuple, throw the options away and\n * always single-resolve, so a resolver asking for every implementation of an\n * abstraction received one object and failed on `.map`.\n */\n const [abstraction, options] = Array.isArray(dep) ? dep : [dep, undefined];\n\n return options?.multiple\n ? context.container.resolveAll(abstraction)\n : context.container.resolve(abstraction);\n });\n\n const actualResolver = resolver(...resolvedDeps);\n\n return actualResolver({ parent, args, context, info });\n };\n\n this.setResolverAtPath(pathParts, graphqlResolver);\n\n return this;\n }\n\n /**\n * @internal This method needs revisiting, to align with DI concepts.\n */\n addResolverDecorator(path: string, decorator: ResolverDecorator): this {\n if (!this.resolverDecorators[path]) {\n this.resolverDecorators[path] = [];\n }\n this.resolverDecorators[path].push(decorator);\n return this;\n }\n\n build(): IGraphQLSchema {\n return {\n typeDefs: this.typeDefsArray.join(\"\\n\"),\n resolvers: this.resolvers,\n resolverDecorators: this.resolverDecorators\n };\n }\n\n private setResolverAtPath(pathParts: string[], resolver: any): void {\n let current: any = this.resolvers;\n\n for (let i = 0; i < pathParts.length - 1; i++) {\n const part = pathParts[i];\n if (!current[part]) {\n current[part] = {};\n }\n current = current[part];\n }\n\n const finalKey = pathParts[pathParts.length - 1];\n current[finalKey] = resolver;\n }\n}\n"],"names":["GraphQLSchemaBuilder","typeDefs","config","path","dependencies","resolver","pathParts","graphqlResolver","parent","args","context","info","resolvedDeps","dep","abstraction","options","Array","undefined","actualResolver","decorator","current","i","part","finalKey"],"mappings":"AAKO,MAAMA;IAKT,YAAYC,QAAgB,EAAQ;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,CAACA;QACxB,OAAO,IAAI;IACf;IAEA,YAAyBC,MAAiC,EAAQ;QAC9D,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAE,EAAEC,QAAQ,EAAE,GAAGH;QAE9C,MAAMI,YAAYH,KAAK,KAAK,CAAC;QAE7B,MAAMI,kBAAkB,CAACC,QAAaC,MAAaC,SAAcC;YAC7D,MAAMC,eAAeR,aAAa,GAAG,CAAC,CAACS;gBAOnC,MAAM,CAACC,aAAaC,QAAQ,GAAGC,MAAM,OAAO,CAACH,OAAOA,MAAM;oBAACA;oBAAKI;iBAAU;gBAE1E,OAAOF,SAAS,WACVL,QAAQ,SAAS,CAAC,UAAU,CAACI,eAC7BJ,QAAQ,SAAS,CAAC,OAAO,CAACI;YACpC;YAEA,MAAMI,iBAAiBb,YAAYO;YAEnC,OAAOM,eAAe;gBAAEV;gBAAQC;gBAAMC;gBAASC;YAAK;QACxD;QAEA,IAAI,CAAC,iBAAiB,CAACL,WAAWC;QAElC,OAAO,IAAI;IACf;IAKA,qBAAqBJ,IAAY,EAAEgB,SAA4B,EAAQ;QACnE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAChB,KAAK,EAC9B,IAAI,CAAC,kBAAkB,CAACA,KAAK,GAAG,EAAE;QAEtC,IAAI,CAAC,kBAAkB,CAACA,KAAK,CAAC,IAAI,CAACgB;QACnC,OAAO,IAAI;IACf;IAEA,QAAwB;QACpB,OAAO;YACH,UAAU,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAClC,WAAW,IAAI,CAAC,SAAS;YACzB,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;IACJ;IAEQ,kBAAkBb,SAAmB,EAAED,QAAa,EAAQ;QAChE,IAAIe,UAAe,IAAI,CAAC,SAAS;QAEjC,IAAK,IAAIC,IAAI,GAAGA,IAAIf,UAAU,MAAM,GAAG,GAAGe,IAAK;YAC3C,MAAMC,OAAOhB,SAAS,CAACe,EAAE;YACzB,IAAI,CAACD,OAAO,CAACE,KAAK,EACdF,OAAO,CAACE,KAAK,GAAG,CAAC;YAErBF,UAAUA,OAAO,CAACE,KAAK;QAC3B;QAEA,MAAMC,WAAWjB,SAAS,CAACA,UAAU,MAAM,GAAG,EAAE;QAChDc,OAAO,CAACG,SAAS,GAAGlB;IACxB;;aAvEiB,aAAa,GAAa,EAAE;aAC5B,SAAS,GAAmB,CAAC;aAC7B,kBAAkB,GAAuB,CAAC;;AAsE/D"}
|
package/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export * from "./plugins/index.js";
|
|
|
7
7
|
export * from "./processRequestBody.js";
|
|
8
8
|
export * from "./createResolverDecorator.js";
|
|
9
9
|
export * from "./ResolverDecoration.js";
|
|
10
|
-
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
11
10
|
export default _default;
|
|
11
|
+
declare function _default(options?: HandlerGraphQLOptions): Plugin[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,29 +18,29 @@
|
|
|
18
18
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@graphql-tools/merge": "9.2.
|
|
22
|
-
"@graphql-tools/resolvers-composition": "7.0.
|
|
23
|
-
"@graphql-tools/schema": "10.
|
|
24
|
-
"@graphql-tools/utils": "
|
|
25
|
-
"@webiny/api": "6.
|
|
26
|
-
"@webiny/di": "1.
|
|
27
|
-
"@webiny/error": "6.
|
|
28
|
-
"@webiny/feature": "6.
|
|
29
|
-
"@webiny/handler": "6.
|
|
30
|
-
"@webiny/plugins": "6.
|
|
31
|
-
"@webiny/stdlib": "0.0.
|
|
32
|
-
"@webiny/utils": "6.
|
|
21
|
+
"@graphql-tools/merge": "9.2.2",
|
|
22
|
+
"@graphql-tools/resolvers-composition": "7.0.35",
|
|
23
|
+
"@graphql-tools/schema": "10.0.38",
|
|
24
|
+
"@graphql-tools/utils": "11.2.2",
|
|
25
|
+
"@webiny/api": "6.5.0-beta.0",
|
|
26
|
+
"@webiny/di": "1.0.2",
|
|
27
|
+
"@webiny/error": "6.5.0-beta.0",
|
|
28
|
+
"@webiny/feature": "6.5.0-beta.0",
|
|
29
|
+
"@webiny/handler": "6.5.0-beta.0",
|
|
30
|
+
"@webiny/plugins": "6.5.0-beta.0",
|
|
31
|
+
"@webiny/stdlib": "0.0.12",
|
|
32
|
+
"@webiny/utils": "6.5.0-beta.0",
|
|
33
33
|
"graphql": "16.14.2",
|
|
34
|
-
"graphql-scalars": "1.
|
|
34
|
+
"graphql-scalars": "1.25.0",
|
|
35
35
|
"graphql-tag": "2.12.7",
|
|
36
|
-
"zod": "4.
|
|
36
|
+
"zod": "4.4.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@webiny/build-tools": "6.
|
|
40
|
-
"@webiny/handler-aws": "6.
|
|
39
|
+
"@webiny/build-tools": "6.5.0-beta.0",
|
|
40
|
+
"@webiny/handler-aws": "6.5.0-beta.0",
|
|
41
41
|
"rimraf": "6.1.3",
|
|
42
|
-
"typescript": "
|
|
43
|
-
"vitest": "
|
|
42
|
+
"typescript": "7.0.2",
|
|
43
|
+
"vitest": "4.1.10"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|