@rsdk/graphql 4.0.0-next.1 → 4.0.0-next.11

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 CHANGED
@@ -3,6 +3,52 @@
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
+ ## [4.0.0-next.11](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.10...v4.0.0-next.11) (2023-11-29)
7
+
8
+ **Note:** Version bump only for package @rsdk/graphql
9
+
10
+ ## [4.0.0-next.10](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.9...v4.0.0-next.10) (2023-11-29)
11
+
12
+ ## [3.8.0](https://github.com/R-Vision/rsdk/compare/v3.7.0...v3.8.0) (2023-11-15)
13
+
14
+ ### Features
15
+
16
+ * 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))
17
+
18
+ ## [4.0.0-next.9](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.8...v4.0.0-next.9) (2023-11-29)
19
+
20
+ **Note:** Version bump only for package @rsdk/graphql
21
+
22
+ ## [4.0.0-next.8](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.7...v4.0.0-next.8) (2023-11-29)
23
+
24
+ **Note:** Version bump only for package @rsdk/graphql
25
+
26
+ ## [4.0.0-next.7](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.6...v4.0.0-next.7) (2023-11-21)
27
+
28
+ **Note:** Version bump only for package @rsdk/graphql
29
+
30
+ ## [4.0.0-next.6](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.5...v4.0.0-next.6) (2023-11-21)
31
+
32
+ **Note:** Version bump only for package @rsdk/graphql
33
+
34
+ ## [4.0.0-next.5](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.4...v4.0.0-next.5) (2023-11-13)
35
+
36
+ **Note:** Version bump only for package @rsdk/graphql
37
+
38
+ ## [4.0.0-next.4](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.3...v4.0.0-next.4) (2023-11-12)
39
+
40
+ **Note:** Version bump only for package @rsdk/graphql
41
+
42
+ ## [4.0.0-next.3](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.2...v4.0.0-next.3) (2023-11-12)
43
+
44
+ ### Bug Fixes
45
+
46
+ * all yarn peers dependency issues ([e0db9ef](https://github.com/R-Vision/rsdk/commit/e0db9ef1ab8a4df4e1f8ff6f6a9e3728f497549b))
47
+
48
+ ## [4.0.0-next.2](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.1...v4.0.0-next.2) (2023-11-10)
49
+
50
+ **Note:** Version bump only for package @rsdk/graphql
51
+
6
52
  ## [4.0.0-next.1](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.0...v4.0.0-next.1) (2023-11-10)
7
53
 
8
54
  **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
+ 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 graphql_config_1 = require("./graphql.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, 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,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;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,CAAC,UAAU,EAAE,CAAC;QAE1E,M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WAAA,IAAA,mBAAY,EAAC,wBAAwB,CAAC,CAAA;6CAChB,8BAAa;GAH3B,wBAAwB,CA6DpC"}
@@ -1,4 +1,5 @@
1
1
  import { Config } from '@rsdk/core';
2
2
  export declare class GraphQLConfig extends Config {
3
3
  playground: boolean;
4
+ requestLogging: boolean;
4
5
  }
@@ -11,9 +11,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GraphQLConfig = void 0;
13
13
  const core_1 = require("@rsdk/core");
14
- let GraphQLConfig = exports.GraphQLConfig = class GraphQLConfig extends core_1.Config {
14
+ let GraphQLConfig = class GraphQLConfig extends core_1.Config {
15
15
  playground;
16
+ requestLogging;
16
17
  };
18
+ exports.GraphQLConfig = GraphQLConfig;
17
19
  __decorate([
18
20
  (0, core_1.Property)('GRAPHQL_ENABLE_PLAYGROUND', new core_1.BoolParser(), {
19
21
  defaultValue: false,
@@ -21,6 +23,13 @@ __decorate([
21
23
  }),
22
24
  __metadata("design:type", Boolean)
23
25
  ], GraphQLConfig.prototype, "playground", void 0);
26
+ __decorate([
27
+ (0, core_1.Property)('GRAPHQL_REQUEST_LOGGING', new core_1.BoolParser(), {
28
+ defaultValue: false,
29
+ description: 'Enable trace logging all requests',
30
+ }),
31
+ __metadata("design:type", Boolean)
32
+ ], GraphQLConfig.prototype, "requestLogging", void 0);
24
33
  exports.GraphQLConfig = GraphQLConfig = __decorate([
25
34
  (0, core_1.ConfigSection)({
26
35
  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;CACtB,CAAA;AADC;IAJC,IAAA,eAAQ,EAAC,2BAA2B,EAAE,IAAI,iBAAU,EAAE,EAAE;QACvD,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,8CAA8C;KAC5D,CAAC;;iDACmB;wBALV,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,CAMzB"}
1
+ {"version":3,"file":"graphql.config.js","sourceRoot":"","sources":["../src/graphql.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMoB;AAKb,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,aAAM;IAKvC,UAAU,CAAW;IAMrB,cAAc,CAAW;CAC1B,CAAA;AAZY,sCAAa;AAKxB;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"}
@@ -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(): any[];
22
+ modules(): NestModuleDefinitions;
23
23
  configureMiddleware(consumer: MiddlewareConsumer): void;
24
24
  errorFormatter(): IErrorsFormatter;
25
25
  errorSender(): IErrorsSender;
@@ -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.path || '/graphql';
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.pl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AAE,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": "4.0.0-next.1",
3
+ "version": "4.0.0-next.11",
4
4
  "description": "Plugin for graphql",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -13,17 +13,23 @@
13
13
  "scripts": {
14
14
  "prepublishOnly": "npm run build"
15
15
  },
16
+ "dependencies": {
17
+ "@apollo/server": "^4.9.5",
18
+ "@apollo/utils.logger": "^2.0.0"
19
+ },
16
20
  "peerDependencies": {
17
- "@apollo/utils.logger": "^2.0.0",
18
- "@nestjs/apollo": "^12.0.7",
19
- "@nestjs/common": "^10.1.3",
20
- "@nestjs/graphql": "^12.0.8",
21
- "@rsdk/common": "^3.5.0",
22
- "@rsdk/core": "^4.0.0-next.1",
23
- "@rsdk/logging": "^4.0.0-next.1",
21
+ "@nestjs/apollo": "^12.0.0",
22
+ "@nestjs/common": "^10.0.0",
23
+ "@nestjs/core": "^10.0.0",
24
+ "@nestjs/graphql": "^12.0.0",
25
+ "@rsdk/common": "^4.0.0-next.11",
26
+ "@rsdk/core": "^4.0.0-next.11",
27
+ "@rsdk/http.server.express": "^4.0.0-next.11",
28
+ "@rsdk/logging": "^4.0.0-next.11",
24
29
  "graphql": "^16.6.0",
25
30
  "graphql-subscriptions": "^2.0.0",
31
+ "reflect-metadata": "^0.1.13",
26
32
  "rxjs": "^7.8.1"
27
33
  },
28
- "gitHead": "d21a800ef5dd191b5effec59846c3a44a7ca3d1e"
34
+ "gitHead": "f1339ae22d78b41382b82a0feabacd49be19acd2"
29
35
  }
@@ -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
+ }
@@ -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
  }
@@ -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.path || '/graphql';
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(): any[] {
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,