@nest-boot/graphql 7.1.2 → 7.1.3
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/decorators/args-type.decorator.d.ts +1 -1
- package/dist/decorators/args-type.decorator.js +1 -1
- package/dist/graphql.exception-filter.d.ts +23 -0
- package/dist/graphql.exception-filter.js +23 -2
- package/dist/graphql.exception-filter.js.map +1 -1
- package/dist/graphql.module-definition.d.ts +1 -1
- package/dist/graphql.module-definition.js +2 -2
- package/dist/graphql.module-definition.js.map +1 -1
- package/dist/graphql.module.d.ts +21 -1
- package/dist/graphql.module.js +23 -0
- package/dist/graphql.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +19 -10
|
@@ -8,7 +8,7 @@ const add_class_type_metadata_util_1 = require("@nestjs/graphql/dist/utils/add-c
|
|
|
8
8
|
/**
|
|
9
9
|
* Decorator that marks a class as a resolver arguments type.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @public
|
|
12
12
|
*/
|
|
13
13
|
function ArgsType(name) {
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
@@ -2,10 +2,33 @@ 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
|
+
/**
|
|
6
|
+
* Global exception filter for GraphQL and HTTP contexts.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Catches all exceptions and converts them to appropriate GraphQL errors
|
|
10
|
+
* or delegates to the base HTTP exception filter. In production, internal
|
|
11
|
+
* error details are hidden from the response.
|
|
12
|
+
*/
|
|
5
13
|
export declare class GraphQLExceptionFilter extends BaseExceptionFilter implements GqlExceptionFilter {
|
|
6
14
|
private readonly logger;
|
|
15
|
+
/** Whether to include debug information (stack traces, error details) in responses. */
|
|
7
16
|
private readonly debug;
|
|
17
|
+
/** Creates a new GraphQLExceptionFilter instance.
|
|
18
|
+
* @param logger - NestJS logger for logging exceptions
|
|
19
|
+
*/
|
|
8
20
|
constructor(logger: Logger);
|
|
21
|
+
/**
|
|
22
|
+
* Catches and handles exceptions from both GraphQL and HTTP contexts.
|
|
23
|
+
* @param error - The caught exception
|
|
24
|
+
* @param host - The execution context arguments
|
|
25
|
+
* @returns A GraphQL error for GraphQL contexts, or delegates to HTTP handler
|
|
26
|
+
*/
|
|
9
27
|
catch(error: Error, host: ArgumentsHost): GraphQLError | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Transforms a generic error into a GraphQL error.
|
|
30
|
+
* @param error - The original error
|
|
31
|
+
* @returns A standardized GraphQL error with appropriate extensions
|
|
32
|
+
*/
|
|
10
33
|
transform(error: Error): GraphQLError;
|
|
11
34
|
}
|
|
@@ -13,12 +13,30 @@ exports.GraphQLExceptionFilter = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const graphql_1 = require("graphql");
|
|
16
|
+
/**
|
|
17
|
+
* Global exception filter for GraphQL and HTTP contexts.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Catches all exceptions and converts them to appropriate GraphQL errors
|
|
21
|
+
* or delegates to the base HTTP exception filter. In production, internal
|
|
22
|
+
* error details are hidden from the response.
|
|
23
|
+
*/
|
|
16
24
|
let GraphQLExceptionFilter = class GraphQLExceptionFilter extends core_1.BaseExceptionFilter {
|
|
25
|
+
/** Creates a new GraphQLExceptionFilter instance.
|
|
26
|
+
* @param logger - NestJS logger for logging exceptions
|
|
27
|
+
*/
|
|
17
28
|
constructor(logger) {
|
|
18
29
|
super();
|
|
19
30
|
this.logger = logger;
|
|
31
|
+
/** Whether to include debug information (stack traces, error details) in responses. */
|
|
20
32
|
this.debug = process.env.NODE_ENV !== "production";
|
|
21
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Catches and handles exceptions from both GraphQL and HTTP contexts.
|
|
36
|
+
* @param error - The caught exception
|
|
37
|
+
* @param host - The execution context arguments
|
|
38
|
+
* @returns A GraphQL error for GraphQL contexts, or delegates to HTTP handler
|
|
39
|
+
*/
|
|
22
40
|
catch(error, host) {
|
|
23
41
|
if (host.getType() === "graphql") {
|
|
24
42
|
const graphqlError = this.transform(error);
|
|
@@ -30,12 +48,15 @@ let GraphQLExceptionFilter = class GraphQLExceptionFilter extends core_1.BaseExc
|
|
|
30
48
|
super.catch(error, host);
|
|
31
49
|
}
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Transforms a generic error into a GraphQL error.
|
|
53
|
+
* @param error - The original error
|
|
54
|
+
* @returns A standardized GraphQL error with appropriate extensions
|
|
55
|
+
*/
|
|
33
56
|
transform(error) {
|
|
34
|
-
// 如果是 GraphQL 错误,直接返回
|
|
35
57
|
if (error instanceof graphql_1.GraphQLError) {
|
|
36
58
|
return error;
|
|
37
59
|
}
|
|
38
|
-
// 如果是 Http 错误,转换为 Apollo 错误
|
|
39
60
|
if (error instanceof common_1.HttpException) {
|
|
40
61
|
const status = error.getStatus();
|
|
41
62
|
const response = error.getResponse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.exception-filter.js","sourceRoot":"","sources":["../src/graphql.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAmD;AAEnD,qCAAuC;
|
|
1
|
+
{"version":3,"file":"graphql.exception-filter.js","sourceRoot":"","sources":["../src/graphql.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAmD;AAEnD,qCAAuC;AAEvC;;;;;;;GAOG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBACX,SAAQ,0BAAmB;IAM3B;;OAEG;IACH,YAA6B,MAAc;QACzC,KAAK,EAAE,CAAC;QADmB,WAA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B,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,mBAAU,CAAC,MAAM,CAAC;oBACxB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC9C;aACF,CACF,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,sBAAY,CACrB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,EACpD;YACE,UAAU,EAAE;gBACV,IAAI,EAAE,uBAAuB;gBAC7B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9C;SACF,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxEY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,cAAK,GAAE;qCAW+B,eAAM;GAVhC,sBAAsB,CAwElC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const MODULE_OPTIONS_TOKEN: unique symbol;
|
|
2
|
-
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<import("@nestjs/apollo").ApolloDriverConfig, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol
|
|
2
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<import("@nestjs/apollo").ApolloDriverConfig, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: import("@nestjs/apollo").ApolloDriverConfig & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<import("@nestjs/apollo").ApolloDriverConfig, "create"> & Partial<{}>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = void 0;
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = void 0;
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
exports.MODULE_OPTIONS_TOKEN = Symbol("GraphQLModuleOptions");
|
|
7
7
|
_a = new common_1.ConfigurableModuleBuilder()
|
|
8
8
|
.setClassMethodName("forRoot")
|
|
9
|
-
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
|
|
9
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
10
10
|
//# sourceMappingURL=graphql.module-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.module-definition.js","sourceRoot":"","sources":["../src/graphql.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEtD,
|
|
1
|
+
{"version":3,"file":"graphql.module-definition.js","sourceRoot":"","sources":["../src/graphql.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEtD,KAKT,IAAI,kCAAyB,EAAwB;KACtD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACD,iCAAyB,4BAC/C,oBAAY,oBACZ,0BAAkB,yBAGT"}
|
package/dist/graphql.module.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./graphql.module-definition";
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL module powered by Apollo Server.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Wraps `@nestjs/graphql` with Apollo driver, providing schema-first
|
|
8
|
+
* auto-generation, playground support, and global exception filtering.
|
|
9
|
+
*/
|
|
2
10
|
export declare class GraphQLModule extends ConfigurableModuleClass {
|
|
11
|
+
/**
|
|
12
|
+
* Registers the GraphQLModule with the given options.
|
|
13
|
+
* @param options - Apollo Server configuration options
|
|
14
|
+
* @returns Dynamic module configuration
|
|
15
|
+
*/
|
|
16
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
17
|
+
/**
|
|
18
|
+
* Registers the GraphQLModule asynchronously with factory functions.
|
|
19
|
+
* @param options - Async configuration options
|
|
20
|
+
* @returns Dynamic module configuration
|
|
21
|
+
*/
|
|
22
|
+
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
3
23
|
}
|
package/dist/graphql.module.js
CHANGED
|
@@ -14,7 +14,30 @@ const core_1 = require("@nestjs/core");
|
|
|
14
14
|
const graphql_1 = require("@nestjs/graphql");
|
|
15
15
|
const graphql_exception_filter_1 = require("./graphql.exception-filter");
|
|
16
16
|
const graphql_module_definition_1 = require("./graphql.module-definition");
|
|
17
|
+
/**
|
|
18
|
+
* GraphQL module powered by Apollo Server.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Wraps `@nestjs/graphql` with Apollo driver, providing schema-first
|
|
22
|
+
* auto-generation, playground support, and global exception filtering.
|
|
23
|
+
*/
|
|
17
24
|
let GraphQLModule = class GraphQLModule extends graphql_module_definition_1.ConfigurableModuleClass {
|
|
25
|
+
/**
|
|
26
|
+
* Registers the GraphQLModule with the given options.
|
|
27
|
+
* @param options - Apollo Server configuration options
|
|
28
|
+
* @returns Dynamic module configuration
|
|
29
|
+
*/
|
|
30
|
+
static forRoot(options) {
|
|
31
|
+
return super.forRoot(options);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers the GraphQLModule asynchronously with factory functions.
|
|
35
|
+
* @param options - Async configuration options
|
|
36
|
+
* @returns Dynamic module configuration
|
|
37
|
+
*/
|
|
38
|
+
static forRootAsync(options) {
|
|
39
|
+
return super.forRootAsync(options);
|
|
40
|
+
}
|
|
18
41
|
};
|
|
19
42
|
exports.GraphQLModule = GraphQLModule;
|
|
20
43
|
exports.GraphQLModule = GraphQLModule = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.module.js","sourceRoot":"","sources":["../src/graphql.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uEAAsG;AACtG,2CAA8C;AAC9C,
|
|
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,2EAMqC;AAGrC;;;;;;GAMG;AAsCI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,mDAAuB;IACxD;;;;OAIG;IACH,MAAM,CAAU,OAAO,CAAC,OAA4B;QAClD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAU,YAAY,CAC1B,OAAkC;QAElC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AApBY,sCAAa;wBAAb,aAAa;IArCzB,IAAA,eAAM,GA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