@webiny/handler-graphql 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/builtInTypes/AnyScalar.d.ts +2 -0
- package/builtInTypes/AnyScalar.js +20 -0
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.d.ts +2 -0
- package/builtInTypes/DateScalar.js +34 -0
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.d.ts +2 -0
- package/builtInTypes/DateTimeScalar.js +34 -0
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.d.ts +6 -0
- package/builtInTypes/DateTimeZScalar.js +63 -0
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -0
- package/builtInTypes/JsonScalar.js +11 -0
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +1 -0
- package/builtInTypes/LongScalar.js +11 -0
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +2 -0
- package/builtInTypes/NumberScalar.js +64 -0
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +2 -0
- package/builtInTypes/RefInputScalar.js +65 -0
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.d.ts +2 -0
- package/builtInTypes/TimeScalar.js +71 -0
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.d.ts +9 -0
- package/builtInTypes/index.js +122 -0
- package/builtInTypes/index.js.map +1 -0
- package/createGraphQLHandler.d.ts +4 -0
- package/createGraphQLHandler.js +82 -0
- package/createGraphQLHandler.js.map +1 -0
- package/createGraphQLSchema.d.ts +2 -0
- package/createGraphQLSchema.js +73 -0
- package/createGraphQLSchema.js.map +1 -0
- package/debugPlugins.d.ts +14 -0
- package/debugPlugins.js +45 -0
- package/debugPlugins.js.map +1 -0
- package/errors.d.ts +4 -0
- package/errors.js +19 -0
- package/errors.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +57 -0
- package/index.js.map +1 -0
- package/interceptConsole.d.ts +5 -0
- package/interceptConsole.js +43 -0
- package/interceptConsole.js.map +1 -0
- package/package.json +50 -0
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -0
- package/plugins/GraphQLSchemaPlugin.js +31 -0
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/processRequestBody.d.ts +5 -0
- package/processRequestBody.js +47 -0
- package/processRequestBody.js.map +1 -0
- package/responses.d.ts +41 -0
- package/responses.js +107 -0
- package/responses.js.map +1 -0
- package/types.d.ts +52 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _boolean = require("boolean");
|
|
11
|
+
|
|
12
|
+
var _handler = require("@webiny/handler");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
17
|
+
|
|
18
|
+
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
19
|
+
|
|
20
|
+
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
23
|
+
|
|
24
|
+
const createRequestBody = body => {
|
|
25
|
+
/**
|
|
26
|
+
* We are trusting that the body payload is correct.
|
|
27
|
+
* The `processRequestBody` will fail if it is not.
|
|
28
|
+
*/
|
|
29
|
+
return typeof body === "string" ? JSON.parse(body) : body;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const formatErrorPayload = error => {
|
|
33
|
+
if (error instanceof _error.default) {
|
|
34
|
+
return {
|
|
35
|
+
message: error.message,
|
|
36
|
+
code: error.code,
|
|
37
|
+
data: error.data
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
name: error.name,
|
|
43
|
+
message: error.message,
|
|
44
|
+
stack: error.stack
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var _default = (options = {}) => {
|
|
49
|
+
let schema = undefined;
|
|
50
|
+
const debug = (0, _boolean.boolean)(options.debug);
|
|
51
|
+
const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
|
|
52
|
+
const route = new _handler.RoutePlugin(async ({
|
|
53
|
+
onPost,
|
|
54
|
+
onOptions,
|
|
55
|
+
context
|
|
56
|
+
}) => {
|
|
57
|
+
onOptions(path, async (_, reply) => {
|
|
58
|
+
return reply.status(204).headers({
|
|
59
|
+
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
60
|
+
}).send({});
|
|
61
|
+
});
|
|
62
|
+
onPost(path, async (request, reply) => {
|
|
63
|
+
if (!schema) {
|
|
64
|
+
try {
|
|
65
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const body = createRequestBody(request.body);
|
|
72
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
73
|
+
return reply.status(200).send(result);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
route.name = "handler.graphql.route.default";
|
|
77
|
+
return [...(debug ? (0, _debugPlugins.default)() : []), {
|
|
78
|
+
type: "wcp-telemetry-tracker"
|
|
79
|
+
}, route];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","ex","result","processRequestBody","debugPlugins","type"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error) => {\n if (error instanceof WebinyError) {\n return {\n message: error.message,\n code: error.code,\n data: error.data\n };\n }\n\n return {\n name: error.name,\n message: error.message,\n stack: error.stack\n };\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({});\n });\n onPost(path, async (request, reply) => {\n if (!schema) {\n try {\n schema = createGraphQLSchema(context);\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n const body = createRequestBody(request.body);\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AAEA,MAAMA,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAExC,MAAMC,iBAAiB,GAAIC,IAAD,IAA8D;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAND;;AAQA,MAAMG,kBAAkB,GAAIC,KAAD,IAAkB;EACzC,IAAIA,KAAK,YAAYC,cAArB,EAAkC;IAC9B,OAAO;MACHC,OAAO,EAAEF,KAAK,CAACE,OADZ;MAEHC,IAAI,EAAEH,KAAK,CAACG,IAFT;MAGHC,IAAI,EAAEJ,KAAK,CAACI;IAHT,CAAP;EAKH;;EAED,OAAO;IACHC,IAAI,EAAEL,KAAK,CAACK,IADT;IAEHH,OAAO,EAAEF,KAAK,CAACE,OAFZ;IAGHI,KAAK,EAAEN,KAAK,CAACM;EAHV,CAAP;AAKH,CAdD;;eAgBe,CAACC,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQJ,OAAO,CAACG,KAAhB,CAAd;EAEA,MAAME,IAAI,GAAG,CAAAL,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEK,IAAT,KAAiB,UAA9B;EAEA,MAAMC,KAAK,GAAG,IAAIC,oBAAJ,CAAgB,OAAO;IAAEC,MAAF;IAAUC,SAAV;IAAqBC;EAArB,CAAP,KAA0C;IACpED,SAAS,CAACJ,IAAD,EAAO,OAAOM,CAAP,EAAUC,KAAV,KAAoB;MAChC,OAAOA,KAAK,CACPC,MADE,CACK,GADL,EAEFC,OAFE,CAEM;QACL,iBAAkB,mBAAkB3B,qBAAsB;MADrD,CAFN,EAKF4B,IALE,CAKG,EALH,CAAP;IAMH,CAPQ,CAAT;IAQAP,MAAM,CAACH,IAAD,EAAO,OAAOW,OAAP,EAAgBJ,KAAhB,KAA0B;MACnC,IAAI,CAACX,MAAL,EAAa;QACT,IAAI;UACAA,MAAM,GAAG,IAAAgB,wCAAA,EAAoBP,OAApB,CAAT;QACH,CAFD,CAEE,OAAOQ,EAAP,EAAW;UACT,OAAON,KAAK,CAAChB,IAAN,CAAW,GAAX,EAAgBmB,IAAhB,CAAqBvB,kBAAkB,CAAC0B,EAAD,CAAvC,CAAP;QACH;MACJ;;MACD,MAAM7B,IAAI,GAAGD,iBAAiB,CAAC4B,OAAO,CAAC3B,IAAT,CAA9B;MACA,MAAM8B,MAAM,GAAG,MAAM,IAAAC,2BAAA,EAAmB/B,IAAnB,EAAyBY,MAAzB,EAAiCS,OAAjC,CAArB;MACA,OAAOE,KAAK,CAACC,MAAN,CAAa,GAAb,EAAkBE,IAAlB,CAAuBI,MAAvB,CAAP;IACH,CAXK,CAAN;EAYH,CArBa,CAAd;EAuBAb,KAAK,CAACR,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIK,KAAK,GAAG,IAAAkB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACIC,IAAI,EAAE;EADV,CAFG,EAKHhB,KALG,CAAP;AAOH,C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createGraphQLSchema = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
|
+
|
|
14
|
+
var _schema = require("@graphql-tools/schema");
|
|
15
|
+
|
|
16
|
+
var _builtInTypes = require("./builtInTypes");
|
|
17
|
+
|
|
18
|
+
const createGraphQLSchema = context => {
|
|
19
|
+
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar); // TODO: once the API packages more closed, we'll have the opportunity
|
|
20
|
+
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
21
|
+
|
|
22
|
+
const typeDefs = [(0, _graphqlTag.default)`
|
|
23
|
+
type Query
|
|
24
|
+
type Mutation
|
|
25
|
+
${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
|
|
26
|
+
scalar JSON
|
|
27
|
+
scalar Long
|
|
28
|
+
scalar RefInput
|
|
29
|
+
scalar Number
|
|
30
|
+
scalar Any
|
|
31
|
+
scalar Date
|
|
32
|
+
scalar DateTime
|
|
33
|
+
scalar Time
|
|
34
|
+
|
|
35
|
+
# This directive doesn't do anything on the GraphQL resolution level. It just serves
|
|
36
|
+
# as a way to tell the Prerendering Service whether the GraphQL query needs to be
|
|
37
|
+
# cached or not.
|
|
38
|
+
directive @ps(cache: Boolean) on QUERY
|
|
39
|
+
`];
|
|
40
|
+
const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
|
|
41
|
+
acc[s.name] = s;
|
|
42
|
+
return acc;
|
|
43
|
+
}, {})), {}, {
|
|
44
|
+
JSON: _builtInTypes.JsonScalar,
|
|
45
|
+
Long: _builtInTypes.LongScalar,
|
|
46
|
+
RefInput: _builtInTypes.RefInputScalar,
|
|
47
|
+
Number: _builtInTypes.NumberScalar,
|
|
48
|
+
Any: _builtInTypes.AnyScalar,
|
|
49
|
+
DateTime: _builtInTypes.DateTimeScalar,
|
|
50
|
+
Date: _builtInTypes.DateScalar,
|
|
51
|
+
Time: _builtInTypes.TimeScalar
|
|
52
|
+
})];
|
|
53
|
+
const plugins = context.plugins.byType("graphql-schema");
|
|
54
|
+
|
|
55
|
+
for (const plugin of plugins) {
|
|
56
|
+
/**
|
|
57
|
+
* TODO @ts-refactor
|
|
58
|
+
* Figure out correct types on typeDefs and resolvers
|
|
59
|
+
*/
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
|
|
62
|
+
|
|
63
|
+
resolvers.push(plugin.schema.resolvers);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (0, _schema.makeExecutableSchema)({
|
|
67
|
+
typeDefs,
|
|
68
|
+
resolvers,
|
|
69
|
+
inheritResolversFromInterfaces: true
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.createGraphQLSchema = createGraphQLSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","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","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { 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 { GraphQLScalarType } from \"graphql/type/definition\";\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 more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const 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 ];\n\n const resolvers = [\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 plugins = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AAYO,MAAMA,mBAAmB,GAAIC,OAAD,IAAsB;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAR,CACXC,MADW,CACiB,gBADjB,EAEXC,GAFW,CAEPC,IAAI,IAAIA,IAAI,CAACC,MAFN,CAAhB,CADqD,CAKrD;EACA;;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAA,CAAI;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAR,CAAYE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAA5C,EAA+CC,IAA/C,CAAoD,GAApD,CAAyD;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAlBqB,CAAjB;EAqBA,MAAMC,SAAS,GAAG,6DAEPV,OAAO,CAACW,MAAR,CAAkD,CAACC,GAAD,EAAMC,CAAN,KAAY;IAC7DD,GAAG,CAACC,CAAC,CAACL,IAAH,CAAH,GAAcK,CAAd;IACA,OAAOD,GAAP;EACH,CAHE,EAGA,EAHA,CAFO;IAMVE,IAAI,EAAEC,wBANI;IAOVC,IAAI,EAAEC,wBAPI;IAQVC,QAAQ,EAAEC,4BARA;IASVC,MAAM,EAAEC,0BATE;IAUVC,GAAG,EAAEC,uBAVK;IAWVC,QAAQ,EAAEC,4BAXA;IAYVC,IAAI,EAAEC,wBAZI;IAaVC,IAAI,EAAEC;EAbI,GAAlB;EAiBA,MAAM5B,OAAO,GAAGF,OAAO,CAACE,OAAR,CAAgBC,MAAhB,CAA4C,gBAA5C,CAAhB;;EACA,KAAK,MAAM4B,MAAX,IAAqB7B,OAArB,EAA8B;IAC1B;AACR;AACA;AACA;IACQ;IACAK,QAAQ,CAACyB,IAAT,CAAcD,MAAM,CAACE,MAAP,CAAc1B,QAA5B,EAN0B,CAO1B;;IACAI,SAAS,CAACqB,IAAV,CAAeD,MAAM,CAACE,MAAP,CAActB,SAA7B;EACH;;EAED,OAAO,IAAAuB,4BAAA,EAAqB;IACxB3B,QADwB;IAExBI,SAFwB;IAGxBwB,8BAA8B,EAAE;EAHR,CAArB,CAAP;AAKH,CA9DM"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
+
import { Context } from "@webiny/api/types";
|
|
3
|
+
import { ContextPlugin } from "@webiny/api";
|
|
4
|
+
interface Log {
|
|
5
|
+
method: string;
|
|
6
|
+
args: any;
|
|
7
|
+
}
|
|
8
|
+
interface DebugContext extends Context {
|
|
9
|
+
debug: {
|
|
10
|
+
logs?: Log[];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
|
|
14
|
+
export default _default;
|
package/debugPlugins.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _interceptConsole = require("./interceptConsole");
|
|
9
|
+
|
|
10
|
+
var _api = require("@webiny/api");
|
|
11
|
+
|
|
12
|
+
var _default = () => [new _api.ContextPlugin(async context => {
|
|
13
|
+
if (!context.debug) {
|
|
14
|
+
context.debug = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!context.debug.logs) {
|
|
18
|
+
context.debug.logs = [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
22
|
+
context.debug.logs.push({
|
|
23
|
+
method,
|
|
24
|
+
args
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}), {
|
|
28
|
+
type: "graphql-after-query",
|
|
29
|
+
|
|
30
|
+
apply({
|
|
31
|
+
result,
|
|
32
|
+
context
|
|
33
|
+
}) {
|
|
34
|
+
result["extensions"] = {
|
|
35
|
+
console: [...(context.debug.logs || [])]
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (context.debug.logs) {
|
|
39
|
+
context.debug.logs.length = 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}];
|
|
44
|
+
|
|
45
|
+
exports.default = _default;
|
|
@@ -0,0 +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;;eAYe,MAAM,CACjB,IAAIA,kBAAJ,CAAgC,MAAMC,OAAN,IAAiB;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAb,EAAoB;IAChBD,OAAO,CAACC,KAAR,GAAgB,EAAhB;EACH;;EAED,IAAI,CAACD,OAAO,CAACC,KAAR,CAAcC,IAAnB,EAAyB;IACrBF,OAAO,CAACC,KAAR,CAAcC,IAAd,GAAqB,EAArB;EACH;;EAED,IAAAC,kCAAA,EAAiB,CAACC,MAAD,EAASC,IAAT,KAAkB;IAC9BL,OAAO,CAACC,KAAR,CAAcC,IAAf,CAA8BI,IAA9B,CAAmC;MAAEF,MAAF;MAAUC;IAAV,CAAnC;EACH,CAFD;AAGH,CAZD,CADiB,EAcjB;EACIE,IAAI,EAAE,qBADV;;EAEIC,KAAK,CAAC;IAAEC,MAAF;IAAUT;EAAV,CAAD,EAAsB;IACvBS,MAAM,CAAC,YAAD,CAAN,GAAuB;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAR,CAAcC,IAAd,IAAsB,EAA1B,CAAD;IAAX,CAAvB;;IACA,IAAIF,OAAO,CAACC,KAAR,CAAcC,IAAlB,EAAwB;MACpBF,OAAO,CAACC,KAAR,CAAcC,IAAd,CAAmBS,MAAnB,GAA4B,CAA5B;IACH;EACJ;;AAPL,CAdiB,C"}
|
package/errors.d.ts
ADDED
package/errors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.NotFoundError = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
class NotFoundError extends _error.default {
|
|
13
|
+
constructor(message = "Not found.") {
|
|
14
|
+
super(message, "NOT_FOUND");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.NotFoundError = NotFoundError;
|
package/errors.js.map
ADDED
|
@@ -0,0 +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,MAAMA,aAAN,SAA4BC,cAA5B,CAAwC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAX,EAAyB;IAChC,MAAMA,OAAN,EAAe,WAAf;EACH;;AAH0C"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HandlerGraphQLOptions } from "./types";
|
|
2
|
+
export * from "./errors";
|
|
3
|
+
export * from "./responses";
|
|
4
|
+
export * from "./plugins";
|
|
5
|
+
declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
|
|
6
|
+
export default _default;
|
package/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
var _exportNames = {};
|
|
9
|
+
exports.default = void 0;
|
|
10
|
+
|
|
11
|
+
var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
|
|
12
|
+
|
|
13
|
+
var _errors = require("./errors");
|
|
14
|
+
|
|
15
|
+
Object.keys(_errors).forEach(function (key) {
|
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
18
|
+
if (key in exports && exports[key] === _errors[key]) return;
|
|
19
|
+
Object.defineProperty(exports, key, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _errors[key];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
var _responses = require("./responses");
|
|
28
|
+
|
|
29
|
+
Object.keys(_responses).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
+
if (key in exports && exports[key] === _responses[key]) return;
|
|
33
|
+
Object.defineProperty(exports, key, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _responses[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
var _plugins = require("./plugins");
|
|
42
|
+
|
|
43
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
44
|
+
if (key === "default" || key === "__esModule") return;
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
46
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
47
|
+
Object.defineProperty(exports, key, {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return _plugins[key];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
|
|
56
|
+
|
|
57
|
+
exports.default = _default;
|
package/index.js.map
ADDED
|
@@ -0,0 +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 = {}) => [createGraphQLHandler(options)];\n"],"mappings":";;;;;;;;;;AACA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.interceptConsole = void 0;
|
|
7
|
+
const consoleMethods = ["assert", "debug", "dir", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "table", "warn"];
|
|
8
|
+
const originalMethods = {};
|
|
9
|
+
const skipOriginal = ["table"];
|
|
10
|
+
|
|
11
|
+
const restoreOriginalMethods = () => {
|
|
12
|
+
for (const method of consoleMethods) {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
console[method] = originalMethods[method];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const interceptConsole = callback => {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
if (console["__WEBINY__"] === true) {
|
|
21
|
+
restoreOriginalMethods();
|
|
22
|
+
} // @ts-ignore
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
console["__WEBINY__"] = true;
|
|
26
|
+
|
|
27
|
+
for (const method of consoleMethods) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
originalMethods[method] = console[method]; // @ts-ignore
|
|
30
|
+
|
|
31
|
+
console[method] = (...args) => {
|
|
32
|
+
callback(method, args);
|
|
33
|
+
|
|
34
|
+
if (skipOriginal.includes(method)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
originalMethods[method](...args);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.interceptConsole = interceptConsole;
|
|
@@ -0,0 +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-ignore\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-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\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,QADmB,EAEnB,OAFmB,EAGnB,KAHmB,EAInB,OAJmB,EAKnB,OALmB,EAMnB,gBANmB,EAOnB,UAPmB,EAQnB,MARmB,EASnB,KATmB,EAUnB,OAVmB,EAWnB,MAXmB,CAAvB;AAcA,MAAMC,eAAoC,GAAG,EAA7C;AACA,MAAMC,YAAsB,GAAG,CAAC,OAAD,CAA/B;;AAEA,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAK,OAAO,CAACD,MAAD,CAAP,GAAkBH,eAAe,CAACG,MAAD,CAAjC;EACH;AACJ,CALD;;AAWO,MAAME,gBAAgB,GAAIC,QAAD,IAAwC;EACpE;EACA,IAAIF,OAAO,CAAC,YAAD,CAAP,KAA0B,IAA9B,EAAoC;IAChCF,sBAAsB;EACzB,CAJmE,CAMpE;;;EACAE,OAAO,CAAC,YAAD,CAAP,GAAwB,IAAxB;;EAEA,KAAK,MAAMD,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAC,eAAe,CAACG,MAAD,CAAf,GAA0BC,OAAO,CAACD,MAAD,CAAjC,CAFiC,CAGjC;;IACAC,OAAO,CAACD,MAAD,CAAP,GAAkB,CAAC,GAAGI,IAAJ,KAAa;MAC3BD,QAAQ,CAACH,MAAD,EAASI,IAAT,CAAR;;MACA,IAAIN,YAAY,CAACO,QAAb,CAAsBL,MAAtB,CAAJ,EAAmC;QAC/B;MACH;;MACDH,eAAe,CAACG,MAAD,CAAf,CAAwB,GAAGI,IAA3B;IACH,CAND;EAOH;AACJ,CArBM"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/handler-graphql",
|
|
3
|
+
"version": "0.0.0-ee-vpcs.549378cf03",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
9
|
+
},
|
|
10
|
+
"description": "The Apollo Server as a function.",
|
|
11
|
+
"contributors": [
|
|
12
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
13
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
14
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/runtime": "7.19.0",
|
|
18
|
+
"@graphql-tools/schema": "7.1.5",
|
|
19
|
+
"@webiny/api": "0.0.0-ee-vpcs.549378cf03",
|
|
20
|
+
"@webiny/error": "0.0.0-ee-vpcs.549378cf03",
|
|
21
|
+
"@webiny/handler": "0.0.0-ee-vpcs.549378cf03",
|
|
22
|
+
"@webiny/plugins": "0.0.0-ee-vpcs.549378cf03",
|
|
23
|
+
"boolean": "3.2.0",
|
|
24
|
+
"graphql": "15.8.0",
|
|
25
|
+
"graphql-scalars": "1.12.0",
|
|
26
|
+
"graphql-tag": "2.12.6"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/cli": "^7.19.3",
|
|
30
|
+
"@babel/core": "^7.19.3",
|
|
31
|
+
"@babel/preset-env": "^7.19.4",
|
|
32
|
+
"@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
|
|
33
|
+
"@webiny/handler-aws": "^0.0.0-ee-vpcs.549378cf03",
|
|
34
|
+
"@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
|
|
35
|
+
"jest": "^28.1.0",
|
|
36
|
+
"jest-mock-console": "^1.0.0",
|
|
37
|
+
"rimraf": "^3.0.2",
|
|
38
|
+
"ttypescript": "^1.5.15",
|
|
39
|
+
"typescript": "4.7.4"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"directory": "dist"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "yarn webiny run build",
|
|
47
|
+
"watch": "yarn webiny run watch"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
5
|
+
typeDefs?: Types;
|
|
6
|
+
resolvers?: Resolvers<TContext>;
|
|
7
|
+
}
|
|
8
|
+
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
9
|
+
static readonly type: string;
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
12
|
+
get schema(): GraphQLSchemaDefinition<TContext>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.GraphQLSchemaPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class GraphQLSchemaPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "config", void 0);
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get schema() {
|
|
22
|
+
return {
|
|
23
|
+
typeDefs: this.config.typeDefs || "",
|
|
24
|
+
resolvers: this.config.resolvers
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.GraphQLSchemaPlugin = GraphQLSchemaPlugin;
|
|
31
|
+
(0, _defineProperty2.default)(GraphQLSchemaPlugin, "type", "graphql-schema");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context> extends Plugin {\n public static override readonly type: string = \"graphql-schema\";\n private 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 };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,mBAAN,SAAsDC,eAAtD,CAA6D;EAIhEC,WAAW,CAACC,MAAD,EAA8C;IACrD;IADqD;IAErD,KAAKA,MAAL,GAAcA,MAAd;EACH;;EAES,IAANC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,KAAKF,MAAL,CAAYE,QAAZ,IAAwB,EAD/B;MAEHC,SAAS,EAAE,KAAKH,MAAL,CAAYG;IAFpB,CAAP;EAIH;;AAd+D;;;8BAAvDN,mB,UACsC,gB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GraphQLSchemaPlugin";
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _GraphQLSchemaPlugin = require("./GraphQLSchemaPlugin");
|
|
8
|
+
|
|
9
|
+
Object.keys(_GraphQLSchemaPlugin).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _GraphQLSchemaPlugin[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _GraphQLSchemaPlugin[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
+
import { GraphQLRequestBody } from "./types";
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
declare const _default: (requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult[] | ExecutionResult>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _graphql = require("graphql");
|
|
9
|
+
|
|
10
|
+
const processRequestBody = async (body, schema, context) => {
|
|
11
|
+
const {
|
|
12
|
+
query,
|
|
13
|
+
variables,
|
|
14
|
+
operationName
|
|
15
|
+
} = body;
|
|
16
|
+
context.plugins.byType("graphql-before-query").forEach(pl => pl.apply({
|
|
17
|
+
body,
|
|
18
|
+
schema,
|
|
19
|
+
context
|
|
20
|
+
}));
|
|
21
|
+
const result = await (0, _graphql.graphql)(schema, query, {}, context, variables, operationName);
|
|
22
|
+
context.plugins.byType("graphql-after-query").forEach(pl => {
|
|
23
|
+
pl.apply({
|
|
24
|
+
result,
|
|
25
|
+
body,
|
|
26
|
+
schema,
|
|
27
|
+
context
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var _default = async (requestBody, schema, context) => {
|
|
34
|
+
if (Array.isArray(requestBody) === true) {
|
|
35
|
+
const result = [];
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < requestBody.length; i++) {
|
|
38
|
+
result.push(await processRequestBody(requestBody[i], schema, context));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return await processRequestBody(requestBody, schema, context);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","i","length","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import { ExecutionResult, graphql, GraphQLSchema } from \"graphql\";\nimport { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin, GraphQLRequestBody } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nconst processRequestBody = async (\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n) => {\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(schema, query, {}, context, variables, operationName);\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result;\n};\n\nexport default async (\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult[] | ExecutionResult> => {\n if (Array.isArray(requestBody) === true) {\n const result: ExecutionResult[] = [];\n for (let i = 0; i < (requestBody as GraphQLRequestBody[]).length; i++) {\n result.push(\n await processRequestBody((requestBody as GraphQLRequestBody[])[i], schema, context)\n );\n }\n return result;\n }\n return await processRequestBody(requestBody as GraphQLRequestBody, schema, context);\n};\n"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,kBAAkB,GAAG,OACvBC,IADuB,EAEvBC,MAFuB,EAGvBC,OAHuB,KAItB;EACD,MAAM;IAAEC,KAAF;IAASC,SAAT;IAAoBC;EAApB,IAAsCL,IAA5C;EAEAE,OAAO,CAACI,OAAR,CACKC,MADL,CACsC,sBADtC,EAEKC,OAFL,CAEaC,EAAE,IAAIA,EAAE,CAACC,KAAH,CAAS;IAAEV,IAAF;IAAQC,MAAR;IAAgBC;EAAhB,CAAT,CAFnB;EAIA,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAA,EAAQX,MAAR,EAAgBE,KAAhB,EAAuB,EAAvB,EAA2BD,OAA3B,EAAoCE,SAApC,EAA+CC,aAA/C,CAArB;EAEAH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAAgD,qBAAhD,EAAuEC,OAAvE,CAA+EC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAH,CAAS;MAAEC,MAAF;MAAUX,IAAV;MAAgBC,MAAhB;MAAwBC;IAAxB,CAAT;EACH,CAFD;EAIA,OAAOS,MAAP;AACH,CAlBD;;eAoBe,OACXE,WADW,EAEXZ,MAFW,EAGXC,OAHW,KAIoC;EAC/C,IAAIY,KAAK,CAACC,OAAN,CAAcF,WAAd,MAA+B,IAAnC,EAAyC;IACrC,MAAMF,MAAyB,GAAG,EAAlC;;IACA,KAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAIH,WAAD,CAAsCI,MAA1D,EAAkED,CAAC,EAAnE,EAAuE;MACnEL,MAAM,CAACO,IAAP,CACI,MAAMnB,kBAAkB,CAAEc,WAAD,CAAsCG,CAAtC,CAAD,EAA2Cf,MAA3C,EAAmDC,OAAnD,CAD5B;IAGH;;IACD,OAAOS,MAAP;EACH;;EACD,OAAO,MAAMZ,kBAAkB,CAACc,WAAD,EAAoCZ,MAApC,EAA4CC,OAA5C,CAA/B;AACH,C"}
|
package/responses.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface ErrorResponseParams {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
data?: any;
|
|
5
|
+
stack?: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare class ErrorResponse {
|
|
8
|
+
readonly data: null;
|
|
9
|
+
readonly error: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
data: any;
|
|
13
|
+
stack: string | null;
|
|
14
|
+
};
|
|
15
|
+
constructor(params: ErrorResponseParams);
|
|
16
|
+
}
|
|
17
|
+
export declare class NotFoundResponse extends ErrorResponse {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class ListErrorResponse {
|
|
21
|
+
readonly data: null;
|
|
22
|
+
readonly meta: null;
|
|
23
|
+
readonly error: {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
data: any;
|
|
27
|
+
stack: string | null;
|
|
28
|
+
};
|
|
29
|
+
constructor(params: ErrorResponseParams);
|
|
30
|
+
}
|
|
31
|
+
export declare class Response<T = any> {
|
|
32
|
+
readonly data: T;
|
|
33
|
+
readonly error: null;
|
|
34
|
+
constructor(data: T);
|
|
35
|
+
}
|
|
36
|
+
export declare class ListResponse<T, M> {
|
|
37
|
+
readonly data: Array<T>;
|
|
38
|
+
readonly meta: M;
|
|
39
|
+
readonly error: null;
|
|
40
|
+
constructor(data: Array<T>, meta?: M);
|
|
41
|
+
}
|