@webiny/handler-graphql 0.0.0-unstable.df6d94b531 → 0.0.0-unstable.e0bfc55d5a
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.d.ts +6 -0
- package/ResolverDecoration.js +26 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.js +3 -2
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.js +5 -5
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +5 -5
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +3 -2
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/JsonScalar.js +3 -2
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.js +5 -5
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.js +6 -6
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.js +33 -11
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +3 -2
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.js +3 -1
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +31 -5
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +3 -1
- package/createGraphQLSchema.js +47 -19
- package/createGraphQLSchema.js.map +1 -1
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +12 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +3 -1
- package/debugPlugins.js.map +1 -1
- package/errors.js +3 -1
- package/errors.js.map +1 -1
- package/index.d.ts +7 -2
- package/index.js +54 -2
- package/index.js.map +1 -1
- package/interceptConsole.js +8 -6
- package/interceptConsole.js.map +1 -1
- package/package.json +19 -22
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +16 -6
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.js +3 -1
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +16 -7
- package/processRequestBody.js.map +1 -1
- package/responses.js +3 -13
- package/responses.js.map +1 -1
- package/types.d.ts +17 -10
- package/types.js +3 -1
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +28 -0
- package/utils/resolve.js.map +1 -0
package/createGraphQLSchema.js
CHANGED
|
@@ -4,15 +4,25 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createGraphQLSchema = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
7
|
+
exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
|
|
9
8
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
10
9
|
var _schema = require("@graphql-tools/schema");
|
|
10
|
+
var _merge = require("@graphql-tools/merge");
|
|
11
11
|
var _builtInTypes = require("./builtInTypes");
|
|
12
|
+
var _ResolverDecoration = require("./ResolverDecoration");
|
|
13
|
+
const getSchemaPlugins = context => {
|
|
14
|
+
return context.plugins.byType("graphql-schema").filter(pl => {
|
|
15
|
+
if (typeof pl.isApplicable === "function") {
|
|
16
|
+
return pl.isApplicable(context);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.getSchemaPlugins = getSchemaPlugins;
|
|
12
22
|
const createGraphQLSchema = context => {
|
|
13
23
|
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
14
24
|
|
|
15
|
-
// TODO: once the API packages more closed, we'll have the opportunity
|
|
25
|
+
// TODO: once the API packages are more closed, we'll have the opportunity
|
|
16
26
|
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
17
27
|
const typeDefs = [(0, _graphqlTag.default)`
|
|
18
28
|
type Query
|
|
@@ -31,11 +41,24 @@ const createGraphQLSchema = context => {
|
|
|
31
41
|
# as a way to tell the Prerendering Service whether the GraphQL query needs to be
|
|
32
42
|
# cached or not.
|
|
33
43
|
directive @ps(cache: Boolean) on QUERY
|
|
44
|
+
|
|
45
|
+
type Error {
|
|
46
|
+
code: String
|
|
47
|
+
message: String
|
|
48
|
+
data: JSON
|
|
49
|
+
stack: String
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type BooleanResponse {
|
|
53
|
+
data: Boolean
|
|
54
|
+
error: Error
|
|
55
|
+
}
|
|
34
56
|
`];
|
|
35
|
-
const resolvers = [
|
|
36
|
-
acc
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
const resolvers = [{
|
|
58
|
+
...scalars.reduce((acc, s) => {
|
|
59
|
+
acc[s.name] = s;
|
|
60
|
+
return acc;
|
|
61
|
+
}, {}),
|
|
39
62
|
JSON: _builtInTypes.JsonScalar,
|
|
40
63
|
Long: _builtInTypes.LongScalar,
|
|
41
64
|
RefInput: _builtInTypes.RefInputScalar,
|
|
@@ -44,22 +67,27 @@ const createGraphQLSchema = context => {
|
|
|
44
67
|
DateTime: _builtInTypes.DateTimeScalar,
|
|
45
68
|
Date: _builtInTypes.DateScalar,
|
|
46
69
|
Time: _builtInTypes.TimeScalar
|
|
47
|
-
}
|
|
48
|
-
const
|
|
70
|
+
}];
|
|
71
|
+
const resolverDecoration = new _ResolverDecoration.ResolverDecoration();
|
|
72
|
+
const plugins = getSchemaPlugins(context);
|
|
49
73
|
for (const plugin of plugins) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
const schema = plugin.schema;
|
|
75
|
+
if (schema.typeDefs) {
|
|
76
|
+
typeDefs.push(schema.typeDefs);
|
|
77
|
+
}
|
|
78
|
+
if (schema.resolvers) {
|
|
79
|
+
resolvers.push(schema.resolvers);
|
|
80
|
+
}
|
|
81
|
+
if (schema.resolverDecorators) {
|
|
82
|
+
resolverDecoration.addDecorators(schema.resolverDecorators);
|
|
83
|
+
}
|
|
58
84
|
}
|
|
59
85
|
return (0, _schema.makeExecutableSchema)({
|
|
60
86
|
typeDefs,
|
|
61
|
-
resolvers,
|
|
87
|
+
resolvers: resolverDecoration.decorateResolvers((0, _merge.mergeResolvers)(resolvers)),
|
|
62
88
|
inheritResolversFromInterfaces: true
|
|
63
89
|
});
|
|
64
90
|
};
|
|
65
|
-
exports.createGraphQLSchema = createGraphQLSchema;
|
|
91
|
+
exports.createGraphQLSchema = createGraphQLSchema;
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=createGraphQLSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_merge","_builtInTypes","_ResolverDecoration","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","resolverDecoration","ResolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","makeExecutableSchema","decorateResolvers","mergeResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport type { GraphQLScalarType } from \"graphql/type/definition\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types\";\nimport type { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { ResolverDecoration } from \"./ResolverDecoration\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\").filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n};\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages are more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs: TypeDefs[] = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n\n type Error {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type BooleanResponse {\n data: Boolean\n error: Error\n }\n `\n ];\n\n const resolvers: Resolvers<any>[] = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n const plugins = getSchemaPlugins(context);\n\n for (const plugin of plugins) {\n const schema = plugin.schema;\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAIA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AAGO,MAAMK,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC,CAACC,MAAM,CAACC,EAAE,IAAI;IAC9E,IAAI,OAAOA,EAAE,CAACC,YAAY,KAAK,UAAU,EAAE;MACvC,OAAOD,EAAE,CAACC,YAAY,CAACL,OAAO,CAAC;IACnC;IACA,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAACM,OAAA,CAAAP,gBAAA,GAAAA,gBAAA;AAEK,MAAMQ,mBAAmB,GAAIP,OAAgB,IAAK;EACrD,MAAMQ,OAAO,GAAGR,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CO,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAoB,GAAG,CACzB,IAAAC,mBAAG;AACX;AACA;AACA,cAAcL,OAAO,CAACC,GAAG,CAACE,MAAM,IAAI,UAAUA,MAAM,CAACG,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AACN,CAAC;AAACxC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createResolverDecorator = void 0;
|
|
7
|
+
const createResolverDecorator = decorator => {
|
|
8
|
+
return decorator;
|
|
9
|
+
};
|
|
10
|
+
exports.createResolverDecorator = createResolverDecorator;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=createResolverDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createResolverDecorator","decorator","exports"],"sources":["createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,uBAAuB,GAChCC,SAAsD,IACrD;EACD,OAAOA,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/debugPlugins.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
-
import { Context } from "@webiny/api/types";
|
|
1
|
+
import type { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
+
import type { Context } from "@webiny/api/types";
|
|
3
3
|
import { ContextPlugin } from "@webiny/api";
|
|
4
4
|
interface Log {
|
|
5
5
|
method: string;
|
package/debugPlugins.js
CHANGED
package/debugPlugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;AAAA;AAGA;AAA4C,
|
|
1
|
+
{"version":3,"names":["_interceptConsole","require","_api","_default","ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length","exports","default"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport type { GraphQLAfterQueryPlugin } from \"./types\";\nimport type { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAD,OAAA;AAA4C,IAAAE,QAAA,GAY7BA,CAAA,KAAM,CACjB,IAAIC,kBAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEA,IAAAC,kCAAgB,EAAC,CAACC,MAAM,EAAEC,IAAI,KAAK;IAC9BL,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWI,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAKA,CAAC;IAAEC,MAAM;IAAET;EAAQ,CAAC,EAAE;IACvBS,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACS,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ;AAAAC,OAAA,CAAAC,OAAA,GAAAf,QAAA","ignoreList":[]}
|
package/errors.js
CHANGED
package/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA;AAEO,
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","NotFoundError","WebinyError","constructor","message","exports"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAWA,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAACC,OAAA,CAAAJ,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types";
|
|
2
3
|
export * from "./errors";
|
|
3
4
|
export * from "./responses";
|
|
5
|
+
export * from "./utils";
|
|
4
6
|
export * from "./plugins";
|
|
5
|
-
|
|
7
|
+
export * from "./processRequestBody";
|
|
8
|
+
export * from "./createResolverDecorator";
|
|
9
|
+
export * from "./ResolverDecoration";
|
|
10
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
6
11
|
export default _default;
|
package/index.js
CHANGED
|
@@ -31,6 +31,18 @@ Object.keys(_responses).forEach(function (key) {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
+
var _utils = require("./utils");
|
|
35
|
+
Object.keys(_utils).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
38
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
39
|
+
Object.defineProperty(exports, key, {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return _utils[key];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
34
46
|
var _plugins = require("./plugins");
|
|
35
47
|
Object.keys(_plugins).forEach(function (key) {
|
|
36
48
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -43,5 +55,45 @@ Object.keys(_plugins).forEach(function (key) {
|
|
|
43
55
|
}
|
|
44
56
|
});
|
|
45
57
|
});
|
|
46
|
-
var
|
|
47
|
-
|
|
58
|
+
var _processRequestBody = require("./processRequestBody");
|
|
59
|
+
Object.keys(_processRequestBody).forEach(function (key) {
|
|
60
|
+
if (key === "default" || key === "__esModule") return;
|
|
61
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
62
|
+
if (key in exports && exports[key] === _processRequestBody[key]) return;
|
|
63
|
+
Object.defineProperty(exports, key, {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () {
|
|
66
|
+
return _processRequestBody[key];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
var _createResolverDecorator = require("./createResolverDecorator");
|
|
71
|
+
Object.keys(_createResolverDecorator).forEach(function (key) {
|
|
72
|
+
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
74
|
+
if (key in exports && exports[key] === _createResolverDecorator[key]) return;
|
|
75
|
+
Object.defineProperty(exports, key, {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _createResolverDecorator[key];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
var _ResolverDecoration = require("./ResolverDecoration");
|
|
83
|
+
Object.keys(_ResolverDecoration).forEach(function (key) {
|
|
84
|
+
if (key === "default" || key === "__esModule") return;
|
|
85
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
86
|
+
if (key in exports && exports[key] === _ResolverDecoration[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _ResolverDecoration[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _default = (options = {}) => {
|
|
95
|
+
return (0, _createGraphQLHandler.default)(options);
|
|
96
|
+
};
|
|
97
|
+
exports.default = _default;
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["options","createGraphQLHandler"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\n\nexport default (options: HandlerGraphQLOptions = {}) =>
|
|
1
|
+
{"version":3,"names":["_createGraphQLHandler","_interopRequireDefault","require","_errors","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_responses","_utils","_plugins","_processRequestBody","_createResolverDecorator","_ResolverDecoration","_default","options","createGraphQLHandler","default"],"sources":["index.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types\";\nimport type { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./utils\";\nexport * from \"./plugins\";\nexport * from \"./processRequestBody\";\nexport * from \"./createResolverDecorator\";\nexport * from \"./ResolverDecoration\";\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n return createGraphQLHandler(options);\n};\n"],"mappings":";;;;;;;;AAEA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,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AA,CAAAC,IAAA,CAAAgB,mBAAA,EAAAf,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAc,mBAAA,CAAAd,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,mBAAA,CAAAd,GAAA;IAAA;EAAA;AAAA;AAAqC,IAAAe,QAAA,GAEtBA,CAACC,OAA8B,GAAG,CAAC,CAAC,KAAe;EAC9D,OAAO,IAAAC,6BAAoB,EAACD,OAAO,CAAC;AACxC,CAAC;AAAAX,OAAA,CAAAa,OAAA,GAAAH,QAAA","ignoreList":[]}
|
package/interceptConsole.js
CHANGED
|
@@ -9,22 +9,22 @@ const originalMethods = {};
|
|
|
9
9
|
const skipOriginal = ["table"];
|
|
10
10
|
const restoreOriginalMethods = () => {
|
|
11
11
|
for (const method of consoleMethods) {
|
|
12
|
-
// @ts-
|
|
12
|
+
// @ts-expect-error
|
|
13
13
|
console[method] = originalMethods[method];
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
const interceptConsole = callback => {
|
|
17
|
-
// @ts-
|
|
17
|
+
// @ts-expect-error
|
|
18
18
|
if (console["__WEBINY__"] === true) {
|
|
19
19
|
restoreOriginalMethods();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// @ts-
|
|
22
|
+
// @ts-expect-error
|
|
23
23
|
console["__WEBINY__"] = true;
|
|
24
24
|
for (const method of consoleMethods) {
|
|
25
|
-
// @ts-
|
|
25
|
+
// @ts-expect-error
|
|
26
26
|
originalMethods[method] = console[method];
|
|
27
|
-
// @ts-
|
|
27
|
+
// @ts-expect-error
|
|
28
28
|
console[method] = (...args) => {
|
|
29
29
|
callback(method, args);
|
|
30
30
|
if (skipOriginal.includes(method)) {
|
|
@@ -34,4 +34,6 @@ const interceptConsole = callback => {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
exports.interceptConsole = interceptConsole;
|
|
37
|
+
exports.interceptConsole = interceptConsole;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=interceptConsole.js.map
|
package/interceptConsole.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["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-
|
|
1
|
+
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes","exports"],"sources":["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"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,CACT;AAED,MAAMC,eAAoC,GAAG,CAAC,CAAC;AAC/C,MAAMC,YAAsB,GAAG,CAAC,OAAO,CAAC;AAExC,MAAMC,sBAAsB,GAAGA,CAAA,KAAM;EACjC,KAAK,MAAMC,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAK,OAAO,CAACD,MAAM,CAAC,GAAGH,eAAe,CAACG,MAAM,CAAC;EAC7C;AACJ,CAAC;AAMM,MAAME,gBAAgB,GAAIC,QAAkC,IAAK;EACpE;EACA,IAAIF,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;IAChCF,sBAAsB,CAAC,CAAC;EAC5B;;EAEA;EACAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;EAE5B,KAAK,MAAMD,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAC,eAAe,CAACG,MAAM,CAAC,GAAGC,OAAO,CAACD,MAAM,CAAC;IACzC;IACAC,OAAO,CAACD,MAAM,CAAC,GAAG,CAAC,GAAGI,IAAI,KAAK;MAC3BD,QAAQ,CAACH,MAAM,EAAEI,IAAI,CAAC;MACtB,IAAIN,YAAY,CAACO,QAAQ,CAACL,MAAM,CAAC,EAAE;QAC/B;MACJ;MACAH,eAAe,CAACG,MAAM,CAAC,CAAC,GAAGI,IAAI,CAAC;IACpC,CAAC;EACL;AACJ,CAAC;AAACE,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e0bfc55d5a",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,37 +14,34 @@
|
|
|
14
14
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@graphql-tools/
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
17
|
+
"@graphql-tools/merge": "9.0.8",
|
|
18
|
+
"@graphql-tools/resolvers-composition": "7.0.2",
|
|
19
|
+
"@graphql-tools/schema": "10.0.7",
|
|
20
|
+
"@graphql-tools/utils": "10.5.5",
|
|
21
|
+
"@webiny/api": "0.0.0-unstable.e0bfc55d5a",
|
|
22
|
+
"@webiny/error": "0.0.0-unstable.e0bfc55d5a",
|
|
23
|
+
"@webiny/handler": "0.0.0-unstable.e0bfc55d5a",
|
|
24
|
+
"@webiny/plugins": "0.0.0-unstable.e0bfc55d5a",
|
|
23
25
|
"boolean": "3.2.0",
|
|
24
|
-
"graphql": "15.
|
|
26
|
+
"graphql": "15.9.0",
|
|
25
27
|
"graphql-scalars": "1.12.0",
|
|
26
28
|
"graphql-tag": "2.12.6"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"jest": "^28.1.0",
|
|
36
|
-
"jest-mock-console": "^1.0.0",
|
|
37
|
-
"rimraf": "^3.0.2",
|
|
38
|
-
"ttypescript": "^1.5.13",
|
|
39
|
-
"typescript": "4.7.4"
|
|
31
|
+
"@webiny/handler-aws": "0.0.0-unstable.e0bfc55d5a",
|
|
32
|
+
"@webiny/project-utils": "0.0.0-unstable.e0bfc55d5a",
|
|
33
|
+
"jest": "29.7.0",
|
|
34
|
+
"jest-mock-console": "2.0.0",
|
|
35
|
+
"rimraf": "6.0.1",
|
|
36
|
+
"typescript": "5.3.3"
|
|
40
37
|
},
|
|
41
38
|
"publishConfig": {
|
|
42
39
|
"access": "public",
|
|
43
40
|
"directory": "dist"
|
|
44
41
|
},
|
|
45
42
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"watch": "
|
|
43
|
+
"build": "node ../cli/bin.js run build",
|
|
44
|
+
"watch": "node ../cli/bin.js run watch"
|
|
48
45
|
},
|
|
49
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "e0bfc55d5a4d6a42b32e6558d9fb2eb6753e331b"
|
|
50
47
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import type { Context } from "@webiny/api/types";
|
|
1
2
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import { GraphQLSchemaDefinition, Resolvers,
|
|
3
|
-
|
|
3
|
+
import type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from "../types";
|
|
4
|
+
export interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
5
|
+
schema: GraphQLSchemaDefinition<TContext>;
|
|
6
|
+
isApplicable: (context: TContext) => boolean;
|
|
7
|
+
}
|
|
4
8
|
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
5
|
-
typeDefs?:
|
|
9
|
+
typeDefs?: TypeDefs;
|
|
6
10
|
resolvers?: Resolvers<TContext>;
|
|
11
|
+
resolverDecorators?: ResolverDecorators;
|
|
12
|
+
isApplicable?: (context: TContext) => boolean;
|
|
7
13
|
}
|
|
8
|
-
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
14
|
+
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin implements IGraphQLSchemaPlugin<TContext> {
|
|
9
15
|
static readonly type: string;
|
|
10
|
-
|
|
16
|
+
protected config: GraphQLSchemaPluginConfig<TContext>;
|
|
11
17
|
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
12
18
|
get schema(): GraphQLSchemaDefinition<TContext>;
|
|
19
|
+
isApplicable(context: TContext): boolean;
|
|
13
20
|
}
|
|
21
|
+
export declare const createGraphQLSchemaPlugin: <T = Context>(config: GraphQLSchemaPluginConfig<T>) => GraphQLSchemaPlugin<T>;
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.GraphQLSchemaPlugin = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
|
+
exports.createGraphQLSchemaPlugin = exports.GraphQLSchemaPlugin = void 0;
|
|
9
7
|
var _plugins = require("@webiny/plugins");
|
|
10
8
|
class GraphQLSchemaPlugin extends _plugins.Plugin {
|
|
9
|
+
static type = "graphql-schema";
|
|
11
10
|
constructor(config) {
|
|
12
11
|
super();
|
|
13
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
|
14
12
|
this.config = config;
|
|
15
13
|
}
|
|
16
14
|
get schema() {
|
|
17
15
|
return {
|
|
18
16
|
typeDefs: this.config.typeDefs || "",
|
|
19
|
-
resolvers: this.config.resolvers
|
|
17
|
+
resolvers: this.config.resolvers,
|
|
18
|
+
resolverDecorators: this.config.resolverDecorators
|
|
20
19
|
};
|
|
21
20
|
}
|
|
21
|
+
isApplicable(context) {
|
|
22
|
+
if (this.config.isApplicable) {
|
|
23
|
+
return this.config.isApplicable(context);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
exports.GraphQLSchemaPlugin = GraphQLSchemaPlugin;
|
|
24
|
-
|
|
29
|
+
const createGraphQLSchemaPlugin = config => {
|
|
30
|
+
return new GraphQLSchemaPlugin(config);
|
|
31
|
+
};
|
|
32
|
+
exports.createGraphQLSchemaPlugin = createGraphQLSchemaPlugin;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=GraphQLSchemaPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers,
|
|
1
|
+
{"version":3,"names":["_plugins","require","GraphQLSchemaPlugin","Plugin","type","constructor","config","schema","typeDefs","resolvers","resolverDecorators","isApplicable","context","exports","createGraphQLSchemaPlugin"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from \"~/types\";\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"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAeO,MAAMC,mBAAmB,SACpBC,eAAM,CAElB;EACI,OAAgCC,IAAI,GAAW,gBAAgB;EAG/DC,WAAWA,CAACC,MAA2C,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,IAAIC,MAAMA,CAAA,EAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,IAAI,CAACF,MAAM,CAACE,QAAQ,IAAI,EAAE;MACpCC,SAAS,EAAE,IAAI,CAACH,MAAM,CAACG,SAAS;MAChCC,kBAAkB,EAAE,IAAI,CAACJ,MAAM,CAACI;IACpC,CAAC;EACL;EAEAC,YAAYA,CAACC,OAAiB,EAAW;IACrC,IAAI,IAAI,CAACN,MAAM,CAACK,YAAY,EAAE;MAC1B,OAAO,IAAI,CAACL,MAAM,CAACK,YAAY,CAACC,OAAO,CAAC;IAC5C;IACA,OAAO,IAAI;EACf;AACJ;AAACC,OAAA,CAAAX,mBAAA,GAAAA,mBAAA;AAEM,MAAMY,yBAAyB,GAAiBR,MAAoC,IAAK;EAC5F,OAAO,IAAIJ,mBAAmB,CAAII,MAAM,CAAC;AAC7C,CAAC;AAACO,OAAA,CAAAC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
package/plugins/index.js
CHANGED
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;AAAA;
|
|
1
|
+
{"version":3,"names":["_GraphQLSchemaPlugin","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,oBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,oBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,oBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/processRequestBody.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
-
import { GraphQLRequestBody } from "./types";
|
|
3
|
-
import { Context } from "@webiny/api/types";
|
|
4
|
-
declare const
|
|
5
|
-
export default _default;
|
|
1
|
+
import type { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
+
import type { GraphQLRequestBody } from "./types";
|
|
3
|
+
import type { Context } from "@webiny/api/types";
|
|
4
|
+
export declare const processRequestBody: <TData = Record<string, any>, TExtensions = Record<string, any>>(requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult<TData, TExtensions> | ExecutionResult<TData, TExtensions>[]>;
|
package/processRequestBody.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.processRequestBody = void 0;
|
|
7
7
|
var _graphql = require("graphql");
|
|
8
|
-
const
|
|
8
|
+
const executeGraphQl = async (body, schema, context) => {
|
|
9
9
|
const {
|
|
10
10
|
query,
|
|
11
11
|
variables,
|
|
@@ -16,7 +16,14 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
16
16
|
schema,
|
|
17
17
|
context
|
|
18
18
|
}));
|
|
19
|
-
const result = await (0, _graphql.graphql)(
|
|
19
|
+
const result = await (0, _graphql.graphql)({
|
|
20
|
+
schema,
|
|
21
|
+
source: query,
|
|
22
|
+
rootValue: {},
|
|
23
|
+
contextValue: context,
|
|
24
|
+
variableValues: variables,
|
|
25
|
+
operationName
|
|
26
|
+
});
|
|
20
27
|
context.plugins.byType("graphql-after-query").forEach(pl => {
|
|
21
28
|
pl.apply({
|
|
22
29
|
result,
|
|
@@ -27,15 +34,17 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
27
34
|
});
|
|
28
35
|
return result;
|
|
29
36
|
};
|
|
30
|
-
|
|
37
|
+
const processRequestBody = async (requestBody, schema, context) => {
|
|
31
38
|
if (Array.isArray(requestBody)) {
|
|
32
39
|
const results = [];
|
|
33
40
|
for (const body of requestBody) {
|
|
34
|
-
const result = await
|
|
41
|
+
const result = await executeGraphQl(body, schema, context);
|
|
35
42
|
results.push(result);
|
|
36
43
|
}
|
|
37
44
|
return results;
|
|
38
45
|
}
|
|
39
|
-
return await
|
|
46
|
+
return await executeGraphQl(requestBody, schema, context);
|
|
40
47
|
};
|
|
41
|
-
exports.
|
|
48
|
+
exports.processRequestBody = processRequestBody;
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=processRequestBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_graphql","require","executeGraphQl","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","source","rootValue","contextValue","variableValues","processRequestBody","requestBody","Array","isArray","results","push","exports"],"sources":["processRequestBody.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema } from \"graphql\";\nimport { graphql } from \"graphql\";\nimport type {\n GraphQLAfterQueryPlugin,\n GraphQLBeforeQueryPlugin,\n GraphQLRequestBody\n} from \"~/types\";\nimport type { Context } from \"@webiny/api/types\";\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"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAQA,MAAMC,cAAc,GAAG,MAAAA,CACnBC,IAAwB,EACxBC,MAAqB,EACrBC,OAAgB,KAC+B;EAC/C,MAAM;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGL,IAAI;EAEhDE,OAAO,CAACI,OAAO,CACVC,MAAM,CAA2B,sBAAsB,CAAC,CACxDC,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACC,KAAK,CAAC;IAAEV,IAAI;IAAEC,MAAM;IAAEC;EAAQ,CAAC,CAAC,CAAC;EAEvD,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAO,EAAC;IACzBX,MAAM;IACNY,MAAM,EAAEV,KAAK;IACbW,SAAS,EAAE,CAAC,CAAC;IACbC,YAAY,EAAEb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