@webiny/handler-graphql 0.0.0-unstable.1e66d121db → 0.0.0-unstable.3386f66516
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +3 -3
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +10 -6
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +3 -3
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/createGraphQLHandler.d.ts +1 -1
- package/createGraphQLHandler.js +50 -11
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.js +13 -8
- package/createGraphQLSchema.js.map +1 -1
- package/package.json +10 -9
- package/processRequestBody.js +6 -5
- package/processRequestBody.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const AnyScalar: GraphQLScalarType;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.AnyScalar = void 0;
|
|
7
7
|
|
|
8
8
|
var _graphql = require("graphql");
|
|
9
9
|
|
|
@@ -11,10 +11,10 @@ const returnValue = value => {
|
|
|
11
11
|
return value;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const AnyScalar = new _graphql.GraphQLScalarType({
|
|
15
15
|
name: "Any",
|
|
16
16
|
description: `A scalar type that represents an ambiguous value.`,
|
|
17
17
|
serialize: returnValue,
|
|
18
18
|
parseValue: returnValue
|
|
19
19
|
});
|
|
20
|
-
exports.
|
|
20
|
+
exports.AnyScalar = AnyScalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["returnValue","value","
|
|
1
|
+
{"version":3,"names":["returnValue","value","AnyScalar","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["AnyScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst returnValue = (value: any): any => {\n return value;\n};\n\nexport const AnyScalar = new GraphQLScalarType({\n name: \"Any\",\n description: `A scalar type that represents an ambiguous value.`,\n serialize: returnValue,\n parseValue: returnValue\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,WAAW,GAAIC,KAAD,IAAqB;EACrC,OAAOA,KAAP;AACH,CAFD;;AAIO,MAAMC,SAAS,GAAG,IAAIC,0BAAJ,CAAsB;EAC3CC,IAAI,EAAE,KADqC;EAE3CC,WAAW,EAAG,mDAF6B;EAG3CC,SAAS,EAAEN,WAHgC;EAI3CO,UAAU,EAAEP;AAJ+B,CAAtB,CAAlB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const NumberScalar: GraphQLScalarType;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.NumberScalar = void 0;
|
|
9
9
|
|
|
10
10
|
var _graphql = require("graphql");
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ const parseValue = value => {
|
|
|
31
31
|
return parseFloat(value);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const NumberScalar = new _graphql.GraphQLScalarType({
|
|
35
35
|
name: "Number",
|
|
36
36
|
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
37
37
|
serialize: value => {
|
|
@@ -50,11 +50,15 @@ const Number = new _graphql.GraphQLScalarType({
|
|
|
50
50
|
},
|
|
51
51
|
parseValue,
|
|
52
52
|
parseLiteral: ast => {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const value = ast.value;
|
|
54
|
+
|
|
55
|
+
if (ast.kind === _language.Kind.INT) {
|
|
56
|
+
return Number(value);
|
|
57
|
+
} else if (ast.kind === _language.Kind.FLOAT) {
|
|
58
|
+
return parseFloat(value);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
throw new Error(`Expected type Number, found {${
|
|
61
|
+
throw new Error(`Expected type Number, found {${value}}`);
|
|
58
62
|
}
|
|
59
63
|
});
|
|
60
|
-
exports.
|
|
64
|
+
exports.NumberScalar = NumberScalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","
|
|
1
|
+
{"version":3,"names":["parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","NumberScalar","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Number","FLOAT","Error"],"sources":["NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).match(/^0x/) !== null) {\n throw new WebinyError(\"Value sent must be a non-hex number.\", \"INVALID_VALUE\", {\n value\n });\n } else if (typeof value === \"number\") {\n return value;\n } else if (value === null || value === undefined) {\n return null;\n } else if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be a number.\", \"INVALID_VALUE\", {\n value\n });\n }\n return parseFloat(value);\n};\n\nexport const NumberScalar = new GraphQLScalarType({\n name: \"Number\",\n description: \"A custom input type to be used with numbers. Supports Int and Float.\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be a number.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n const value = (ast as any).value;\n if (ast.kind === Kind.INT) {\n return Number(value);\n } else if (ast.kind === Kind.FLOAT) {\n return parseFloat(value);\n }\n throw new Error(`Expected type Number, found {${value}}`);\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,UAAU,GAAIC,KAAD,IAAgB;EAC/B,IAAIC,MAAM,CAACD,KAAD,CAAN,CAAcE,KAAd,CAAoB,KAApB,MAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIC,cAAJ,CAAgB,sCAAhB,EAAwD,eAAxD,EAAyE;MAC3EH;IAD2E,CAAzE,CAAN;EAGH,CAJD,MAIO,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAClC,OAAOA,KAAP;EACH,CAFM,MAEA,IAAIA,KAAK,KAAK,IAAV,IAAkBA,KAAK,KAAKI,SAAhC,EAA2C;IAC9C,OAAO,IAAP;EACH,CAFM,MAEA,IAAIC,KAAK,CAACL,KAAD,CAAL,KAAiB,IAArB,EAA2B;IAC9B,MAAM,IAAIG,cAAJ,CAAgB,8BAAhB,EAAgD,eAAhD,EAAiE;MACnEH;IADmE,CAAjE,CAAN;EAGH;;EACD,OAAOM,UAAU,CAACN,KAAD,CAAjB;AACH,CAfD;;AAiBO,MAAMO,YAAY,GAAG,IAAIC,0BAAJ,CAAsB;EAC9CC,IAAI,EAAE,QADwC;EAE9CC,WAAW,EAAE,sEAFiC;EAG9CC,SAAS,EAAGX,KAAD,IAAgB;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAD,CAAjB;IACH,CAFD,CAEE,OAAOY,EAAP,EAAW;MACTC,OAAO,CAACC,GAAR,CAAY;QACRC,OAAO,EAAE,8BADD;QAERC,IAAI,EAAE,eAFE;QAGRC,IAAI,EAAE;UACFjB;QADE;MAHE,CAAZ;MAOA,OAAO,IAAP;IACH;EACJ,CAhB6C;EAiB9CD,UAjB8C;EAkB9CmB,YAAY,EAAEC,GAAG,IAAI;IACjB,MAAMnB,KAAK,GAAImB,GAAD,CAAanB,KAA3B;;IACA,IAAImB,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKC,GAAtB,EAA2B;MACvB,OAAOC,MAAM,CAACvB,KAAD,CAAb;IACH,CAFD,MAEO,IAAImB,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKG,KAAtB,EAA6B;MAChC,OAAOlB,UAAU,CAACN,KAAD,CAAjB;IACH;;IACD,MAAM,IAAIyB,KAAJ,CAAW,gCAA+BzB,KAAM,GAAhD,CAAN;EACH;AA1B6C,CAAtB,CAArB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const RefInputScalar: GraphQLScalarType;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.RefInputScalar = void 0;
|
|
7
7
|
|
|
8
8
|
var _graphql = require("graphql");
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ const isMongoId = value => {
|
|
|
15
15
|
throw new Error("Must be a valid Mongo ID!");
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const RefInputScalar = new _graphql.GraphQLScalarType({
|
|
19
19
|
name: "RefInput",
|
|
20
20
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
21
21
|
serialize: value => {
|
|
@@ -62,4 +62,4 @@ const RefInput = new _graphql.GraphQLScalarType({
|
|
|
62
62
|
throw new Error("Invalid RefInput value!");
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
exports.
|
|
65
|
+
exports.RefInputScalar = RefInputScalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isMongoId","value","test","Error","
|
|
1
|
+
{"version":3,"names":["isMongoId","value","test","Error","RefInputScalar","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields","length"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst isMongoId = (value: any): string => {\n if (/^[0-9a-fA-F]{24}$/.test(value)) {\n return value;\n }\n\n throw new Error(\"Must be a valid Mongo ID!\");\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isMongoId(value);\n }\n\n if (\"id\" in value) {\n return isMongoId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isMongoId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-ignore\n return isMongoId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,SAAS,GAAIC,KAAD,IAAwB;EACtC,IAAI,oBAAoBC,IAApB,CAAyBD,KAAzB,CAAJ,EAAqC;IACjC,OAAOA,KAAP;EACH;;EAED,MAAM,IAAIE,KAAJ,CAAU,2BAAV,CAAN;AACH,CAND;;AAQO,MAAMC,cAAc,GAAG,IAAIC,0BAAJ,CAAsB;EAChDC,IAAI,EAAE,UAD0C;EAEhDC,WAAW,EACP,oGAH4C;EAIhDC,SAAS,EAAEP,KAAK,IAAI;IAChB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,OAAO,OAAOR,KAAP,KAAiB,QAAjB,GAA4BA,KAA5B,GAAoCA,KAAK,CAACQ,EAAjD;EACH,CAV+C;EAWhDC,UAAU,EAAET,KAAK,IAAI;IACjB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,IAAI,OAAOR,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOD,SAAS,CAACC,KAAD,CAAhB;IACH;;IAED,IAAI,QAAQA,KAAZ,EAAmB;MACf,OAAOD,SAAS,CAACC,KAAK,CAACQ,EAAP,CAAhB;IACH;;IAED,MAAM,IAAIN,KAAJ,CAAU,yBAAV,CAAN;EACH,CAzB+C;EA0BhDQ,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,OAAOb,SAAS,CAACY,GAAG,CAACX,KAAL,CAAhB;IACH;;IAED,IAAIW,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,GAAG,CAACG,MAAJ,CAAWC,MAA/B,EAAuCF,CAAC,EAAxC,EAA4C;QACxC,MAAM;UAAER,IAAF;UAAQL;QAAR,IAAkBW,GAAG,CAACG,MAAJ,CAAWD,CAAX,CAAxB;;QACA,IAAIR,IAAI,CAACL,KAAL,KAAe,IAAnB,EAAyB;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAP,CAAhB;QACH;MACJ;IACJ;;IAED,MAAM,IAAIE,KAAJ,CAAU,yBAAV,CAAN;EACH;AA1C+C,CAAtB,CAAvB"}
|
package/createGraphQLHandler.js
CHANGED
|
@@ -9,24 +9,44 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _boolean = require("boolean");
|
|
11
11
|
|
|
12
|
+
var _handler = require("@webiny/handler");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
12
16
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
13
17
|
|
|
14
18
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
15
19
|
|
|
16
20
|
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
17
21
|
|
|
18
|
-
var _handler = require("@webiny/handler");
|
|
19
|
-
|
|
20
22
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
21
23
|
|
|
22
|
-
/**
|
|
23
|
-
* TODO Until we figure out how to better convert incoming body, we will leave it as any.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
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
|
+
*/
|
|
27
29
|
return typeof body === "string" ? JSON.parse(body) : body;
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
const formatErrorPayload = error => {
|
|
33
|
+
if (error instanceof _error.default) {
|
|
34
|
+
return JSON.stringify({
|
|
35
|
+
type: "CoreGraphQLWebinyError",
|
|
36
|
+
message: error.message,
|
|
37
|
+
code: error.code,
|
|
38
|
+
data: error.data
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return JSON.stringify({
|
|
43
|
+
type: "Error",
|
|
44
|
+
name: error.name,
|
|
45
|
+
message: error.message,
|
|
46
|
+
stack: error.stack
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
30
50
|
var _default = (options = {}) => {
|
|
31
51
|
let schema = undefined;
|
|
32
52
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
@@ -39,16 +59,35 @@ var _default = (options = {}) => {
|
|
|
39
59
|
onOptions(path, async (_, reply) => {
|
|
40
60
|
return reply.status(204).headers({
|
|
41
61
|
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
42
|
-
}).send({});
|
|
62
|
+
}).send({}).hijack();
|
|
43
63
|
});
|
|
44
64
|
onPost(path, async (request, reply) => {
|
|
45
65
|
if (!schema) {
|
|
46
|
-
|
|
66
|
+
try {
|
|
67
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
68
|
+
} catch (ex) {
|
|
69
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
70
|
+
}
|
|
47
71
|
}
|
|
48
72
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
let body;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
body = createRequestBody(request.body);
|
|
77
|
+
} catch (ex) {
|
|
78
|
+
console.log(`Error while creating the body request.`);
|
|
79
|
+
console.log(formatErrorPayload(ex));
|
|
80
|
+
throw ex;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
85
|
+
return reply.status(200).send(result);
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
console.log(`Error while processing the body request.`);
|
|
88
|
+
console.log(formatErrorPayload(ex));
|
|
89
|
+
throw ex;
|
|
90
|
+
}
|
|
52
91
|
});
|
|
53
92
|
});
|
|
54
93
|
route.name = "handler.graphql.route.default";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","code","data","name","stack","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","hijack","request","createGraphQLSchema","ex","console","log","result","processRequestBody","debugPlugins"],"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): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\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 .hijack();\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 let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.log(`Error while creating the body request.`);\n console.log(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n } catch (ex) {\n console.log(`Error while processing the body request.`);\n console.log(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wc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CADG,EAEH;IACI9B,IAAI,EAAE;EADV,CAFG,EAKHY,KALG,CAAP;AAOH,C"}
|
package/createGraphQLSchema.js
CHANGED
|
@@ -16,7 +16,9 @@ var _schema = require("@graphql-tools/schema");
|
|
|
16
16
|
var _builtInTypes = require("./builtInTypes");
|
|
17
17
|
|
|
18
18
|
const createGraphQLSchema = context => {
|
|
19
|
-
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
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
|
+
|
|
20
22
|
const typeDefs = [(0, _graphqlTag.default)`
|
|
21
23
|
type Query
|
|
22
24
|
type Mutation
|
|
@@ -29,6 +31,11 @@ const createGraphQLSchema = context => {
|
|
|
29
31
|
scalar Date
|
|
30
32
|
scalar DateTime
|
|
31
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
|
|
32
39
|
`];
|
|
33
40
|
const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
|
|
34
41
|
acc[s.name] = s;
|
|
@@ -36,23 +43,21 @@ const createGraphQLSchema = context => {
|
|
|
36
43
|
}, {})), {}, {
|
|
37
44
|
JSON: _builtInTypes.JsonScalar,
|
|
38
45
|
Long: _builtInTypes.LongScalar,
|
|
39
|
-
RefInput: _builtInTypes.
|
|
40
|
-
Number: _builtInTypes.
|
|
41
|
-
Any: _builtInTypes.
|
|
46
|
+
RefInput: _builtInTypes.RefInputScalar,
|
|
47
|
+
Number: _builtInTypes.NumberScalar,
|
|
48
|
+
Any: _builtInTypes.AnyScalar,
|
|
42
49
|
DateTime: _builtInTypes.DateTimeScalar,
|
|
43
50
|
Date: _builtInTypes.DateScalar,
|
|
44
51
|
Time: _builtInTypes.TimeScalar
|
|
45
52
|
})];
|
|
46
|
-
const
|
|
53
|
+
const plugins = context.plugins.byType("graphql-schema");
|
|
47
54
|
|
|
48
|
-
for (
|
|
49
|
-
const plugin = gqlPlugins[i];
|
|
55
|
+
for (const plugin of plugins) {
|
|
50
56
|
/**
|
|
51
57
|
* TODO @ts-refactor
|
|
52
58
|
* Figure out correct types on typeDefs and resolvers
|
|
53
59
|
*/
|
|
54
60
|
// @ts-ignore
|
|
55
|
-
|
|
56
61
|
typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
|
|
57
62
|
|
|
58
63
|
resolvers.push(plugin.schema.resolvers);
|
|
@@ -1 +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","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","
|
|
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"}
|
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.3386f66516",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "7.19.0",
|
|
18
18
|
"@graphql-tools/schema": "7.1.5",
|
|
19
|
-
"@webiny/api": "0.0.0-unstable.
|
|
20
|
-
"@webiny/error": "0.0.0-unstable.
|
|
21
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
22
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.3386f66516",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.3386f66516",
|
|
21
|
+
"@webiny/handler": "0.0.0-unstable.3386f66516",
|
|
22
|
+
"@webiny/plugins": "0.0.0-unstable.3386f66516",
|
|
23
23
|
"boolean": "3.2.0",
|
|
24
24
|
"graphql": "15.8.0",
|
|
25
25
|
"graphql-scalars": "1.12.0",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"@babel/cli": "^7.19.3",
|
|
30
30
|
"@babel/core": "^7.19.3",
|
|
31
31
|
"@babel/preset-env": "^7.19.4",
|
|
32
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
33
|
-
"@webiny/handler-aws": "^0.0.0-unstable.
|
|
34
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
32
|
+
"@webiny/cli": "^0.0.0-unstable.3386f66516",
|
|
33
|
+
"@webiny/handler-aws": "^0.0.0-unstable.3386f66516",
|
|
34
|
+
"@webiny/project-utils": "^0.0.0-unstable.3386f66516",
|
|
35
35
|
"jest": "^28.1.0",
|
|
36
36
|
"jest-mock-console": "^1.0.0",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
38
|
+
"ttypescript": "^1.5.15",
|
|
38
39
|
"typescript": "4.7.4"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"build": "yarn webiny run build",
|
|
46
47
|
"watch": "yarn webiny run watch"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3386f66516b16fe54e2508243b91dfff1a0156f9"
|
|
49
50
|
}
|
package/processRequestBody.js
CHANGED
|
@@ -31,14 +31,15 @@ const processRequestBody = async (body, schema, context) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
var _default = async (requestBody, schema, context) => {
|
|
34
|
-
if (Array.isArray(requestBody)
|
|
35
|
-
const
|
|
34
|
+
if (Array.isArray(requestBody)) {
|
|
35
|
+
const results = [];
|
|
36
36
|
|
|
37
|
-
for (
|
|
38
|
-
result
|
|
37
|
+
for (const body of requestBody) {
|
|
38
|
+
const result = await processRequestBody(body, schema, context);
|
|
39
|
+
results.push(result);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
return
|
|
42
|
+
return results;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
return await processRequestBody(requestBody, schema, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","
|
|
1
|
+
{"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","results","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)) {\n const results: ExecutionResult[] = [];\n for (const body of requestBody) {\n const result = await processRequestBody(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await processRequestBody(requestBody, 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,CAAJ,EAAgC;IAC5B,MAAMG,OAA0B,GAAG,EAAnC;;IACA,KAAK,MAAMhB,IAAX,IAAmBa,WAAnB,EAAgC;MAC5B,MAAMF,MAAM,GAAG,MAAMZ,kBAAkB,CAACC,IAAD,EAAOC,MAAP,EAAeC,OAAf,CAAvC;MACAc,OAAO,CAACC,IAAR,CAAaN,MAAb;IACH;;IACD,OAAOK,OAAP;EACH;;EACD,OAAO,MAAMjB,kBAAkB,CAACc,WAAD,EAAcZ,MAAd,EAAsBC,OAAtB,CAA/B;AACH,C"}
|