@rsdk/graphql 3.6.1-next.0 → 3.8.0
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/CHANGELOG.md +10 -0
- package/dist/graphql-logger.interceptor.d.ts +10 -0
- package/dist/graphql-logger.interceptor.js +80 -0
- package/dist/graphql-logger.interceptor.js.map +1 -0
- package/dist/graphql.config.d.ts +1 -0
- package/dist/graphql.config.js +8 -0
- package/dist/graphql.config.js.map +1 -1
- package/dist/graphql.plugin.d.ts +2 -2
- package/dist/graphql.plugin.js +12 -1
- package/dist/graphql.plugin.js.map +1 -1
- package/package.json +4 -3
- package/src/graphql-logger.interceptor.ts +80 -0
- package/src/graphql.config.ts +6 -0
- package/src/graphql.plugin.ts +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.8.0](https://github.com/R-Vision/rsdk/compare/v3.7.0...v3.8.0) (2023-11-15)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added configuration for request logging and move to trace level all request logging ([#158](https://github.com/R-Vision/rsdk/issues/158)) ([0304672](https://github.com/R-Vision/rsdk/commit/0304672c112fd626642a2d44b0384fbf188e71b4))
|
|
11
|
+
|
|
12
|
+
## [3.6.1](https://github.com/R-Vision/rsdk/compare/v3.6.1-next.1...v3.6.1) (2023-10-24)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/graphql
|
|
15
|
+
|
|
6
16
|
## [3.6.1-next.0](https://github.com/R-Vision/rsdk/compare/v3.6.0...v3.6.1-next.0) (2023-10-20)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/graphql
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { ILogger } from '@rsdk/logging';
|
|
3
|
+
import type { Observable } from 'rxjs/internal/Observable';
|
|
4
|
+
import { GraphQLConfig } from './graphql.config';
|
|
5
|
+
export declare class GraphqlLoggerInterceptor implements NestInterceptor {
|
|
6
|
+
private logger;
|
|
7
|
+
private graphQLConfig;
|
|
8
|
+
constructor(logger: ILogger, graphQLConfig: GraphQLConfig);
|
|
9
|
+
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> | Promise<Observable<any>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var GraphqlLoggerInterceptor_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.GraphqlLoggerInterceptor = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
19
|
+
const core_1 = require("@rsdk/core");
|
|
20
|
+
const throwError_1 = require("rxjs/internal/observable/throwError");
|
|
21
|
+
const catchError_1 = require("rxjs/internal/operators/catchError");
|
|
22
|
+
const tap_1 = require("rxjs/internal/operators/tap");
|
|
23
|
+
const graphql_config_1 = require("./graphql.config");
|
|
24
|
+
let GraphqlLoggerInterceptor = exports.GraphqlLoggerInterceptor = GraphqlLoggerInterceptor_1 = class GraphqlLoggerInterceptor {
|
|
25
|
+
logger;
|
|
26
|
+
graphQLConfig;
|
|
27
|
+
constructor(logger, graphQLConfig) {
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
this.graphQLConfig = graphQLConfig;
|
|
30
|
+
}
|
|
31
|
+
intercept(context, next) {
|
|
32
|
+
if (!this.graphQLConfig.requestLogging) {
|
|
33
|
+
return next.handle();
|
|
34
|
+
}
|
|
35
|
+
const isGraphql = context.getType() === 'graphql';
|
|
36
|
+
if (!isGraphql) {
|
|
37
|
+
return next.handle();
|
|
38
|
+
}
|
|
39
|
+
const { req: request } = graphql_1.GqlExecutionContext.create(context).getContext();
|
|
40
|
+
const startDate = Date.now();
|
|
41
|
+
const requestForLog = {
|
|
42
|
+
body: request.body,
|
|
43
|
+
query: request.query,
|
|
44
|
+
params: request.params,
|
|
45
|
+
method: request.method,
|
|
46
|
+
url: request.url,
|
|
47
|
+
headers: request.headers,
|
|
48
|
+
};
|
|
49
|
+
this.logger.trace('received graphql request', {
|
|
50
|
+
request: requestForLog,
|
|
51
|
+
timestamp: startDate,
|
|
52
|
+
});
|
|
53
|
+
return next.handle().pipe((0, catchError_1.catchError)((error) => {
|
|
54
|
+
const endDate = Date.now();
|
|
55
|
+
this.logger.trace('handled graphql request with error', {
|
|
56
|
+
request: requestForLog,
|
|
57
|
+
startDate,
|
|
58
|
+
endDate,
|
|
59
|
+
duration: endDate - startDate,
|
|
60
|
+
error,
|
|
61
|
+
});
|
|
62
|
+
return (0, throwError_1.throwError)(() => error);
|
|
63
|
+
}), (0, tap_1.tap)((response) => {
|
|
64
|
+
const endDate = Date.now();
|
|
65
|
+
this.logger.trace('handled graphql request', {
|
|
66
|
+
request: requestForLog,
|
|
67
|
+
startDate,
|
|
68
|
+
endDate,
|
|
69
|
+
duration: endDate - startDate,
|
|
70
|
+
response,
|
|
71
|
+
});
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.GraphqlLoggerInterceptor = GraphqlLoggerInterceptor = GraphqlLoggerInterceptor_1 = __decorate([
|
|
76
|
+
(0, common_1.Injectable)(),
|
|
77
|
+
__param(0, (0, core_1.InjectLogger)(GraphqlLoggerInterceptor_1)),
|
|
78
|
+
__metadata("design:paramtypes", [Object, graphql_config_1.GraphQLConfig])
|
|
79
|
+
], GraphqlLoggerInterceptor);
|
|
80
|
+
//# sourceMappingURL=graphql-logger.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-logger.interceptor.js","sourceRoot":"","sources":["../src/graphql-logger.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,2CAA4C;AAE5C,6CAAsD;AACtD,qCAA0C;AAG1C,oEAAiE;AACjE,mEAAgE;AAChE,qDAAkD;AAElD,qDAAiD;AAG1C,IAAM,wBAAwB,mEAA9B,MAAM,wBAAwB;IAEe;IACxC;IAFV,YACkD,MAAe,EACvD,aAA4B;QADY,WAAM,GAAN,MAAM,CAAS;QACvD,kBAAa,GAAb,aAAa,CAAe;IACnC,CAAC;IAEJ,SAAS,CACP,OAAyB,EACzB,IAAsB;QAEtB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE;YACtC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;SACtB;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,EAAkB,KAAK,SAAS,CAAC;QAClE,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;SACtB;QAED,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CA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U,GAAE;IAGR,WAAA,IAAA,mBAAY,EAAC,0BAAwB,CAAC,CAAA;6CAChB,8BAAa;GAH3B,wBAAwB,CA6DpC"}
|
package/dist/graphql.config.d.ts
CHANGED
package/dist/graphql.config.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.GraphQLConfig = void 0;
|
|
|
13
13
|
const core_1 = require("@rsdk/core");
|
|
14
14
|
let GraphQLConfig = exports.GraphQLConfig = class GraphQLConfig extends core_1.Config {
|
|
15
15
|
playground;
|
|
16
|
+
requestLogging;
|
|
16
17
|
};
|
|
17
18
|
__decorate([
|
|
18
19
|
(0, core_1.Property)('GRAPHQL_ENABLE_PLAYGROUND', new core_1.BoolParser(), {
|
|
@@ -21,6 +22,13 @@ __decorate([
|
|
|
21
22
|
}),
|
|
22
23
|
__metadata("design:type", Boolean)
|
|
23
24
|
], GraphQLConfig.prototype, "playground", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, core_1.Property)('GRAPHQL_REQUEST_LOGGING', new core_1.BoolParser(), {
|
|
27
|
+
defaultValue: false,
|
|
28
|
+
description: 'Enable trace logging all requests',
|
|
29
|
+
}),
|
|
30
|
+
__metadata("design:type", Boolean)
|
|
31
|
+
], GraphQLConfig.prototype, "requestLogging", void 0);
|
|
24
32
|
exports.GraphQLConfig = GraphQLConfig = __decorate([
|
|
25
33
|
(0, core_1.ConfigSection)({
|
|
26
34
|
tags: [core_1.ConfigTag.infrastructure, core_1.ConfigTag.transport, core_1.ConfigTag.graphql],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.config.js","sourceRoot":"","sources":["../src/graphql.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMoB;AAKb,IAAM,aAAa,2BAAnB,MAAM,aAAc,SAAQ,aAAM;IAKvC,UAAU,CAAW;
|
|
1
|
+
{"version":3,"file":"graphql.config.js","sourceRoot":"","sources":["../src/graphql.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMoB;AAKb,IAAM,aAAa,2BAAnB,MAAM,aAAc,SAAQ,aAAM;IAKvC,UAAU,CAAW;IAMrB,cAAc,CAAW;CAC1B,CAAA;AAPC;IAJC,IAAA,eAAQ,EAAC,2BAA2B,EAAE,IAAI,iBAAU,EAAE,EAAE;QACvD,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,8CAA8C;KAC5D,CAAC;;iDACmB;AAMrB;IAJC,IAAA,eAAQ,EAAC,yBAAyB,EAAE,IAAI,iBAAU,EAAE,EAAE;QACrD,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,mCAAmC;KACjD,CAAC;;qDACuB;wBAXd,aAAa;IAHzB,IAAA,oBAAa,EAAC;QACb,IAAI,EAAE,CAAC,gBAAS,CAAC,cAAc,EAAE,gBAAS,CAAC,SAAS,EAAE,gBAAS,CAAC,OAAO,CAAC;KACzE,CAAC;GACW,aAAa,CAYzB"}
|
package/dist/graphql.plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
-
import type { IErrorsFormatter, IErrorsSender, PlatformAppPlugin } from '@rsdk/core';
|
|
2
|
+
import type { IErrorsFormatter, IErrorsSender, NestModuleDefinitions, PlatformAppPlugin } from '@rsdk/core';
|
|
3
3
|
export type Approach = 'schema-first' | 'code-first';
|
|
4
4
|
export interface GraphQLPluginOptions<T extends Approach> {
|
|
5
5
|
approach: T;
|
|
@@ -19,7 +19,7 @@ export declare class GraphQLPlugin implements PlatformAppPlugin {
|
|
|
19
19
|
private readonly path;
|
|
20
20
|
constructor(options: GraphQLPluginCodeFirstOptions | GraphQLPluginSchemaFirstOptions);
|
|
21
21
|
forTransports(): Readonly<string[]>;
|
|
22
|
-
modules():
|
|
22
|
+
modules(): NestModuleDefinitions;
|
|
23
23
|
configureMiddleware(consumer: MiddlewareConsumer): void;
|
|
24
24
|
errorFormatter(): IErrorsFormatter;
|
|
25
25
|
errorSender(): IErrorsSender;
|
package/dist/graphql.plugin.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphQLPlugin = exports.isCodeFirst = exports.isSchemaFirst = void 0;
|
|
4
4
|
const apollo_1 = require("@nestjs/apollo");
|
|
5
|
+
const core_1 = require("@nestjs/core");
|
|
5
6
|
const graphql_1 = require("@nestjs/graphql");
|
|
6
7
|
const logging_1 = require("@rsdk/logging");
|
|
7
8
|
const apollo_logger_adapter_1 = require("./apollo-logger.adapter");
|
|
8
9
|
const error_handling_1 = require("./error-handling");
|
|
9
10
|
const graphql_config_1 = require("./graphql.config");
|
|
11
|
+
const graphql_logger_interceptor_1 = require("./graphql-logger.interceptor");
|
|
10
12
|
const onConnect = (connectionParams) => {
|
|
11
13
|
const out = connectionParams ?? {};
|
|
12
14
|
const headers = out.headers ?? {};
|
|
@@ -26,7 +28,7 @@ class GraphQLPlugin {
|
|
|
26
28
|
path;
|
|
27
29
|
constructor(options) {
|
|
28
30
|
this.options = options;
|
|
29
|
-
this.path = options
|
|
31
|
+
this.path = options?.path || '/graphql';
|
|
30
32
|
if (!this.path.startsWith('/')) {
|
|
31
33
|
this.path = '/' + this.path;
|
|
32
34
|
}
|
|
@@ -36,6 +38,15 @@ class GraphQLPlugin {
|
|
|
36
38
|
}
|
|
37
39
|
modules() {
|
|
38
40
|
return [
|
|
41
|
+
{
|
|
42
|
+
module: GraphQLPlugin,
|
|
43
|
+
providers: [
|
|
44
|
+
{
|
|
45
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
46
|
+
useClass: graphql_logger_interceptor_1.GraphqlLoggerInterceptor,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
39
50
|
graphql_1.GraphQLModule.forRootAsync({
|
|
40
51
|
inject: [graphql_config_1.GraphQLConfig],
|
|
41
52
|
driver: apollo_1.ApolloDriver,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,6CAAgD;
|
|
1
|
+
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,uCAA+C;AAC/C,6CAAgD;AAOhD,2CAA8C;AAE9C,mEAA8D;AAC9D,qDAA+E;AAC/E,qDAAiD;AACjD,6EAAwE;AAExE,MAAM,SAAS,GAAG,CAAC,gBAAqB,EAAO,EAAE;IAC/C,MAAM,GAAG,GAAG,gBAAgB,IAAI,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;IAElC,4BAA4B;IAC5B,IAAI,gBAAgB,EAAE,aAAa,IAAI,gBAAgB,EAAE,aAAa,EAAE;QACtE,OAAO,CAAC,aAAa;YACnB,gBAAgB,EAAE,aAAa,IAAI,gBAAgB,EAAE,aAAa,CAAC;KACtE;IACD,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;AACtC,CAAC,CAAC;AAmBK,MAAM,aAAa,GAAG,CAC3B,OAAuC,EACK,EAAE,CAC9C,OAAO,CAAC,QAAQ,KAAK,cAAc,CAAC;AAHzB,QAAA,aAAa,iBAGY;AAS/B,MAAM,WAAW,GAAG,CACzB,OAAuC,EACG,EAAE,CAC5C,OAAO,CAAC,QAAQ,KAAK,YAAY,CAAC;AAHvB,QAAA,WAAW,eAGY;AAEpC,MAAa,aAAa;IAIL;IAHF,IAAI,CAAS;IAE9B,YACmB,OAEkB;QAFlB,YAAO,GAAP,OAAO,CAEW;QAEnC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,UAAU,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,IAAI,GAAG,G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;wBAC3B,CAAC,CAAC;4BACE,QAAQ,EAAE,IAAI,CAAC,IAAI;4BACnB,oBAAoB,EAAE,IAAI,CAAC,IAAI;yBAChC;wBACH,CAAC,CAAC,KAAK;oBACT,aAAa,EAAE;wBACb,YAAY,EAAE;4BACZ,SAAS;4BACT,IAAI,EAAE,IAAI,CAAC,IAAI;yBAChB;wBAED,iEAAiE;wBACjE,8DAA8D;wBAC9D,gBAAgB;wBAChB,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI;4BACvB,4BAA4B,EAAE;gCAC5B,SAAS;gCACT,IAAI,EAAE,IAAI,CAAC,IAAI;6BAChB;yBACF,CAAC;qBACH;oBACD,eAAe,EAAE,IAAI;oBACrB,sEAAsE;oBACtE,wCAAwC;iBACzC,CAAC;aACH,CAAC;SACH,CAAC;IACJ,CAAC;IAED,mBAAmB,CAAC,QAA4B;QAC9C,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE;YACtD,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACjD;IACH,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,uCAAsB,EAAE,CAAC;IACtC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,oCAAmB,EAAE,CAAC;IACnC,CAAC;CACF;AArGD,sCAqGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/graphql",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Plugin for graphql",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,13 +17,14 @@
|
|
|
17
17
|
"@apollo/utils.logger": "^2.0.0",
|
|
18
18
|
"@nestjs/apollo": "^12.0.7",
|
|
19
19
|
"@nestjs/common": "^10.1.3",
|
|
20
|
+
"@nestjs/core": "^10.1.3",
|
|
20
21
|
"@nestjs/graphql": "^12.0.8",
|
|
21
22
|
"@rsdk/common": "^3.5.0",
|
|
22
|
-
"@rsdk/core": "^3.6.1
|
|
23
|
+
"@rsdk/core": "^3.6.1",
|
|
23
24
|
"@rsdk/logging": "^3.6.0",
|
|
24
25
|
"graphql": "^16.6.0",
|
|
25
26
|
"graphql-subscriptions": "^2.0.0",
|
|
26
27
|
"rxjs": "^7.8.1"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "2ea4aa82c26a18c1211054ea01652d40af0a82f3"
|
|
29
30
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CallHandler,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
NestInterceptor,
|
|
5
|
+
} from '@nestjs/common';
|
|
6
|
+
import { Injectable } from '@nestjs/common';
|
|
7
|
+
import type { GqlContextType } from '@nestjs/graphql';
|
|
8
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
9
|
+
import { InjectLogger } from '@rsdk/core';
|
|
10
|
+
import { ILogger } from '@rsdk/logging';
|
|
11
|
+
import type { Observable } from 'rxjs/internal/Observable';
|
|
12
|
+
import { throwError } from 'rxjs/internal/observable/throwError';
|
|
13
|
+
import { catchError } from 'rxjs/internal/operators/catchError';
|
|
14
|
+
import { tap } from 'rxjs/internal/operators/tap';
|
|
15
|
+
|
|
16
|
+
import { GraphQLConfig } from './graphql.config';
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class GraphqlLoggerInterceptor implements NestInterceptor {
|
|
20
|
+
constructor(
|
|
21
|
+
@InjectLogger(GraphqlLoggerInterceptor) private logger: ILogger,
|
|
22
|
+
private graphQLConfig: GraphQLConfig,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
intercept(
|
|
26
|
+
context: ExecutionContext,
|
|
27
|
+
next: CallHandler<any>,
|
|
28
|
+
): Observable<any> | Promise<Observable<any>> {
|
|
29
|
+
if (!this.graphQLConfig.requestLogging) {
|
|
30
|
+
return next.handle();
|
|
31
|
+
}
|
|
32
|
+
const isGraphql = context.getType<GqlContextType>() === 'graphql';
|
|
33
|
+
if (!isGraphql) {
|
|
34
|
+
return next.handle();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { req: request } = GqlExecutionContext.create(context).getContext();
|
|
38
|
+
|
|
39
|
+
const startDate = Date.now();
|
|
40
|
+
const requestForLog = {
|
|
41
|
+
body: request.body,
|
|
42
|
+
query: request.query,
|
|
43
|
+
params: request.params,
|
|
44
|
+
method: request.method,
|
|
45
|
+
url: request.url,
|
|
46
|
+
headers: request.headers,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.logger.trace('received graphql request', {
|
|
50
|
+
request: requestForLog,
|
|
51
|
+
timestamp: startDate,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return next.handle().pipe(
|
|
55
|
+
catchError((error) => {
|
|
56
|
+
const endDate = Date.now();
|
|
57
|
+
|
|
58
|
+
this.logger.trace('handled graphql request with error', {
|
|
59
|
+
request: requestForLog,
|
|
60
|
+
startDate,
|
|
61
|
+
endDate,
|
|
62
|
+
duration: endDate - startDate,
|
|
63
|
+
error,
|
|
64
|
+
});
|
|
65
|
+
return throwError(() => error);
|
|
66
|
+
}),
|
|
67
|
+
tap((response) => {
|
|
68
|
+
const endDate = Date.now();
|
|
69
|
+
|
|
70
|
+
this.logger.trace('handled graphql request', {
|
|
71
|
+
request: requestForLog,
|
|
72
|
+
startDate,
|
|
73
|
+
endDate,
|
|
74
|
+
duration: endDate - startDate,
|
|
75
|
+
response,
|
|
76
|
+
});
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/graphql.config.ts
CHANGED
|
@@ -15,4 +15,10 @@ export class GraphQLConfig extends Config {
|
|
|
15
15
|
description: 'Enables GraphQL playground and introspection',
|
|
16
16
|
})
|
|
17
17
|
playground!: boolean;
|
|
18
|
+
|
|
19
|
+
@Property('GRAPHQL_REQUEST_LOGGING', new BoolParser(), {
|
|
20
|
+
defaultValue: false,
|
|
21
|
+
description: 'Enable trace logging all requests',
|
|
22
|
+
})
|
|
23
|
+
requestLogging!: boolean;
|
|
18
24
|
}
|
package/src/graphql.plugin.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ApolloDriverConfig } from '@nestjs/apollo';
|
|
2
2
|
import { ApolloDriver } from '@nestjs/apollo';
|
|
3
3
|
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
4
|
+
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
4
5
|
import { GraphQLModule } from '@nestjs/graphql';
|
|
5
6
|
import type {
|
|
6
7
|
IErrorsFormatter,
|
|
7
8
|
IErrorsSender,
|
|
9
|
+
NestModuleDefinitions,
|
|
8
10
|
PlatformAppPlugin,
|
|
9
11
|
} from '@rsdk/core';
|
|
10
12
|
import { LoggerFactory } from '@rsdk/logging';
|
|
@@ -12,6 +14,7 @@ import { LoggerFactory } from '@rsdk/logging';
|
|
|
12
14
|
import { ApolloLoggerAdapter } from './apollo-logger.adapter';
|
|
13
15
|
import { GraphQLErrorsFormatter, GraphQLErrorsSender } from './error-handling';
|
|
14
16
|
import { GraphQLConfig } from './graphql.config';
|
|
17
|
+
import { GraphqlLoggerInterceptor } from './graphql-logger.interceptor';
|
|
15
18
|
|
|
16
19
|
const onConnect = (connectionParams: any): any => {
|
|
17
20
|
const out = connectionParams ?? {};
|
|
@@ -67,7 +70,7 @@ export class GraphQLPlugin implements PlatformAppPlugin {
|
|
|
67
70
|
| GraphQLPluginCodeFirstOptions
|
|
68
71
|
| GraphQLPluginSchemaFirstOptions,
|
|
69
72
|
) {
|
|
70
|
-
this.path = options
|
|
73
|
+
this.path = options?.path || '/graphql';
|
|
71
74
|
if (!this.path.startsWith('/')) {
|
|
72
75
|
this.path = '/' + this.path;
|
|
73
76
|
}
|
|
@@ -77,8 +80,17 @@ export class GraphQLPlugin implements PlatformAppPlugin {
|
|
|
77
80
|
return ['http'];
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
modules():
|
|
83
|
+
modules(): NestModuleDefinitions {
|
|
81
84
|
return [
|
|
85
|
+
{
|
|
86
|
+
module: GraphQLPlugin,
|
|
87
|
+
providers: [
|
|
88
|
+
{
|
|
89
|
+
provide: APP_INTERCEPTOR,
|
|
90
|
+
useClass: GraphqlLoggerInterceptor,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
82
94
|
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
|
83
95
|
inject: [GraphQLConfig],
|
|
84
96
|
driver: ApolloDriver,
|