@nest-boot/graphql 6.10.1 → 6.10.2
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.
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { type ArgumentsHost } from "@nestjs/common";
|
|
1
|
+
import { type ArgumentsHost, Logger } from "@nestjs/common";
|
|
2
2
|
import { BaseExceptionFilter } from "@nestjs/core";
|
|
3
3
|
import { GqlExceptionFilter } from "@nestjs/graphql";
|
|
4
4
|
import { GraphQLError } from "graphql";
|
|
5
5
|
export declare class GraphQLExceptionFilter extends BaseExceptionFilter implements GqlExceptionFilter {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly debug;
|
|
8
|
+
constructor(logger: Logger);
|
|
6
9
|
catch(error: Error, host: ArgumentsHost): GraphQLError | undefined;
|
|
7
10
|
transform(error: Error): GraphQLError;
|
|
8
11
|
}
|
|
@@ -5,17 +5,30 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.GraphQLExceptionFilter = void 0;
|
|
10
13
|
const common_1 = require("@nestjs/common");
|
|
11
14
|
const core_1 = require("@nestjs/core");
|
|
12
15
|
const graphql_1 = require("graphql");
|
|
13
16
|
let GraphQLExceptionFilter = class GraphQLExceptionFilter extends core_1.BaseExceptionFilter {
|
|
17
|
+
constructor(logger) {
|
|
18
|
+
super();
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
this.debug = process.env.NODE_ENV !== "production";
|
|
21
|
+
}
|
|
14
22
|
catch(error, host) {
|
|
15
23
|
if (host.getType() === "graphql") {
|
|
16
|
-
|
|
24
|
+
const graphqlError = this.transform(error);
|
|
25
|
+
this.logger.error(graphqlError.message, { err: graphqlError });
|
|
26
|
+
return graphqlError;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.logger.error(error.message, { err: error });
|
|
30
|
+
super.catch(error, host);
|
|
17
31
|
}
|
|
18
|
-
super.catch(error, host);
|
|
19
32
|
}
|
|
20
33
|
transform(error) {
|
|
21
34
|
// 如果是 GraphQL 错误,直接返回
|
|
@@ -29,23 +42,26 @@ let GraphQLExceptionFilter = class GraphQLExceptionFilter extends core_1.BaseExc
|
|
|
29
42
|
const message = typeof response === "string"
|
|
30
43
|
? response
|
|
31
44
|
: (response.message ?? response.reason ?? "INTERNAL_SERVER_ERROR");
|
|
32
|
-
return new graphql_1.GraphQLError(
|
|
45
|
+
return new graphql_1.GraphQLError(this.debug || error.getStatus() !== 500
|
|
46
|
+
? message
|
|
47
|
+
: "Internal server error", {
|
|
33
48
|
extensions: {
|
|
34
49
|
code: common_1.HttpStatus[status],
|
|
35
|
-
stack: error.stack,
|
|
50
|
+
...(this.debug ? { stack: error.stack } : {}),
|
|
36
51
|
},
|
|
37
52
|
});
|
|
38
53
|
}
|
|
39
|
-
return new graphql_1.GraphQLError(error.message, {
|
|
54
|
+
return new graphql_1.GraphQLError(this.debug ? error.message : "Internal server error", {
|
|
40
55
|
extensions: {
|
|
41
56
|
code: "INTERNAL_SERVER_ERROR",
|
|
42
|
-
stack: error.stack,
|
|
57
|
+
...(this.debug ? { stack: error.stack } : {}),
|
|
43
58
|
},
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
61
|
};
|
|
47
62
|
exports.GraphQLExceptionFilter = GraphQLExceptionFilter;
|
|
48
63
|
exports.GraphQLExceptionFilter = GraphQLExceptionFilter = __decorate([
|
|
49
|
-
(0, common_1.Catch)()
|
|
64
|
+
(0, common_1.Catch)(),
|
|
65
|
+
__metadata("design:paramtypes", [common_1.Logger])
|
|
50
66
|
], GraphQLExceptionFilter);
|
|
51
67
|
//# sourceMappingURL=graphql.exception-filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.exception-filter.js","sourceRoot":"","sources":["../src/graphql.exception-filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql.exception-filter.js","sourceRoot":"","sources":["../src/graphql.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAmD;AAEnD,qCAAuC;AAGhC,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,0BAAmB;IAK3B,YAA6B,MAAc;QACzC,KAAK,EAAE,CAAC;QADmB,WAAM,GAAN,MAAM,CAAQ;QAF1B,UAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAI/D,CAAC;IAED,KAAK,CAAC,KAAY,EAAE,IAAmB;QACrC,IAAI,IAAI,CAAC,OAAO,EAA2B,KAAK,SAAS,EAAE,CAAC;YAC1D,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;YAC/D,OAAO,YAAY,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;YACjD,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,SAAS,CAAC,KAAY;QACpB,sBAAsB;QACtB,IAAI,KAAK,YAAY,sBAAY,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,C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|
const default_1 = require("@apollo/server/plugin/landingPage/default");
|
|
17
17
|
const apollo_1 = require("@nestjs/apollo");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
+
const common_2 = require("@nestjs/common");
|
|
19
20
|
const core_1 = require("@nestjs/core");
|
|
20
21
|
const graphql_1 = require("@nestjs/graphql");
|
|
21
22
|
const graphql_exception_filter_1 = require("./graphql.exception-filter");
|
|
@@ -72,6 +73,7 @@ exports.GraphQLModule = GraphQLModule = __decorate([
|
|
|
72
73
|
(0, common_1.Global)(),
|
|
73
74
|
(0, common_1.Module)({
|
|
74
75
|
providers: [
|
|
76
|
+
common_2.Logger,
|
|
75
77
|
plugins_1.ComplexityPlugin,
|
|
76
78
|
logging_plugin_1.LoggingPlugin,
|
|
77
79
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.module.js","sourceRoot":"","sources":["../src/graphql.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAAsG;AACtG,2CAA8C;AAC9C,2CAA4E;AAC5E,uCAA0C;AAC1C,6CAAqE;AAErE,yEAAoE;AACpE,2EAKqC;AAErC,uCAA6C;AAC7C,6DAAyD;
|
|
1
|
+
{"version":3,"file":"graphql.module.js","sourceRoot":"","sources":["../src/graphql.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAAsG;AACtG,2CAA8C;AAC9C,2CAA4E;AAC5E,2CAAwC;AACxC,uCAA0C;AAC1C,6CAAqE;AAErE,yEAAoE;AACpE,2EAKqC;AAErC,uCAA6C;AAC7C,6DAAyD;AAelD,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,mDAAuB;IACxD,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAkC;QACpD,OAAO,IAAI,CAAC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