@rsdk/graphql 4.0.0-next.9 → 4.0.1-next.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 CHANGED
@@ -3,6 +3,65 @@
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.1-next.0](https://github.com/R-Vision/rsdk/compare/v4.0.0...v4.0.1-next.0) (2023-12-06)
7
+
8
+ ### Bug Fixes
9
+
10
+ * correctly deps versions ([47e6063](https://github.com/R-Vision/rsdk/commit/47e6063aa50b988e4bcf99535d42ff1d0079be5f))
11
+
12
+ ## [4.0.0](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.19...v4.0.0) (2023-12-04)
13
+
14
+ **Note:** Version bump only for package @rsdk/graphql
15
+
16
+ ## [4.0.0-next.19](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.18...v4.0.0-next.19) (2023-12-02)
17
+
18
+ **Note:** Version bump only for package @rsdk/graphql
19
+
20
+ ## [4.0.0-next.18](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.17...v4.0.0-next.18) (2023-12-02)
21
+
22
+ **Note:** Version bump only for package @rsdk/graphql
23
+
24
+ ## [4.0.0-next.17](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.16...v4.0.0-next.17) (2023-12-01)
25
+
26
+ **Note:** Version bump only for package @rsdk/graphql
27
+
28
+ ## [4.0.0-next.16](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.15...v4.0.0-next.16) (2023-11-30)
29
+
30
+ **Note:** Version bump only for package @rsdk/graphql
31
+
32
+ ## [4.0.0-next.15](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.14...v4.0.0-next.15) (2023-11-30)
33
+
34
+ ### Features
35
+
36
+ * added protocol detector ([#166](https://github.com/R-Vision/rsdk/issues/166)) ([f348995](https://github.com/R-Vision/rsdk/commit/f348995f29648c7392b7375c5b2001197d60eb36))
37
+
38
+ ## [4.0.0-next.14](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.13...v4.0.0-next.14) (2023-11-29)
39
+
40
+ ### Features
41
+
42
+ * **core:** PFM-601 Add support send trace id from client to server ([#164](https://github.com/R-Vision/rsdk/issues/164)) ([9e37243](https://github.com/R-Vision/rsdk/commit/9e372437fbb3d7d2b1167b99d07b0ac64cb4013d)), closes [#pfm-601](https://github.com/R-Vision/rsdk/issues/pfm-601) [#pfm-601](https://github.com/R-Vision/rsdk/issues/pfm-601)
43
+
44
+ ## [4.0.0-next.13](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.12...v4.0.0-next.13) (2023-11-29)
45
+
46
+ **Note:** Version bump only for package @rsdk/graphql
47
+
48
+ ## [4.0.0-next.12](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.11...v4.0.0-next.12) (2023-11-29)
49
+
50
+ **Note:** Version bump only for package @rsdk/graphql
51
+
52
+ ## [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)
53
+
54
+ **Note:** Version bump only for package @rsdk/graphql
55
+
56
+ ## [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)
57
+
58
+ ## [3.8.0](https://github.com/R-Vision/rsdk/compare/v3.7.0...v3.8.0) (2023-11-15)
59
+
60
+ ### Features
61
+
62
+ * added configuration for request logging and move to trace level all request
63
+ logging ([#158](https://github.com/R-Vision/rsdk/issues/158)) ([0304672](https://github.com/R-Vision/rsdk/commit/0304672c112fd626642a2d44b0384fbf188e71b4))
64
+
6
65
  ## [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)
7
66
 
8
67
  **Note:** Version bump only for package @rsdk/graphql
@@ -31,7 +90,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
31
90
 
32
91
  ### Bug Fixes
33
92
 
34
- * all yarn peers dependency issues ([e0db9ef](https://github.com/R-Vision/rsdk/commit/e0db9ef1ab8a4df4e1f8ff6f6a9e3728f497549b))
93
+ * all yarn peers dependency
94
+ issues ([e0db9ef](https://github.com/R-Vision/rsdk/commit/e0db9ef1ab8a4df4e1f8ff6f6a9e3728f497549b))
35
95
 
36
96
  ## [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)
37
97
 
@@ -201,7 +261,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
201
261
 
202
262
  ### Bug Fixes
203
263
 
204
- * **deps:** correctly peerDependencies ([349628f](https://github.com/R-Vision/rsdk/commit/349628f10da46a30d6c8b9f9387e010869318212))
264
+ * **deps:** correctly
265
+ peerDependencies ([349628f](https://github.com/R-Vision/rsdk/commit/349628f10da46a30d6c8b9f9387e010869318212))
205
266
 
206
267
  ## [3.0.1-next.0](https://github.com/R-Vision/rsdk/compare/v3.0.0...v3.0.1-next.0) (2023-08-07)
207
268
 
@@ -327,7 +388,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
327
388
 
328
389
  ### Bug Fixes
329
390
 
330
- * remove private dependencies from `peerDependencies` section ([0bce6ff](https://github.com/R-Vision/rsdk/commit/0bce6ffb5b699e2ed1dc9aca77cbdbf085267ff7))
391
+ * remove private dependencies from `peerDependencies`
392
+ section ([0bce6ff](https://github.com/R-Vision/rsdk/commit/0bce6ffb5b699e2ed1dc9aca77cbdbf085267ff7))
331
393
 
332
394
  ## 1.0.11 (2023-05-23)
333
395
 
@@ -337,7 +399,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
337
399
 
338
400
  ### Bug Fixes
339
401
 
340
- * add "access: public" to new packages ([04d5983](https://github.com/R-Vision/rsdk/commit/04d5983cfa3e97c5d8219e07208a0499a8c6bc83))
402
+ * add "access: public" to new
403
+ packages ([04d5983](https://github.com/R-Vision/rsdk/commit/04d5983cfa3e97c5d8219e07208a0499a8c6bc83))
341
404
 
342
405
  ## 1.0.9 (2023-05-21)
343
406
 
@@ -367,7 +430,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
367
430
 
368
431
  ### Bug Fixes
369
432
 
370
- * builtin make not private in npm ([50c83b6](https://github.com/R-Vision/rsdk/commit/50c83b6454f9a89f1e99d3b33a497ce2c029d8c6))
433
+ * builtin make not private in
434
+ npm ([50c83b6](https://github.com/R-Vision/rsdk/commit/50c83b6454f9a89f1e99d3b33a497ce2c029d8c6))
371
435
 
372
436
  ## 1.0.2 (2023-05-10)
373
437
 
@@ -1,4 +1,3 @@
1
- import type { ArgumentsHost } from '@nestjs/common';
2
1
  import type { IErrorsFormatter } from '@rsdk/core';
3
2
  import type { GraphQLFormattedError } from 'graphql';
4
3
  import { GraphQLError } from 'graphql';
@@ -11,7 +10,7 @@ import { GraphQLError } from 'graphql';
11
10
  * в ErrorsFormatter) и нормализация объектов.
12
11
  */
13
12
  export declare class GraphQLErrorsFormatter implements IErrorsFormatter {
13
+ protocol: string;
14
14
  static finalFormat(formattedError: GraphQLFormattedError, _error: unknown): GraphQLFormattedError;
15
- match(host: ArgumentsHost): boolean;
16
15
  format(ex: unknown, verbose?: boolean): GraphQLError;
17
16
  }
@@ -15,6 +15,7 @@ const DEFAULT_MESSAGE = 'Something went wrong';
15
15
  * в ErrorsFormatter) и нормализация объектов.
16
16
  */
17
17
  class GraphQLErrorsFormatter {
18
+ protocol = 'graphql';
18
19
  static finalFormat(formattedError,
19
20
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
21
  _error) {
@@ -34,9 +35,6 @@ class GraphQLErrorsFormatter {
34
35
  }),
35
36
  };
36
37
  }
37
- match(host) {
38
- return host.getType() === 'graphql';
39
- }
40
38
  format(ex, verbose) {
41
39
  if (ex instanceof core_1.PipelineException) {
42
40
  const formatVerbose = verbose || ALWAYS_VERBOSE.has(ex.kind);
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-errors.formatter.js","sourceRoot":"","s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C,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;gBAClE,CAAC,CAAC,eAAe,CAAC;YAEpB,OAAO,IAAI,sBAAY,CAAC,OAAO,EAAE;gBAC/B,UAAU,EAAE;oBACV,IAAI,EAAE,oBAAa,CAAC,IAAI,CAAC;oBAEzB,IAAI;oBACJ;;;uBAGG;oBACH,GAAG,CAAC,OAAO,IAAI;wBACb,KAAK;wBACL,OAAO;qBACR,CAAC;iBACH;aACF,CAAC,CAAC;SACJ;QAED,MAAM,OAAO,GAAG,OAAO;YACrB,CAAC,CAAE,EAAU,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3C,CAAC,CAAC,eAAe,CAAC;QAEpB,OAAO,IAAI,sBAAY,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACF;AA/DD,wDA+DC"}
1
+ {"version":3,"file":"graphql-errors.formatter.js","sourceRoot":"","sources":["../../src/error-handling/graphql-errors.formatter.ts"],"names":[],"mappings":";;;AAAA,yCAAyD;AAEzD,qCAA8D;AAE9D,qCAAuC;AAEvC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,oBAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AACtD,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAa,sBAAsB;IACjC,QAAQ,GAAG,SAAS,CAAC;IAErB,MAAM,CAAC,WAAW,CAChB,cAAqC;IACrC,6DAA6D;IAC7D,MAAe;QAEf,OAAO,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC;QAE5C,OAAO;YACL,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,GAAG,CAAC,cAAc,CAAC,IAAI,IAAI;gBACzB,IAAI,EAAE,cAAc,CAAC,IAAI;aAC1B,CAAC;YAEF,GAAG,CAAC,cAAc,CAAC,SAAS,IAAI;gBAC9B,SAAS,EAAE,cAAc,CAAC,SAAS;aACpC,CAAC;YAEF,UAAU,EAAE,IAAA,mBAAU,GAAE,CAAC,cAAc,CAAC,UAAU,EAAE;gBAClD,mDAAmD;gBACnD,UAAU,EAAE,CAAC,OAAO,CAAC;gBACrB,QAAQ,EAAE,sBAAa;aACxB,CAA4B;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,EAAW,EAAE,OAAiB;QACnC,IAAI,EAAE,YAAY,wBAAiB,EAAE,CAAC;YACpC,MAAM,aAAa,GAAG,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAE7D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;YAE1C,MAAM,OAAO,GAAG,aAAa;gBAC3B,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,wBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;gBAClE,CAAC,CAAC,eAAe,CAAC;YAEpB,OAAO,IAAI,sBAAY,CAAC,OAAO,EAAE;gBAC/B,UAAU,EAAE;oBACV,IAAI,EAAE,oBAAa,CAAC,IAAI,CAAC;oBAEzB,IAAI;oBACJ;;;uBAGG;oBACH,GAAG,CAAC,OAAO,IAAI;wBACb,KAAK;wBACL,OAAO;qBACR,CAAC;iBACH;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,OAAO;YACrB,CAAC,CAAE,EAAU,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3C,CAAC,CAAC,eAAe,CAAC;QAEpB,OAAO,IAAI,sBAAY,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACF;AA7DD,wDA6DC"}
@@ -2,6 +2,6 @@ import type { ArgumentsHost } from '@nestjs/common';
2
2
  import type { IErrorsSender } from '@rsdk/core';
3
3
  import type { Observable } from 'rxjs';
4
4
  export declare class GraphQLErrorsSender implements IErrorsSender {
5
- match(host: ArgumentsHost): boolean;
5
+ protocol: string;
6
6
  send(_host: ArgumentsHost, ex: unknown): Observable<never>;
7
7
  }
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphQLErrorsSender = void 0;
4
4
  class GraphQLErrorsSender {
5
- match(host) {
6
- return host.getType() === 'graphql';
7
- }
5
+ protocol = 'graphql';
8
6
  send(_host, ex) {
9
7
  // Only throwing will provision exception data to apollo-server
10
8
  throw ex;
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-errors.sender.js","sourceRoot":"","sources":["../../src/error-handling/graphql-errors.sender.ts"],"names":[],"mappings":";;;AAIA,MAAa,mBAAmB;IAC9B,KAAK,CAAC,IAAmB;QACvB,OAAO,IAAI,CAAC,OAAO,EAAa,KAAK,SAAS,CAAC;IACjD,CAAC;IAED,IAAI,CAAC,KAAoB,EAAE,EAAW;QACpC,+DAA+D;QAC/D,MAAM,EAAE,CAAC;IACX,CAAC;CACF;AATD,kDASC"}
1
+ {"version":3,"file":"graphql-errors.sender.js","sourceRoot":"","sources":["../../src/error-handling/graphql-errors.sender.ts"],"names":[],"mappings":";;;AAIA,MAAa,mBAAmB;IAC9B,QAAQ,GAAG,SAAS,CAAC;IAErB,IAAI,CAAC,KAAoB,EAAE,EAAW;QACpC,+DAA+D;QAC/D,MAAM,EAAE,CAAC;IACX,CAAC;CACF;AAPD,kDAOC"}
@@ -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,CAAC;YACvC,OAAO,IAAI,CAAC,MAAM,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AC;YAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,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,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
  }
@@ -13,6 +13,7 @@ exports.GraphQLConfig = void 0;
13
13
  const core_1 = require("@rsdk/core");
14
14
  let GraphQLConfig = class GraphQLConfig extends core_1.Config {
15
15
  playground;
16
+ requestLogging;
16
17
  };
17
18
  exports.GraphQLConfig = GraphQLConfig;
18
19
  __decorate([
@@ -22,6 +23,13 @@ __decorate([
22
23
  }),
23
24
  __metadata("design:type", Boolean)
24
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);
25
33
  exports.GraphQLConfig = GraphQLConfig = __decorate([
26
34
  (0, core_1.ConfigSection)({
27
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,GAAnB,MAAM,aAAc,SAAQ,aAAM;IAKvC,UAAU,CAAW;CACtB,CAAA;AANY,sCAAa;AAKxB;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,
@@ -53,7 +64,10 @@ class GraphQLPlugin {
53
64
  }),
54
65
  // Что это?
55
66
  context: ({ req, connection }) => ({
56
- req: req ?? connection.context,
67
+ /**
68
+ * Иногда даже контекста может не быть, поэтому "?"
69
+ */
70
+ req: req ?? connection?.context,
57
71
  }),
58
72
  fieldResolverEnhancers: ['filters'],
59
73
  formatError: error_handling_1.GraphQLErrorsFormatter.finalFormat,
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.plugin.js","sourceRoot":"","sources":["../src/graphql.plugin.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,6CAAgD;AAMhD,2CAA8C;AAE9C,mEAA8D;AAC9D,qDAA+E;AAC/E,qDAAiD;AAEjD,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,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AI,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,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;AAxGD,sCAwGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/graphql",
3
- "version": "4.0.0-next.9",
3
+ "version": "4.0.1-next.0",
4
4
  "description": "Plugin for graphql",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -21,14 +21,15 @@
21
21
  "@nestjs/apollo": "^12.0.0",
22
22
  "@nestjs/common": "^10.0.0",
23
23
  "@nestjs/core": "^10.0.0",
24
- "@nestjs/graphql": "^12.0.0",
25
- "@rsdk/common": "^4.0.0-next.9",
26
- "@rsdk/core": "^4.0.0-next.9",
27
- "@rsdk/logging": "^4.0.0-next.9",
24
+ "@nestjs/graphql": "^12.0.8",
25
+ "@rsdk/common": "^4.0.1-next.0",
26
+ "@rsdk/core": "^4.0.1-next.0",
27
+ "@rsdk/http.server.express": "^4.0.1-next.0",
28
+ "@rsdk/logging": "^4.0.1-next.0",
28
29
  "graphql": "^16.6.0",
29
30
  "graphql-subscriptions": "^2.0.0",
30
31
  "reflect-metadata": "^0.1.13",
31
32
  "rxjs": "^7.8.1"
32
33
  },
33
- "gitHead": "889228ebf4076fafc1c7fce4406b1ea5a3d985ff"
34
+ "gitHead": "772c1ca796c9a5b279274d6a6fb1a356e64aa71f"
34
35
  }
@@ -1,4 +1,3 @@
1
- import type { ArgumentsHost } from '@nestjs/common';
2
1
  import { normalizer, sortErrorKeys } from '@rsdk/common';
3
2
  import type { IErrorsFormatter } from '@rsdk/core';
4
3
  import { ExceptionKind, PipelineException } from '@rsdk/core';
@@ -17,6 +16,8 @@ const DEFAULT_MESSAGE = 'Something went wrong';
17
16
  * в ErrorsFormatter) и нормализация объектов.
18
17
  */
19
18
  export class GraphQLErrorsFormatter implements IErrorsFormatter {
19
+ protocol = 'graphql';
20
+
20
21
  static finalFormat(
21
22
  formattedError: GraphQLFormattedError,
22
23
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -42,10 +43,6 @@ export class GraphQLErrorsFormatter implements IErrorsFormatter {
42
43
  };
43
44
  }
44
45
 
45
- match(host: ArgumentsHost): boolean {
46
- return host.getType<'graphql'>() === 'graphql';
47
- }
48
-
49
46
  format(ex: unknown, verbose?: boolean): GraphQLError {
50
47
  if (ex instanceof PipelineException) {
51
48
  const formatVerbose = verbose || ALWAYS_VERBOSE.has(ex.kind);
@@ -3,9 +3,7 @@ import type { IErrorsSender } from '@rsdk/core';
3
3
  import type { Observable } from 'rxjs';
4
4
 
5
5
  export class GraphQLErrorsSender implements IErrorsSender {
6
- match(host: ArgumentsHost): boolean {
7
- return host.getType<'graphql'>() === 'graphql';
8
- }
6
+ protocol = 'graphql';
9
7
 
10
8
  send(_host: ArgumentsHost, ex: unknown): Observable<never> {
11
9
  // Only throwing will provision exception data to apollo-server
@@ -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,
@@ -99,7 +111,10 @@ export class GraphQLPlugin implements PlatformAppPlugin {
99
111
 
100
112
  // Что это?
101
113
  context: ({ req, connection }: any) => ({
102
- req: req ?? connection.context,
114
+ /**
115
+ * Иногда даже контекста может не быть, поэтому "?"
116
+ */
117
+ req: req ?? connection?.context,
103
118
  }),
104
119
  fieldResolverEnhancers: ['filters'],
105
120
  formatError: GraphQLErrorsFormatter.finalFormat,
package/tsconfig.json CHANGED
@@ -4,6 +4,16 @@
4
4
  "declaration": true,
5
5
  "outDir": "dist"
6
6
  },
7
- "include": ["src/**/*"],
8
- "exclude": ["node_modules", "dist", "test", "**/*.spec.ts", "**/*.test.ts", "**/*.spec.e2e.ts", "**/*.test.e2e.ts"]
7
+ "include": [
8
+ "src/**/*"
9
+ ],
10
+ "exclude": [
11
+ "node_modules",
12
+ "dist",
13
+ "test",
14
+ "**/*.spec.ts",
15
+ "**/*.test.ts",
16
+ "**/*.spec.e2e.ts",
17
+ "**/*.test.e2e.ts"
18
+ ]
9
19
  }