@rsdk/graphql 5.7.0-next.6 → 6.0.0-next.1
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/graphql.log-formatter.d.ts +13 -0
- package/dist/graphql.log-formatter.js +53 -0
- package/dist/graphql.log-formatter.js.map +1 -0
- package/dist/graphql.plugin.d.ts +2 -1
- package/dist/graphql.plugin.js +4 -11
- package/dist/graphql.plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/graphql.log-formatter.ts +60 -0
- package/src/graphql.plugin.ts +6 -11
- package/dist/graphql-logger.interceptor.d.ts +0 -10
- package/dist/graphql-logger.interceptor.js +0 -80
- package/dist/graphql-logger.interceptor.js.map +0 -1
- package/src/graphql-logger.interceptor.ts +0 -80
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import type { LogFormatter } from '@rsdk/core';
|
|
3
|
+
export declare class GraphqlLogFormatter implements LogFormatter {
|
|
4
|
+
readonly protocol = "graphql";
|
|
5
|
+
shouldLog(context: ExecutionContext): boolean;
|
|
6
|
+
getPath(context: ExecutionContext): string;
|
|
7
|
+
/**
|
|
8
|
+
* TODO: Проверить, что не вызывается несколько раз, если несколько
|
|
9
|
+
* резолверов.
|
|
10
|
+
*/
|
|
11
|
+
formatRequest(context: ExecutionContext, includeBody: boolean): Record<string, unknown>;
|
|
12
|
+
formatResponse(context: ExecutionContext, body: unknown | undefined): Record<string, unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GraphqlLogFormatter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
12
|
+
let GraphqlLogFormatter = class GraphqlLogFormatter {
|
|
13
|
+
protocol = 'graphql';
|
|
14
|
+
shouldLog(context) {
|
|
15
|
+
const { prev } = graphql_1.GqlExecutionContext.create(context).getInfo().path;
|
|
16
|
+
/**
|
|
17
|
+
* No logging for nested resolvers
|
|
18
|
+
*/
|
|
19
|
+
return !prev;
|
|
20
|
+
}
|
|
21
|
+
getPath(context) {
|
|
22
|
+
const { key, typename } = graphql_1.GqlExecutionContext.create(context).getInfo().path;
|
|
23
|
+
return `${typename.toLowerCase()} - ${key}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* TODO: Проверить, что не вызывается несколько раз, если несколько
|
|
27
|
+
* резолверов.
|
|
28
|
+
*/
|
|
29
|
+
formatRequest(context, includeBody) {
|
|
30
|
+
const { req } = graphql_1.GqlExecutionContext.create(context).getContext();
|
|
31
|
+
return {
|
|
32
|
+
...(includeBody && { body: req.body }),
|
|
33
|
+
query: req.query,
|
|
34
|
+
params: req.params,
|
|
35
|
+
method: req.method,
|
|
36
|
+
url: req.url,
|
|
37
|
+
headers: req.headers,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
formatResponse(context, body) {
|
|
41
|
+
const { req: { res }, } = graphql_1.GqlExecutionContext.create(context).getContext();
|
|
42
|
+
return {
|
|
43
|
+
headers: res.getHeaders(),
|
|
44
|
+
statusCode: res.statusCode,
|
|
45
|
+
body,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.GraphqlLogFormatter = GraphqlLogFormatter;
|
|
50
|
+
exports.GraphqlLogFormatter = GraphqlLogFormatter = __decorate([
|
|
51
|
+
(0, common_1.Injectable)()
|
|
52
|
+
], GraphqlLogFormatter);
|
|
53
|
+
//# sourceMappingURL=graphql.log-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.log-formatter.js","sourceRoot":"","sources":["../src/graphql.log-formatter.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAA4C;AAC5C,6CAAsD;AAI/C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACrB,QAAQ,GAAG,SAAS,CAAC;IAE9B,SAAS,CAAC,OAAyB;QACjC,MAAM,EAAE,IAAI,EAAE,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QAEpE;;WAEG;QACH,OAAO,CAAC,IAAI,CAAC;IACf,CAAC;IAED,OAAO,CAAC,OAAyB;QAC/B,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GACrB,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QAErD,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,EAAE,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,aAAa,CACX,OAAyB,EACzB,WAAoB;QAEpB,MAAM,EAAE,GAAG,EAAE,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;QAEjE,OAAO;YACL,GAAG,CAAC,WAAW,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;YACtC,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC;IACJ,CAAC;IAED,cAAc,CACZ,OAAyB,EACzB,IAAyB;QAEzB,MAAM,EACJ,GAAG,EAAE,EAAE,GAAG,EAAE,GACb,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;QAErD,OAAO;YACL,OAAO,EAAE,GAAG,CAAC,UAAU,EAAE;YACzB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,IAAI;SACL,CAAC;IACJ,CAAC;CACF,CAAA;AArDY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;GACA,mBAAmB,CAqD/B"}
|
package/dist/graphql.plugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
2
|
import type { AutoSchemaFileValue } from '@nestjs/graphql';
|
|
3
|
-
import type { IErrorsFormatter, IErrorsSender, NestModuleDefinitions, PlatformAppPlugin, WithGenericHeaders } from '@rsdk/core';
|
|
3
|
+
import type { IErrorsFormatter, IErrorsSender, LogFormatter, NestModuleDefinitions, PlatformAppPlugin, WithGenericHeaders } from '@rsdk/core';
|
|
4
4
|
export type Approach = 'schema-first' | 'code-first';
|
|
5
5
|
export interface GraphQLPluginOptions<T extends Approach> {
|
|
6
6
|
approach: T;
|
|
@@ -24,6 +24,7 @@ export declare class GraphQLPlugin implements PlatformAppPlugin {
|
|
|
24
24
|
extractor: WithGenericHeaders;
|
|
25
25
|
}[];
|
|
26
26
|
forTransports(): Readonly<string[]>;
|
|
27
|
+
logFormatter(): LogFormatter;
|
|
27
28
|
modules(): NestModuleDefinitions;
|
|
28
29
|
configureMiddleware(consumer: MiddlewareConsumer): void;
|
|
29
30
|
errorFormatter(): IErrorsFormatter;
|
package/dist/graphql.plugin.js
CHANGED
|
@@ -4,14 +4,13 @@ exports.GraphQLPlugin = exports.isCodeFirst = exports.isSchemaFirst = void 0;
|
|
|
4
4
|
const inlineTrace_1 = require("@apollo/server/plugin/inlineTrace");
|
|
5
5
|
const default_1 = require("@apollo/server/plugin/landingPage/default");
|
|
6
6
|
const apollo_1 = require("@nestjs/apollo");
|
|
7
|
-
const core_1 = require("@nestjs/core");
|
|
8
7
|
const graphql_1 = require("@nestjs/graphql");
|
|
9
8
|
const logging_1 = require("@rsdk/logging");
|
|
10
9
|
const apollo_logger_adapter_1 = require("./apollo-logger.adapter");
|
|
11
10
|
const config_1 = require("./config");
|
|
12
11
|
const error_handling_1 = require("./error-handling");
|
|
13
12
|
const gql_headers_1 = require("./gql.headers");
|
|
14
|
-
const
|
|
13
|
+
const graphql_log_formatter_1 = require("./graphql.log-formatter");
|
|
15
14
|
const onConnect = (connectionParams) => {
|
|
16
15
|
const out = connectionParams ?? {};
|
|
17
16
|
const headers = out.headers ?? {};
|
|
@@ -49,17 +48,11 @@ class GraphQLPlugin {
|
|
|
49
48
|
forTransports() {
|
|
50
49
|
return ['http'];
|
|
51
50
|
}
|
|
51
|
+
logFormatter() {
|
|
52
|
+
return new graphql_log_formatter_1.GraphqlLogFormatter();
|
|
53
|
+
}
|
|
52
54
|
modules() {
|
|
53
55
|
return [
|
|
54
|
-
{
|
|
55
|
-
module: GraphQLPlugin,
|
|
56
|
-
providers: [
|
|
57
|
-
{
|
|
58
|
-
provide: core_1.APP_INTERCEPTOR,
|
|
59
|
-
useClass: graphql_logger_interceptor_1.GraphqlLoggerInterceptor,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
56
|
graphql_1.GraphQLModule.forRootAsync({
|
|
64
57
|
inject: [config_1.GraphqlConfig],
|
|
65
58
|
driver: apollo_1.ApolloDriver,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AAAA,mEAAkF;AAClF,uEAAsG;AAEtG,2CAA8C;
|
|
1
|
+
{"version":3,"file":"graphql.plugin.js","s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I,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YACvD,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,uCAAsB,EAAE,CAAC;IACtC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,oCAAmB,EAAE,CAAC;IACnC,CAAC;CACF;AA3ID,sCA2IC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/graphql",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.1",
|
|
4
4
|
"description": "Plugin for graphql",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@nestjs/apollo": "^12.0.0",
|
|
19
19
|
"@nestjs/common": "^10.0.0",
|
|
20
20
|
"@nestjs/core": "^10.0.0",
|
|
21
|
-
"@nestjs/graphql": "^12.
|
|
21
|
+
"@nestjs/graphql": "^12.0.8",
|
|
22
22
|
"@rsdk/common": "*",
|
|
23
23
|
"@rsdk/core": "*",
|
|
24
24
|
"@rsdk/http.server": "*",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"graphql": "^16.6.0",
|
|
28
28
|
"graphql-subscriptions": "^2.0.0",
|
|
29
29
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
30
|
-
"rxjs": "^7.1
|
|
30
|
+
"rxjs": "^7.8.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "3114a76df17cf98d6f3cbb8a931599a883af6783"
|
|
33
33
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
4
|
+
import type { LogFormatter } from '@rsdk/core';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class GraphqlLogFormatter implements LogFormatter {
|
|
8
|
+
readonly protocol = 'graphql';
|
|
9
|
+
|
|
10
|
+
shouldLog(context: ExecutionContext): boolean {
|
|
11
|
+
const { prev } = GqlExecutionContext.create(context).getInfo().path;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* No logging for nested resolvers
|
|
15
|
+
*/
|
|
16
|
+
return !prev;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getPath(context: ExecutionContext): string {
|
|
20
|
+
const { key, typename } =
|
|
21
|
+
GqlExecutionContext.create(context).getInfo().path;
|
|
22
|
+
|
|
23
|
+
return `${typename.toLowerCase()} - ${key}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* TODO: Проверить, что не вызывается несколько раз, если несколько
|
|
28
|
+
* резолверов.
|
|
29
|
+
*/
|
|
30
|
+
formatRequest(
|
|
31
|
+
context: ExecutionContext,
|
|
32
|
+
includeBody: boolean,
|
|
33
|
+
): Record<string, unknown> {
|
|
34
|
+
const { req } = GqlExecutionContext.create(context).getContext();
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...(includeBody && { body: req.body }),
|
|
38
|
+
query: req.query,
|
|
39
|
+
params: req.params,
|
|
40
|
+
method: req.method,
|
|
41
|
+
url: req.url,
|
|
42
|
+
headers: req.headers,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
formatResponse(
|
|
47
|
+
context: ExecutionContext,
|
|
48
|
+
body: unknown | undefined,
|
|
49
|
+
): Record<string, unknown> {
|
|
50
|
+
const {
|
|
51
|
+
req: { res },
|
|
52
|
+
} = GqlExecutionContext.create(context).getContext();
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
headers: res.getHeaders(),
|
|
56
|
+
statusCode: res.statusCode,
|
|
57
|
+
body,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/graphql.plugin.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin
|
|
|
3
3
|
import type { ApolloDriverConfig } from '@nestjs/apollo';
|
|
4
4
|
import { ApolloDriver } from '@nestjs/apollo';
|
|
5
5
|
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
6
|
-
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
7
6
|
import type { AutoSchemaFileValue } from '@nestjs/graphql';
|
|
8
7
|
import { GraphQLModule } from '@nestjs/graphql';
|
|
9
8
|
import type {
|
|
10
9
|
IErrorsFormatter,
|
|
11
10
|
IErrorsSender,
|
|
11
|
+
LogFormatter,
|
|
12
12
|
NestModuleDefinitions,
|
|
13
13
|
PlatformAppPlugin,
|
|
14
14
|
WithGenericHeaders,
|
|
@@ -19,7 +19,7 @@ import { ApolloLoggerAdapter } from './apollo-logger.adapter';
|
|
|
19
19
|
import { GraphqlConfig, Playground } from './config';
|
|
20
20
|
import { GraphQLErrorsFormatter, GraphQLErrorsSender } from './error-handling';
|
|
21
21
|
import { GqlHeaders } from './gql.headers';
|
|
22
|
-
import {
|
|
22
|
+
import { GraphqlLogFormatter } from './graphql.log-formatter';
|
|
23
23
|
|
|
24
24
|
const onConnect = (connectionParams: any): any => {
|
|
25
25
|
const out = connectionParams ?? {};
|
|
@@ -99,17 +99,12 @@ export class GraphQLPlugin implements PlatformAppPlugin {
|
|
|
99
99
|
return ['http'];
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
logFormatter(): LogFormatter {
|
|
103
|
+
return new GraphqlLogFormatter();
|
|
104
|
+
}
|
|
105
|
+
|
|
102
106
|
modules(): NestModuleDefinitions {
|
|
103
107
|
return [
|
|
104
|
-
{
|
|
105
|
-
module: GraphQLPlugin,
|
|
106
|
-
providers: [
|
|
107
|
-
{
|
|
108
|
-
provide: APP_INTERCEPTOR,
|
|
109
|
-
useClass: GraphqlLoggerInterceptor,
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
108
|
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
|
114
109
|
inject: [GraphqlConfig],
|
|
115
110
|
driver: ApolloDriver,
|
|
@@ -1,10 +0,0 @@
|
|
|
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 './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
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.GraphqlLoggerInterceptor = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const graphql_1 = require("@nestjs/graphql");
|
|
18
|
-
const core_1 = require("@rsdk/core");
|
|
19
|
-
const throwError_1 = require("rxjs/internal/observable/throwError");
|
|
20
|
-
const catchError_1 = require("rxjs/internal/operators/catchError");
|
|
21
|
-
const tap_1 = require("rxjs/internal/operators/tap");
|
|
22
|
-
const config_1 = require("./config");
|
|
23
|
-
let GraphqlLoggerInterceptor = class GraphqlLoggerInterceptor {
|
|
24
|
-
logger;
|
|
25
|
-
graphQLConfig;
|
|
26
|
-
constructor(logger, graphQLConfig) {
|
|
27
|
-
this.logger = logger;
|
|
28
|
-
this.graphQLConfig = graphQLConfig;
|
|
29
|
-
}
|
|
30
|
-
intercept(context, next) {
|
|
31
|
-
if (!this.graphQLConfig.requestLogging) {
|
|
32
|
-
return next.handle();
|
|
33
|
-
}
|
|
34
|
-
const isGraphql = context.getType() === 'graphql';
|
|
35
|
-
if (!isGraphql) {
|
|
36
|
-
return next.handle();
|
|
37
|
-
}
|
|
38
|
-
const { req: request } = graphql_1.GqlExecutionContext.create(context).getContext();
|
|
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
|
-
this.logger.trace('received graphql request', {
|
|
49
|
-
request: requestForLog,
|
|
50
|
-
timestamp: startDate,
|
|
51
|
-
});
|
|
52
|
-
return next.handle().pipe((0, catchError_1.catchError)((error) => {
|
|
53
|
-
const endDate = Date.now();
|
|
54
|
-
this.logger.trace('handled graphql request with error', {
|
|
55
|
-
request: requestForLog,
|
|
56
|
-
startDate,
|
|
57
|
-
endDate,
|
|
58
|
-
duration: endDate - startDate,
|
|
59
|
-
error,
|
|
60
|
-
});
|
|
61
|
-
return (0, throwError_1.throwError)(() => error);
|
|
62
|
-
}), (0, tap_1.tap)((response) => {
|
|
63
|
-
const endDate = Date.now();
|
|
64
|
-
this.logger.trace('handled graphql request', {
|
|
65
|
-
request: requestForLog,
|
|
66
|
-
startDate,
|
|
67
|
-
endDate,
|
|
68
|
-
duration: endDate - startDate,
|
|
69
|
-
response,
|
|
70
|
-
});
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
exports.GraphqlLoggerInterceptor = GraphqlLoggerInterceptor;
|
|
75
|
-
exports.GraphqlLoggerInterceptor = GraphqlLoggerInterceptor = __decorate([
|
|
76
|
-
(0, common_1.Injectable)(),
|
|
77
|
-
__param(0, (0, core_1.InjectLogger)(GraphqlLoggerInterceptor)),
|
|
78
|
-
__metadata("design:paramtypes", [Object, config_1.GraphqlConfig])
|
|
79
|
-
], GraphqlLoggerInterceptor);
|
|
80
|
-
//# sourceMappingURL=graphql-logger.interceptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,qCAAyC;AAGlC,IAAM,wBAAwB,GAA9B,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,CAAC;YACvC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,SAAS,GAAG,OAAO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yB,EAAE;gBAC3C,OAAO,EAAE,aAAa;gBACtB,SAAS;gBACT,OAAO;gBACP,QAAQ,EAAE,OAAO,GAAG,SAAS;gBAC7B,QAAQ;aACT,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AA7DY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,mBAAY,EAAC,wBAAwB,CAAC,CAAA;6CAChB,sBAAa;GAH3B,wBAAwB,CA6DpC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
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 './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
|
-
}
|