@webiny/handler-graphql 6.3.0-beta.4 → 6.4.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/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 +13 -13
- 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
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { GraphQLSchemaComposer } from "./GraphQLSchemaComposer.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const GraphQLSchemaComposerFeature = createFeature({
|
|
4
|
+
name: "GraphQLSchemaComposer",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GraphQLSchemaComposer);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { GraphQLSchemaComposerFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/feature.js","sources":["../../../src/features/GraphQLSchemaBuilder/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GraphQLSchemaComposer } from \"./GraphQLSchemaComposer.js\";\n\nexport const GraphQLSchemaComposerFeature = createFeature({\n name: \"GraphQLSchemaComposer\",\n register(container) {\n container.register(GraphQLSchemaComposer);\n }\n});\n"],"names":["GraphQLSchemaComposerFeature","createFeature","container","GraphQLSchemaComposer"],"mappings":";;AAGO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains abstraction for use by the core Webiny team, or anyone contributing to the webiny-js repository.
|
|
3
|
-
*/
|
|
4
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export const CoreGraphQLSchemaFactory = createAbstraction("CoreGraphQLSchemaFactory");
|
|
2
|
+
const CoreGraphQLSchemaFactory = createAbstraction("CoreGraphQLSchemaFactory");
|
|
3
|
+
export { CoreGraphQLSchemaFactory };
|
|
9
4
|
|
|
10
5
|
//# sourceMappingURL=abstractions.core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/abstractions.core.js","sources":["../../src/graphql/abstractions.core.ts"],"sourcesContent":["/**\n * This file contains abstraction for use by the core Webiny team, or anyone contributing to the webiny-js repository.\n */\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { IGraphQLSchemaFactory } from \"./abstractions.public.js\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\n/**\n * CoreGraphQLSchemaFactory\n */\nexport const CoreGraphQLSchemaFactory = createAbstraction<IGraphQLSchemaFactory>(\n \"CoreGraphQLSchemaFactory\"\n);\nexport namespace CoreGraphQLSchemaFactory {\n export type Interface = IGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"names":["CoreGraphQLSchemaFactory","createAbstraction"],"mappings":";AAUO,MAAMA,2BAA2BC,kBACpC"}
|
package/graphql/abstractions.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains abstraction for use by third party developers.
|
|
3
|
-
*/
|
|
4
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Define custom GraphQL schema extensions. */
|
|
9
|
-
export const GraphQLSchemaFactory = createAbstraction("GraphQLSchemaFactory");
|
|
2
|
+
const GraphQLSchemaFactory = createAbstraction("GraphQLSchemaFactory");
|
|
3
|
+
export { GraphQLSchemaFactory };
|
|
10
4
|
|
|
11
5
|
//# sourceMappingURL=abstractions.public.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/abstractions.public.js","sources":["../../src/graphql/abstractions.public.ts"],"sourcesContent":["/**\n * This file contains abstraction for use by third party developers.\n */\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n Resolvers as IResolvers,\n TypeDefs as ITypeDefs,\n ResolverDecorators as IResolverDecorators\n} from \"~/types.js\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\nexport interface IGraphQLSchema {\n typeDefs?: ITypeDefs;\n resolvers?: IResolvers<any>;\n resolverDecorators?: IResolverDecorators;\n}\n\n/** Define custom GraphQL schema extensions. */\nexport interface IGraphQLSchemaFactory {\n execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;\n}\n\n/** Define custom GraphQL schema extensions. */\nexport const GraphQLSchemaFactory =\n createAbstraction<IGraphQLSchemaFactory>(\"GraphQLSchemaFactory\");\n\nexport namespace GraphQLSchemaFactory {\n export type Interface = IGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"names":["GraphQLSchemaFactory","createAbstraction"],"mappings":";AAuBO,MAAMA,uBACTC,kBAAyC"}
|
package/index.js
CHANGED
|
@@ -6,8 +6,7 @@ export * from "./plugins/index.js";
|
|
|
6
6
|
export * from "./processRequestBody.js";
|
|
7
7
|
export * from "./createResolverDecorator.js";
|
|
8
8
|
export * from "./ResolverDecoration.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
9
|
+
const src = (options = {})=>createGraphQLHandler(options);
|
|
10
|
+
export default src;
|
|
12
11
|
|
|
13
12
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { HandlerGraphQLOptions } from \"./types.js\";\nimport createGraphQLHandler from \"./createGraphQLHandler.js\";\n\nexport * from \"./errors.js\";\nexport * from \"./responses.js\";\nexport * from \"./utils/index.js\";\nexport * from \"./plugins/index.js\";\nexport * from \"./processRequestBody.js\";\nexport * from \"./createResolverDecorator.js\";\nexport * from \"./ResolverDecoration.js\";\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n return createGraphQLHandler(options);\n};\n"],"names":["options","createGraphQLHandler"],"mappings":";;;;;;;;AAYA,YAAgB,CAAAA,UAAiC,CAAC,CAAC,GACxCC,qBAAqBD"}
|
package/interceptConsole.js
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
const consoleMethods = [
|
|
1
|
+
const consoleMethods = [
|
|
2
|
+
"assert",
|
|
3
|
+
"debug",
|
|
4
|
+
"dir",
|
|
5
|
+
"error",
|
|
6
|
+
"group",
|
|
7
|
+
"groupCollapsed",
|
|
8
|
+
"groupEnd",
|
|
9
|
+
"info",
|
|
10
|
+
"log",
|
|
11
|
+
"table",
|
|
12
|
+
"warn"
|
|
13
|
+
];
|
|
2
14
|
const originalMethods = {};
|
|
3
|
-
const skipOriginal = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
console[method] = originalMethods[method];
|
|
8
|
-
}
|
|
15
|
+
const skipOriginal = [
|
|
16
|
+
"table"
|
|
17
|
+
];
|
|
18
|
+
const restoreOriginalMethods = ()=>{
|
|
19
|
+
for (const method of consoleMethods)console[method] = originalMethods[method];
|
|
9
20
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
console[method] = (...args) => {
|
|
23
|
-
callback(method, args);
|
|
24
|
-
if (skipOriginal.includes(method)) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
originalMethods[method](...args);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
21
|
+
const interceptConsole = (callback)=>{
|
|
22
|
+
if (true === console["__WEBINY__"]) restoreOriginalMethods();
|
|
23
|
+
console["__WEBINY__"] = true;
|
|
24
|
+
for (const method of consoleMethods){
|
|
25
|
+
originalMethods[method] = console[method];
|
|
26
|
+
console[method] = (...args)=>{
|
|
27
|
+
callback(method, args);
|
|
28
|
+
if (skipOriginal.includes(method)) return;
|
|
29
|
+
originalMethods[method](...args);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
30
32
|
};
|
|
33
|
+
export { interceptConsole };
|
|
31
34
|
|
|
32
35
|
//# sourceMappingURL=interceptConsole.js.map
|
package/interceptConsole.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"interceptConsole.js","sources":["../src/interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-expect-error\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-expect-error\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-expect-error\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-expect-error\n originalMethods[method] = console[method];\n // @ts-expect-error\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args"],"mappings":"AAAA,MAAMA,iBAAiB;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAED,MAAMC,kBAAuC,CAAC;AAC9C,MAAMC,eAAyB;IAAC;CAAQ;AAExC,MAAMC,yBAAyB;IAC3B,KAAK,MAAMC,UAAUJ,eAEjBK,OAAO,CAACD,OAAO,GAAGH,eAAe,CAACG,OAAO;AAEjD;AAMO,MAAME,mBAAmB,CAACC;IAE7B,IAAIF,AAA0B,SAA1BA,OAAO,CAAC,aAAa,EACrBF;IAIJE,OAAO,CAAC,aAAa,GAAG;IAExB,KAAK,MAAMD,UAAUJ,eAAgB;QAEjCC,eAAe,CAACG,OAAO,GAAGC,OAAO,CAACD,OAAO;QAEzCC,OAAO,CAACD,OAAO,GAAG,CAAC,GAAGI;YAClBD,SAASH,QAAQI;YACjB,IAAIN,aAAa,QAAQ,CAACE,SACtB;YAEJH,eAAe,CAACG,OAAO,IAAII;QAC/B;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -22,29 +22,29 @@
|
|
|
22
22
|
"@graphql-tools/resolvers-composition": "7.0.31",
|
|
23
23
|
"@graphql-tools/schema": "10.0.33",
|
|
24
24
|
"@graphql-tools/utils": "11.1.0",
|
|
25
|
-
"@webiny/api": "6.
|
|
25
|
+
"@webiny/api": "6.4.0-beta.0",
|
|
26
26
|
"@webiny/di": "0.2.3",
|
|
27
|
-
"@webiny/error": "6.
|
|
28
|
-
"@webiny/feature": "6.
|
|
29
|
-
"@webiny/handler": "6.
|
|
30
|
-
"@webiny/plugins": "6.
|
|
31
|
-
"@webiny/utils": "6.
|
|
27
|
+
"@webiny/error": "6.4.0-beta.0",
|
|
28
|
+
"@webiny/feature": "6.4.0-beta.0",
|
|
29
|
+
"@webiny/handler": "6.4.0-beta.0",
|
|
30
|
+
"@webiny/plugins": "6.4.0-beta.0",
|
|
31
|
+
"@webiny/utils": "6.4.0-beta.0",
|
|
32
32
|
"boolean": "3.2.0",
|
|
33
|
-
"graphql": "16.
|
|
33
|
+
"graphql": "16.14.0",
|
|
34
34
|
"graphql-scalars": "1.25.0",
|
|
35
35
|
"graphql-tag": "2.12.6",
|
|
36
|
-
"zod": "4.3
|
|
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.4.0-beta.0",
|
|
40
|
+
"@webiny/handler-aws": "6.4.0-beta.0",
|
|
41
41
|
"rimraf": "6.1.3",
|
|
42
42
|
"typescript": "6.0.3",
|
|
43
|
-
"vitest": "4.1.
|
|
43
|
+
"vitest": "4.1.6"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|
|
47
47
|
"directory": "dist"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
|
|
50
50
|
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
class GraphQLSchemaPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "graphql-schema";
|
|
5
|
+
}
|
|
6
|
+
constructor(config){
|
|
7
|
+
super();
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
get schema() {
|
|
11
|
+
return {
|
|
12
|
+
typeDefs: this.config.typeDefs || "",
|
|
13
|
+
resolvers: this.config.resolvers,
|
|
14
|
+
resolverDecorators: this.config.resolverDecorators
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
isApplicable(context) {
|
|
18
|
+
if (this.config.isApplicable) return this.config.isApplicable(context);
|
|
19
|
+
return true;
|
|
18
20
|
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
22
|
+
const createGraphQLSchemaPlugin = (config)=>new GraphQLSchemaPlugin(config);
|
|
23
|
+
export { GraphQLSchemaPlugin, createGraphQLSchemaPlugin };
|
|
25
24
|
|
|
26
25
|
//# sourceMappingURL=GraphQLSchemaPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/GraphQLSchemaPlugin.js","sources":["../../src/plugins/GraphQLSchemaPlugin.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from \"~/types.js\";\n\nexport interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {\n schema: GraphQLSchemaDefinition<TContext>;\n isApplicable: (context: TContext) => boolean;\n}\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\n isApplicable?: (context: TContext) => boolean;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context>\n extends Plugin\n implements IGraphQLSchemaPlugin<TContext>\n{\n public static override readonly type: string = \"graphql-schema\";\n protected config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers,\n resolverDecorators: this.config.resolverDecorators\n };\n }\n\n isApplicable(context: TContext): boolean {\n if (this.config.isApplicable) {\n return this.config.isApplicable(context);\n }\n return true;\n }\n}\n\nexport const createGraphQLSchemaPlugin = <T = Context>(config: GraphQLSchemaPluginConfig<T>) => {\n return new GraphQLSchemaPlugin<T>(config);\n};\n"],"names":["GraphQLSchemaPlugin","Plugin","config","context","createGraphQLSchemaPlugin"],"mappings":";AAgBO,MAAMA,4BACDC;;aAGwB,IAAI,GAAW;;IAG/C,YAAYC,MAA2C,CAAE;QACrD,KAAK;QACL,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,IAAI,SAA4C;QAC5C,OAAO;YACH,UAAU,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI;YAClC,WAAW,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,oBAAoB,IAAI,CAAC,MAAM,CAAC,kBAAkB;QACtD;IACJ;IAEA,aAAaC,OAAiB,EAAW;QACrC,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAACA;QAEpC,OAAO;IACX;AACJ;AAEO,MAAMC,4BAA4B,CAAcF,SAC5C,IAAIF,oBAAuBE"}
|
package/plugins/index.js
CHANGED
package/processRequestBody.js
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
import { graphql } from "graphql";
|
|
2
|
-
const executeGraphQl = async (body, schema, context)
|
|
3
|
-
|
|
4
|
-
query
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rootValue: {},
|
|
17
|
-
contextValue: context,
|
|
18
|
-
variableValues: variables,
|
|
19
|
-
operationName
|
|
20
|
-
});
|
|
21
|
-
context.plugins.byType("graphql-after-query").forEach(pl => {
|
|
22
|
-
pl.apply({
|
|
23
|
-
result,
|
|
24
|
-
body,
|
|
25
|
-
schema,
|
|
26
|
-
context
|
|
2
|
+
const executeGraphQl = async (body, schema, context)=>{
|
|
3
|
+
const { query, variables, operationName } = body;
|
|
4
|
+
context.plugins.byType("graphql-before-query").forEach((pl)=>pl.apply({
|
|
5
|
+
body,
|
|
6
|
+
schema,
|
|
7
|
+
context
|
|
8
|
+
}));
|
|
9
|
+
const result = await graphql({
|
|
10
|
+
schema,
|
|
11
|
+
source: query,
|
|
12
|
+
rootValue: {},
|
|
13
|
+
contextValue: context,
|
|
14
|
+
variableValues: variables,
|
|
15
|
+
operationName
|
|
27
16
|
});
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
context.plugins.byType("graphql-after-query").forEach((pl)=>{
|
|
18
|
+
pl.apply({
|
|
19
|
+
result,
|
|
20
|
+
body,
|
|
21
|
+
schema,
|
|
22
|
+
context
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
30
26
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const processRequestBody = async (requestBody, schema, context)=>{
|
|
28
|
+
if (Array.isArray(requestBody)) {
|
|
29
|
+
const results = [];
|
|
30
|
+
for (const body of requestBody){
|
|
31
|
+
const result = await executeGraphQl(body, schema, context);
|
|
32
|
+
results.push(result);
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
37
35
|
}
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
return await executeGraphQl(requestBody, schema, context);
|
|
36
|
+
return await executeGraphQl(requestBody, schema, context);
|
|
41
37
|
};
|
|
38
|
+
export { processRequestBody };
|
|
42
39
|
|
|
43
40
|
//# sourceMappingURL=processRequestBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"processRequestBody.js","sources":["../src/processRequestBody.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema } from \"graphql\";\nimport { graphql } from \"graphql\";\nimport type {\n GraphQLAfterQueryPlugin,\n GraphQLBeforeQueryPlugin,\n GraphQLRequestBody\n} from \"~/types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\n\nconst executeGraphQl = async <TData = Record<string, any>, TExtensions = Record<string, any>>(\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>> => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql({\n schema,\n source: query,\n rootValue: {},\n contextValue: context,\n variableValues: variables,\n operationName\n });\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result as ExecutionResult<TData, TExtensions>;\n};\n\nexport const processRequestBody = async <\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n>(\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>[] | ExecutionResult<TData, TExtensions>> => {\n if (Array.isArray(requestBody)) {\n const results: ExecutionResult<TData, TExtensions>[] = [];\n for (const body of requestBody) {\n const result = await executeGraphQl<TData, TExtensions>(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await executeGraphQl<TData, TExtensions>(requestBody, schema, context);\n};\n"],"names":["executeGraphQl","body","schema","context","query","variables","operationName","pl","result","graphql","processRequestBody","requestBody","Array","results"],"mappings":";AASA,MAAMA,iBAAiB,OACnBC,MACAC,QACAC;IAEA,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,aAAa,EAAE,GAAGL;IAE5CE,QAAQ,OAAO,CACV,MAAM,CAA2B,wBACjC,OAAO,CAACI,CAAAA,KAAMA,GAAG,KAAK,CAAC;YAAEN;YAAMC;YAAQC;QAAQ;IAEpD,MAAMK,SAAS,MAAMC,QAAQ;QACzBP;QACA,QAAQE;QACR,WAAW,CAAC;QACZ,cAAcD;QACd,gBAAgBE;QAChBC;IACJ;IAEAH,QAAQ,OAAO,CAAC,MAAM,CAA0B,uBAAuB,OAAO,CAACI,CAAAA;QAC3EA,GAAG,KAAK,CAAC;YAAEC;YAAQP;YAAMC;YAAQC;QAAQ;IAC7C;IAEA,OAAOK;AACX;AAEO,MAAME,qBAAqB,OAI9BC,aACAT,QACAC;IAEA,IAAIS,MAAM,OAAO,CAACD,cAAc;QAC5B,MAAME,UAAiD,EAAE;QACzD,KAAK,MAAMZ,QAAQU,YAAa;YAC5B,MAAMH,SAAS,MAAMR,eAAmCC,MAAMC,QAAQC;YACtEU,QAAQ,IAAI,CAACL;QACjB;QACA,OAAOK;IACX;IACA,OAAO,MAAMb,eAAmCW,aAAaT,QAAQC;AACzE"}
|
package/responses.js
CHANGED
|
@@ -1,76 +1,59 @@
|
|
|
1
1
|
const defaultParams = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
code: "",
|
|
3
|
+
message: "",
|
|
4
|
+
data: null,
|
|
5
|
+
stack: null
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
class ErrorResponse {
|
|
8
|
+
constructor(params){
|
|
9
|
+
this.data = null;
|
|
10
|
+
const debug = "true" === process.env.DEBUG;
|
|
11
|
+
let stack = defaultParams.stack;
|
|
12
|
+
if (debug && params.stack) stack = params.stack;
|
|
13
|
+
this.error = {
|
|
14
|
+
code: params.code || defaultParams.code,
|
|
15
|
+
message: params.message || defaultParams.message,
|
|
16
|
+
data: params.data || defaultParams.data,
|
|
17
|
+
stack: stack
|
|
18
|
+
};
|
|
18
19
|
}
|
|
19
|
-
this.error = {
|
|
20
|
-
code: params.code || defaultParams.code,
|
|
21
|
-
message: params.message || defaultParams.message,
|
|
22
|
-
data: params.data || defaultParams.data,
|
|
23
|
-
stack: stack
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
}
|
|
21
|
+
class NotFoundResponse extends ErrorResponse {
|
|
22
|
+
constructor(message){
|
|
23
|
+
super({
|
|
24
|
+
code: "NOT_FOUND",
|
|
25
|
+
message
|
|
26
|
+
});
|
|
27
|
+
}
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
class ListErrorResponse {
|
|
30
|
+
constructor(params){
|
|
31
|
+
this.meta = null;
|
|
32
|
+
this.data = null;
|
|
33
|
+
const debug = "true" === process.env.DEBUG;
|
|
34
|
+
let stack = defaultParams.stack;
|
|
35
|
+
if (debug && params.stack) stack = params.stack;
|
|
36
|
+
this.error = {
|
|
37
|
+
code: params.code || defaultParams.code,
|
|
38
|
+
message: params.message || defaultParams.message,
|
|
39
|
+
data: params.data || defaultParams.data,
|
|
40
|
+
stack: stack
|
|
41
|
+
};
|
|
49
42
|
}
|
|
50
|
-
this.error = {
|
|
51
|
-
code: params.code || defaultParams.code,
|
|
52
|
-
message: params.message || defaultParams.message,
|
|
53
|
-
data: params.data || defaultParams.data,
|
|
54
|
-
stack: stack
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
43
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.error = null;
|
|
64
|
-
}
|
|
44
|
+
class Response {
|
|
45
|
+
constructor(data){
|
|
46
|
+
this.data = data;
|
|
47
|
+
this.error = null;
|
|
48
|
+
}
|
|
65
49
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.error = null;
|
|
73
|
-
}
|
|
50
|
+
class ListResponse {
|
|
51
|
+
constructor(data, meta){
|
|
52
|
+
this.data = Array.isArray(data) ? data : [];
|
|
53
|
+
this.meta = meta || {};
|
|
54
|
+
this.error = null;
|
|
55
|
+
}
|
|
74
56
|
}
|
|
57
|
+
export { ErrorResponse, ListErrorResponse, ListResponse, NotFoundResponse, Response };
|
|
75
58
|
|
|
76
59
|
//# sourceMappingURL=responses.js.map
|
package/responses.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"responses.js","sources":["../src/responses.ts"],"sourcesContent":["export interface IMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor?: string | null;\n}\n\nexport interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\n/** GraphQL error response helper. */\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL not-found response helper. */\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\n/** GraphQL list error response helper. */\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL response helper. */\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\n/** GraphQL list response helper. */\nexport class ListResponse<T, M = IMeta> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"names":["defaultParams","ErrorResponse","params","debug","process","stack","NotFoundResponse","message","ListErrorResponse","Response","data","ListResponse","meta","Array"],"mappings":"AAaA,MAAMA,gBAA+C;IACjD,MAAM;IACN,SAAS;IACT,MAAM;IACN,OAAO;AACX;AAGO,MAAMC;IAST,YAAYC,MAA2B,CAAE;QACrC,IAAI,CAAC,IAAI,GAAG;QAEZ,MAAMC,QAAQC,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK;QAG/B,IAAIC,QAAQL,cAAc,KAAK;QAC/B,IAAIG,SAASD,OAAO,KAAK,EACrBG,QAAQH,OAAO,KAAK;QAGxB,IAAI,CAAC,KAAK,GAAG;YACT,MAAMA,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,SAASE,OAAO,OAAO,IAAIF,cAAc,OAAO;YAChD,MAAME,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,OAAOK;QACX;IACJ;AACJ;AAGO,MAAMC,yBAAyBL;IAClC,YAAYM,OAAe,CAAE;QACzB,KAAK,CAAC;YACF,MAAM;YACNA;QACJ;IACJ;AACJ;AAGO,MAAMC;IAUT,YAAYN,MAA2B,CAAE;QACrC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;QAEZ,MAAMC,QAAQC,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK;QAG/B,IAAIC,QAAQL,cAAc,KAAK;QAC/B,IAAIG,SAASD,OAAO,KAAK,EACrBG,QAAQH,OAAO,KAAK;QAGxB,IAAI,CAAC,KAAK,GAAG;YACT,MAAMA,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,SAASE,OAAO,OAAO,IAAIF,cAAc,OAAO;YAChD,MAAME,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,OAAOK;QACX;IACJ;AACJ;AAGO,MAAMI;IAIT,YAAYC,IAAO,CAAE;QACjB,IAAI,CAAC,IAAI,GAAGA;QACZ,IAAI,CAAC,KAAK,GAAG;IACjB;AACJ;AAGO,MAAMC;IAKT,YAAYD,IAAc,EAAEE,IAAQ,CAAE;QAClC,IAAI,CAAC,IAAI,GAAGC,MAAM,OAAO,CAACH,QAAQA,OAAO,EAAE;QAC3C,IAAI,CAAC,IAAI,GAAGE,QAAS,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG;IACjB;AACJ"}
|
package/types.js
CHANGED
package/utils/index.js
CHANGED
package/utils/resolve.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "../responses.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const emptyResolver = ()=>({});
|
|
3
|
+
const resolve = async (fn)=>{
|
|
4
|
+
try {
|
|
5
|
+
return new Response(await fn());
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
return new ErrorResponse(ex);
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const resolveList = async (fn)=>{
|
|
11
|
+
try {
|
|
12
|
+
const result = await fn();
|
|
13
|
+
return new ListResponse(result.items, result.meta);
|
|
14
|
+
} catch (ex) {
|
|
15
|
+
return new ListErrorResponse(ex);
|
|
16
|
+
}
|
|
17
17
|
};
|
|
18
|
+
export { emptyResolver, resolve, resolveList };
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=resolve.js.map
|
package/utils/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/resolve.js","sources":["../../src/utils/resolve.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"~/responses.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface Meta {\n totalCount: number;\n hasMoreItems: boolean;\n cursor: string | null;\n}\n\nexport const emptyResolver = () => ({});\n\ninterface ResolveCallable<T = GenericRecord> {\n (): Promise<T>;\n}\n\nexport const resolve = async <T = GenericRecord>(fn: ResolveCallable<T>) => {\n try {\n return new Response(await fn());\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\ninterface ResolveListCallable<T> {\n (): Promise<IListResult<T>>;\n}\n\ninterface IListResult<T = GenericRecord> {\n items: T[];\n meta: Meta;\n}\n\nexport const resolveList = async <T = GenericRecord>(fn: ResolveListCallable<T>) => {\n try {\n const result = (await fn()) as IListResult<T>;\n return new ListResponse(result.items, result.meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"names":["emptyResolver","resolve","fn","Response","ex","ErrorResponse","resolveList","result","ListResponse","ListErrorResponse"],"mappings":";AASO,MAAMA,gBAAgB,IAAO,EAAC;AAM9B,MAAMC,UAAU,OAA0BC;IAC7C,IAAI;QACA,OAAO,IAAIC,SAAS,MAAMD;IAC9B,EAAE,OAAOE,IAAI;QACT,OAAO,IAAIC,cAAcD;IAC7B;AACJ;AAWO,MAAME,cAAc,OAA0BJ;IACjD,IAAI;QACA,MAAMK,SAAU,MAAML;QACtB,OAAO,IAAIM,aAAaD,OAAO,KAAK,EAAEA,OAAO,IAAI;IACrD,EAAE,OAAOH,IAAI;QACT,OAAO,IAAIK,kBAAkBL;IACjC;AACJ"}
|