@axinom/mosaic-graphql-common 0.26.0-rc.20 → 0.26.0-rc.21
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/dist/postgraphile/enhance-graphql-errors.d.ts +2 -1
- package/dist/postgraphile/enhance-graphql-errors.d.ts.map +1 -1
- package/dist/postgraphile/enhance-graphql-errors.js +13 -3
- package/dist/postgraphile/enhance-graphql-errors.js.map +1 -1
- package/package.json +7 -7
- package/src/postgraphile/enhance-graphql-errors.ts +19 -1
|
@@ -39,10 +39,11 @@ export interface GraphQlOperation {
|
|
|
39
39
|
* @param operationName - The operation name that was executed in case the request contained more than one operation. Found in `req.body.operationName`.
|
|
40
40
|
* @param customizeFields - Override error fields message, exception code, and add extensions fields with your custom values. Extension fields are added to the extensions object and cannot use existing field names.
|
|
41
41
|
* @param log - allows you to log the error with parts of the GraphQL request data
|
|
42
|
+
* @param removeSuggestions - Removes any suggestions in cases where the query is sent with typos.
|
|
42
43
|
*/
|
|
43
44
|
export declare const enhanceGraphqlErrors: (errors: readonly GraphQLError[], operationName?: string, customizeFields?: ((error: GraphQLError, originalError?: Error | null) => {
|
|
44
45
|
message?: string;
|
|
45
46
|
code?: string;
|
|
46
47
|
extensions?: Dict<unknown>;
|
|
47
|
-
} | undefined) | undefined, log?: ((error: GraphQLErrorEnhanced, originalError?: Error | null, operations?: GraphQlOperation[]) => void) | undefined) => GraphQLErrorEnhanced[];
|
|
48
|
+
} | undefined) | undefined, log?: ((error: GraphQLErrorEnhanced, originalError?: Error | null, operations?: GraphQlOperation[]) => void) | undefined, removeSuggestions?: boolean) => GraphQLErrorEnhanced[];
|
|
48
49
|
//# sourceMappingURL=enhance-graphql-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhance-graphql-errors.d.ts","sourceRoot":"","sources":["../../src/postgraphile/enhance-graphql-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAEZ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E/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAuDD;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,WACvB,SAAS,YAAY,EAAE,kBACf,MAAM,6BAEb,YAAY,kBACH,KAAK,GAAG,IAAI,KAE1B;IACE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;CAC5B,GACD,SAAS,8BAEJ,oBAAoB,kBACX,KAAK,GAAG,IAAI,eACf,gBAAgB,EAAE,KAC5B,IAAI,+CAER,oBAAoB,EAgCtB,CAAC"}
|
|
@@ -3,8 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhanceGraphqlErrors = exports.GeneralGraphQlErrorCode = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
exports.GeneralGraphQlErrorCode = 'GENERAL_GRAPHQL_ERROR';
|
|
6
|
-
|
|
6
|
+
function removeSuggestions(error) {
|
|
7
|
+
if (error.message.includes('Did you mean')) {
|
|
8
|
+
error.message =
|
|
9
|
+
'Invalid GraphQL Query. Requested fields do not exist in the GraphQL Schema.';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const basicErrorMapper = (error, shouldRemoveSuggestions, operationName) => {
|
|
7
13
|
var _a;
|
|
14
|
+
if (shouldRemoveSuggestions) {
|
|
15
|
+
removeSuggestions(error);
|
|
16
|
+
}
|
|
8
17
|
return Object.assign(Object.assign({}, error), { message: (_a = error.message) !== null && _a !== void 0 ? _a : 'No error description was provided', extensions: {
|
|
9
18
|
timestamp: new Date().toISOString(),
|
|
10
19
|
operationName,
|
|
@@ -39,11 +48,12 @@ const getGraphQlOperations = (requestBody) => {
|
|
|
39
48
|
* @param operationName - The operation name that was executed in case the request contained more than one operation. Found in `req.body.operationName`.
|
|
40
49
|
* @param customizeFields - Override error fields message, exception code, and add extensions fields with your custom values. Extension fields are added to the extensions object and cannot use existing field names.
|
|
41
50
|
* @param log - allows you to log the error with parts of the GraphQL request data
|
|
51
|
+
* @param removeSuggestions - Removes any suggestions in cases where the query is sent with typos.
|
|
42
52
|
*/
|
|
43
|
-
const enhanceGraphqlErrors = (errors, operationName, customizeFields, log) => {
|
|
53
|
+
const enhanceGraphqlErrors = (errors, operationName, customizeFields, log, removeSuggestions = false) => {
|
|
44
54
|
return errors.map((error) => {
|
|
45
55
|
var _a, _b, _c, _d;
|
|
46
|
-
const enhancedError = basicErrorMapper(error, operationName);
|
|
56
|
+
const enhancedError = basicErrorMapper(error, removeSuggestions, operationName);
|
|
47
57
|
if (customizeFields) {
|
|
48
58
|
const custom = customizeFields(error, error.originalError);
|
|
49
59
|
enhancedError.message = (_a = custom === null || custom === void 0 ? void 0 : custom.message) !== null && _a !== void 0 ? _a : enhancedError.message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhance-graphql-errors.js","sourceRoot":"","sources":["../../src/postgraphile/enhance-graphql-errors.ts"],"names":[],"mappings":";;;AAAA,qCAOiB;AAmBJ,QAAA,uBAAuB,GAAG,uBAAuB,CAAC;AAoB/D,MAAM,gBAAgB,GAAG,CACvB,KAAmB,EACnB,aAAsB,EACA,EAAE;;IACxB,uCACK,KAAK,KACR,OAAO,EAAE,MAAA,KAAK,CAAC,OAAO,mCAAI,mCAAmC,EAC7D,UAAU,EAAE;YACV,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,aAAa;YACb,SAAS,EAAE;gBACT,IAAI,EAAE,+BAAuB;aAC9B;SACF;QACD,uDAAuD;QACvD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACnC,IAAI,EAAE,+BAAuB,EAC7B,OAAO,EAAE,SAAS,IAClB;AACJ,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAC3B,WAAmB,EACa,EAAE;IAClC,IAAI;QACF,MAAM,gBAAgB,GAAG,IAAA,eAAK,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAQ,gBAAgB,CAAC,WAAyC,CAAC,GAAG,CACpE,CAAC,EAAE,EAAE,EAAE;;YAAC,OAAA,CAAC;gBACP,IAAI,EAAE,MAAA,MAAA,EAAE,CAAC,IAAI,0CAAE,KAAK,mCAAI,mBAAmB;gBAC3C,SAAS,EAAE,EAAE,CAAC,SAAS;gBACvB,aAAa,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAC3C,CAAC,SAAS,EAAE,EAAE,CAAE,SAAuB,CAAC,IAAI,CAAC,KAAK,CACnD;aACF,CAAC,CAAA;SAAA,CACH,CAAC;KACH;IAAC,WAAM;QACN,8CAA8C;QAC9C,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"enhance-graphql-errors.js","sourceRoot":"","sources":["../../src/postgraphile/enhance-graphql-errors.ts"],"names":[],"mappings":";;;AAAA,qCAOiB;AAmBJ,QAAA,uBAAuB,GAAG,uBAAuB,CAAC;AAoB/D,SAAS,iBAAiB,CAAC,KAAmB;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;QAC1C,KAAK,CAAC,OAAO;YACX,6EAA6E,CAAC;KACjF;AACH,CAAC;AAED,MAAM,gBAAgB,GAAG,CACvB,KAAmB,EACnB,uBAAgC,EAChC,aAAsB,EACA,EAAE;;IACxB,IAAI,uBAAuB,EAAE;QAC3B,iBAAiB,CAAC,KAAK,CAAC,CAAC;KAC1B;IAED,uCACK,KAAK,KACR,OAAO,EAAE,MAAA,KAAK,CAAC,OAAO,mCAAI,mCAAmC,EAC7D,UAAU,EAAE;YAC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aAAa,CAAC,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,aAAa,CAAC,OAAO,CAAC;YACjE,aAAa,CAAC,UAAU,mCACnB,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,GAClB,aAAa,CAAC,UAAU,CAC5B,CAAC;YACF,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI;gBACrC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;YAE1D,uDAAuD;YACvD,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;YAC7D,aAAa,CAAC,OAAO,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAC;SAC5C;QAED,IAAI,GAAG,EAAE;YACP,MAAM,aAAa,GAAG,KAAK,CAAC,aAA2C,CAAC;YACxE,MAAM,OAAO,GAAG,CAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,IAAI,MAAI,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,0CAAE,IAAI,CAAA,CAAC;YAClE,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;YACxD,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAC;SACtD;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAnDW,QAAA,oBAAoB,wBAmD/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-graphql-common",
|
|
3
|
-
"version": "0.26.0-rc.
|
|
3
|
+
"version": "0.26.0-rc.21",
|
|
4
4
|
"description": "Common GraphQL and PostGraphile related functionality.",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"lint": "eslint . --ext .ts,.tsx,.js --color --cache"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@axinom/mosaic-db-common": "^0.50.0-rc.
|
|
35
|
-
"@axinom/mosaic-message-bus": "^0.43.0-rc.
|
|
34
|
+
"@axinom/mosaic-db-common": "^0.50.0-rc.21",
|
|
35
|
+
"@axinom/mosaic-message-bus": "^0.43.0-rc.21",
|
|
36
36
|
"@axinom/mosaic-message-bus-abstractions": "^0.24.0",
|
|
37
|
-
"@axinom/mosaic-messages": "^0.60.0-rc.
|
|
38
|
-
"@axinom/mosaic-service-common": "^0.62.0-rc.
|
|
39
|
-
"@axinom/mosaic-transactional-inbox-outbox": "^0.22.0-rc.
|
|
37
|
+
"@axinom/mosaic-messages": "^0.60.0-rc.21",
|
|
38
|
+
"@axinom/mosaic-service-common": "^0.62.0-rc.21",
|
|
39
|
+
"@axinom/mosaic-transactional-inbox-outbox": "^0.22.0-rc.21",
|
|
40
40
|
"@graphile/pg-pubsub": "^4.12.3",
|
|
41
41
|
"endent": "^2.1.0",
|
|
42
42
|
"express": "^4.17.1",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"access": "public"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8ba469d9dd1c164774be6e2ebdf17ae8869b159b"
|
|
70
70
|
}
|
|
@@ -44,10 +44,22 @@ export interface GraphQlOperation {
|
|
|
44
44
|
rootEndpoints?: string[];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
function removeSuggestions(error: GraphQLError): void {
|
|
48
|
+
if (error.message.includes('Did you mean')) {
|
|
49
|
+
error.message =
|
|
50
|
+
'Invalid GraphQL Query. Requested fields do not exist in the GraphQL Schema.';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
const basicErrorMapper = (
|
|
48
55
|
error: GraphQLError,
|
|
56
|
+
shouldRemoveSuggestions: boolean,
|
|
49
57
|
operationName?: string,
|
|
50
58
|
): GraphQLErrorEnhanced => {
|
|
59
|
+
if (shouldRemoveSuggestions) {
|
|
60
|
+
removeSuggestions(error);
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
return {
|
|
52
64
|
...error,
|
|
53
65
|
message: error.message ?? 'No error description was provided',
|
|
@@ -92,6 +104,7 @@ const getGraphQlOperations = (
|
|
|
92
104
|
* @param operationName - The operation name that was executed in case the request contained more than one operation. Found in `req.body.operationName`.
|
|
93
105
|
* @param customizeFields - Override error fields message, exception code, and add extensions fields with your custom values. Extension fields are added to the extensions object and cannot use existing field names.
|
|
94
106
|
* @param log - allows you to log the error with parts of the GraphQL request data
|
|
107
|
+
* @param removeSuggestions - Removes any suggestions in cases where the query is sent with typos.
|
|
95
108
|
*/
|
|
96
109
|
export const enhanceGraphqlErrors = (
|
|
97
110
|
errors: readonly GraphQLError[],
|
|
@@ -111,9 +124,14 @@ export const enhanceGraphqlErrors = (
|
|
|
111
124
|
originalError?: Error | null,
|
|
112
125
|
operations?: GraphQlOperation[],
|
|
113
126
|
) => void,
|
|
127
|
+
removeSuggestions = false,
|
|
114
128
|
): GraphQLErrorEnhanced[] => {
|
|
115
129
|
return errors.map((error) => {
|
|
116
|
-
const enhancedError = basicErrorMapper(
|
|
130
|
+
const enhancedError = basicErrorMapper(
|
|
131
|
+
error,
|
|
132
|
+
removeSuggestions,
|
|
133
|
+
operationName,
|
|
134
|
+
);
|
|
117
135
|
|
|
118
136
|
if (customizeFields) {
|
|
119
137
|
const custom = customizeFields(error, error.originalError);
|