@nest-boot/graphql 6.0.0-alpha.2 → 6.0.0-beta.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.
Files changed (69) hide show
  1. package/dist/graphql.exception-filter.d.ts +5 -3
  2. package/dist/graphql.exception-filter.js +4 -2
  3. package/dist/graphql.exception-filter.js.map +1 -1
  4. package/dist/graphql.module.d.ts +3 -0
  5. package/dist/graphql.module.js +27 -5
  6. package/dist/graphql.module.js.map +1 -1
  7. package/dist/index.d.ts +0 -6
  8. package/dist/index.js +0 -6
  9. package/dist/index.js.map +1 -1
  10. package/dist/interfaces/cost-response.interface.d.ts +10 -0
  11. package/dist/interfaces/{connection.interface.js → cost-response.interface.js} +1 -1
  12. package/dist/interfaces/cost-response.interface.js.map +1 -0
  13. package/dist/interfaces/graphql-module-options.interface.d.ts +8 -11
  14. package/dist/interfaces/index.d.ts +1 -4
  15. package/dist/interfaces/index.js +1 -4
  16. package/dist/interfaces/index.js.map +1 -1
  17. package/dist/plugins/complexity.plugin.d.ts +9 -8
  18. package/dist/plugins/complexity.plugin.js +94 -62
  19. package/dist/plugins/complexity.plugin.js.map +1 -1
  20. package/dist/plugins/logging.plugin.d.ts +7 -0
  21. package/dist/plugins/logging.plugin.js +48 -0
  22. package/dist/plugins/logging.plugin.js.map +1 -0
  23. package/dist/tsconfig.build.tsbuildinfo +1 -0
  24. package/package.json +22 -31
  25. package/dist/connection.builder.d.ts +0 -24
  26. package/dist/connection.builder.js +0 -122
  27. package/dist/connection.builder.js.map +0 -1
  28. package/dist/connection.service.d.ts +0 -10
  29. package/dist/connection.service.js +0 -147
  30. package/dist/connection.service.js.map +0 -1
  31. package/dist/dtos/index.d.ts +0 -1
  32. package/dist/dtos/index.js +0 -18
  33. package/dist/dtos/index.js.map +0 -1
  34. package/dist/dtos/page-info.object.d.ts +0 -6
  35. package/dist/dtos/page-info.object.js +0 -36
  36. package/dist/dtos/page-info.object.js.map +0 -1
  37. package/dist/entity.data-loader.d.ts +0 -7
  38. package/dist/entity.data-loader.js +0 -18
  39. package/dist/entity.data-loader.js.map +0 -1
  40. package/dist/enums/index.d.ts +0 -2
  41. package/dist/enums/index.js +0 -19
  42. package/dist/enums/index.js.map +0 -1
  43. package/dist/enums/order-direction.enum.d.ts +0 -4
  44. package/dist/enums/order-direction.enum.js +0 -11
  45. package/dist/enums/order-direction.enum.js.map +0 -1
  46. package/dist/enums/paging-type.enum.d.ts +0 -4
  47. package/dist/enums/paging-type.enum.js +0 -9
  48. package/dist/enums/paging-type.enum.js.map +0 -1
  49. package/dist/interfaces/connection-args.interface.d.ts +0 -9
  50. package/dist/interfaces/connection-args.interface.js +0 -3
  51. package/dist/interfaces/connection-args.interface.js.map +0 -1
  52. package/dist/interfaces/connection.interface.d.ts +0 -9
  53. package/dist/interfaces/connection.interface.js.map +0 -1
  54. package/dist/interfaces/order-field.type.d.ts +0 -8
  55. package/dist/interfaces/order-field.type.js +0 -3
  56. package/dist/interfaces/order-field.type.js.map +0 -1
  57. package/dist/interfaces/order.interface.d.ts +0 -6
  58. package/dist/interfaces/order.interface.js +0 -3
  59. package/dist/interfaces/order.interface.js.map +0 -1
  60. package/dist/tsconfig.tsbuildinfo +0 -1
  61. package/dist/utils/cursor.d.ts +0 -6
  62. package/dist/utils/cursor.js +0 -30
  63. package/dist/utils/cursor.js.map +0 -1
  64. package/dist/utils/get-paging-type.d.ts +0 -3
  65. package/dist/utils/get-paging-type.js +0 -21
  66. package/dist/utils/get-paging-type.js.map +0 -1
  67. package/dist/utils/index.d.ts +0 -2
  68. package/dist/utils/index.js +0 -19
  69. package/dist/utils/index.js.map +0 -1
@@ -1,6 +1,8 @@
1
- import { type ArgumentsHost, type ExceptionFilter } from "@nestjs/common";
1
+ import { type ArgumentsHost } from "@nestjs/common";
2
+ import { BaseExceptionFilter } from "@nestjs/core";
3
+ import { GqlExceptionFilter } from "@nestjs/graphql";
2
4
  import { GraphQLError } from "graphql";
3
- export declare class GraphQLExceptionFilter implements ExceptionFilter {
4
- catch(error: Error, host: ArgumentsHost): void;
5
+ export declare class GraphQLExceptionFilter extends BaseExceptionFilter implements GqlExceptionFilter {
6
+ catch(error: Error, host: ArgumentsHost): GraphQLError | undefined;
5
7
  transform(error: Error): GraphQLError;
6
8
  }
@@ -8,12 +8,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.GraphQLExceptionFilter = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
+ const core_1 = require("@nestjs/core");
11
12
  const graphql_1 = require("graphql");
12
- let GraphQLExceptionFilter = class GraphQLExceptionFilter {
13
+ let GraphQLExceptionFilter = class GraphQLExceptionFilter extends core_1.BaseExceptionFilter {
13
14
  catch(error, host) {
14
15
  if (host.getType() === "graphql") {
15
- throw this.transform(error);
16
+ return this.transform(error);
16
17
  }
18
+ super.catch(error, host);
17
19
  }
18
20
  transform(error) {
19
21
  // 如果是 GraphQL 错误,直接返回
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.exception-filter.js","sourceRoot":"","sources":["../src/graphql.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAOwB;AACxB,qCAAuC;AAGhC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,KAAK,CAAC,KAAY,EAAE,IAAmB;QACrC,IAAI,IAAI,CAAC,OAAO,EAA2B,KAAK,SAAS,EAAE;YACzD,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC7B;IACH,CAAC;IAED,SAAS,CAAC,KAAY;QACpB,sBAAsB;QACtB,IAAI,KAAK,YAAY,sBAAY,EAAE;YACjC,OAAO,KAAK,CAAC;SACd;QAED,4BAA4B;QAC5B,IAAI,KAAK,YAAY,sBAAa,EAAE;YAClC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAQ,KAAK,CAAC,WAAW,EAAE,CAAC;Y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AC,SAAS,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAQ,KAAK,CAAC,WAAW,EAAE,CAAC;YAC1C,MAAM,OAAO,GACX,OAAO,QAAQ,KAAK,QAAQ;gBAC1B,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,MAAM,IAAI,uBAAuB,CAAC;YAErE,OAAO,IAAI,sBAAY,CAAC,OAAO,EAAE;gBAC/B,UAAU,EAAE;oBACV,IAAI,EAAE,mBAAU,CAAC,MAAM,CAAC;oBACxB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,sBAAY,CAAC,KAAK,CAAC,OAAO,EAAE;YACrC,UAAU,EAAE;gBACV,IAAI,EAAE,uBAAuB;gBAC7B,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA1CY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,cAAK,GAAE;GACK,sBAAsB,CA0ClC"}
@@ -1,7 +1,10 @@
1
1
  import { type DynamicModule } from "@nestjs/common";
2
2
  import { type ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, type OPTIONS_TYPE } from "./graphql.module-definition";
3
+ import { type GraphQLModuleOptions } from "./interfaces";
3
4
  export declare class GraphQLModule extends ConfigurableModuleClass {
5
+ private readonly options;
4
6
  static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
5
7
  static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
6
8
  private static withBaseGraphQLModule;
9
+ constructor(options: GraphQLModuleOptions);
7
10
  }
@@ -5,16 +5,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
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
+ };
8
14
  Object.defineProperty(exports, "__esModule", { value: true });
9
15
  exports.GraphQLModule = void 0;
16
+ const default_1 = require("@apollo/server/plugin/landingPage/default");
10
17
  const apollo_1 = require("@nestjs/apollo");
11
18
  const common_1 = require("@nestjs/common");
12
19
  const core_1 = require("@nestjs/core");
13
20
  const graphql_1 = require("@nestjs/graphql");
14
- const connection_service_1 = require("./connection.service");
15
21
  const graphql_exception_filter_1 = require("./graphql.exception-filter");
16
22
  const graphql_module_definition_1 = require("./graphql.module-definition");
17
23
  const plugins_1 = require("./plugins");
24
+ const logging_plugin_1 = require("./plugins/logging.plugin");
18
25
  let GraphQLModule = class GraphQLModule extends graphql_module_definition_1.ConfigurableModuleClass {
19
26
  static forRoot(options) {
20
27
  return this.withBaseGraphQLModule(super.forRoot(options));
@@ -27,8 +34,16 @@ let GraphQLModule = class GraphQLModule extends graphql_module_definition_1.Conf
27
34
  driver: apollo_1.ApolloDriver,
28
35
  inject: [graphql_module_definition_1.MODULE_OPTIONS_TOKEN],
29
36
  useFactory: (options) => {
37
+ if (options.playground !== false) {
38
+ options.playground = false;
39
+ options.plugins = [
40
+ ...(options.plugins ?? []),
41
+ (0, default_1.ApolloServerPluginLandingPageLocalDefault)({
42
+ includeCookies: true,
43
+ }),
44
+ ];
45
+ }
30
46
  return {
31
- playground: false,
32
47
  ...options,
33
48
  ...(typeof options.subscriptions !== "undefined"
34
49
  ? {
@@ -40,26 +55,33 @@ let GraphQLModule = class GraphQLModule extends graphql_module_definition_1.Conf
40
55
  };
41
56
  },
42
57
  });
58
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
43
59
  dynamicModule.imports = [
44
60
  ...(dynamicModule.imports ?? []),
45
61
  BaseGraphQLDynamicModule,
46
62
  ];
47
63
  return dynamicModule;
48
64
  }
65
+ constructor(options) {
66
+ super();
67
+ this.options = options;
68
+ }
49
69
  };
50
70
  exports.GraphQLModule = GraphQLModule;
51
71
  exports.GraphQLModule = GraphQLModule = __decorate([
52
72
  (0, common_1.Global)(),
53
73
  (0, common_1.Module)({
54
74
  providers: [
55
- connection_service_1.ConnectionService,
56
75
  plugins_1.ComplexityPlugin,
76
+ logging_plugin_1.LoggingPlugin,
57
77
  {
58
78
  provide: core_1.APP_FILTER,
59
79
  useClass: graphql_exception_filter_1.GraphQLExceptionFilter,
60
80
  },
61
81
  ],
62
- exports: [graphql_module_definition_1.MODULE_OPTIONS_TOKEN, connection_service_1.ConnectionService],
63
- })
82
+ exports: [graphql_module_definition_1.MODULE_OPTIONS_TOKEN],
83
+ }),
84
+ __param(0, (0, common_1.Inject)(graphql_module_definition_1.MODULE_OPTIONS_TOKEN)),
85
+ __metadata("design:paramtypes", [Object])
64
86
  ], GraphQLModule);
65
87
  //# sourceMappingURL=graphql.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.module.js","sourceRoot":"","sources":["../src/graphql.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8C;AAC9C,2CAAoE;AACpE,uCAA0C;AAC1C,6CAAqE;AAErE,6DAAyD;AACzD,yEAAoE;AACpE,2EAKqC;AAErC,uCAA6C;AActC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,mDAAuB;IACxD,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAkC;QACpD,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAEO,MAAM,CAAC,qBAAqB,CAClC,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ACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,0BAAgB;YAChB,8BAAa;YACb;gBACE,OAAO,EAAE,iBAAU;gBACnB,QAAQ,EAAE,iDAAsB;aACjC;SACF;QACD,OAAO,EAAE,CAAC,gDAAoB,CAAC;KAChC,CAAC;IAkDG,WAAA,IAAA,eAAM,EAAC,gDAAoB,CAAC,CAAA;;GAjDpB,aAAa,CAsDzB"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,8 @@
1
1
  export * from "./complexities";
2
- export * from "./connection.builder";
3
- export * from "./connection.service";
4
2
  export * from "./decorators";
5
- export * from "./dtos";
6
- export * from "./entity.data-loader";
7
- export * from "./enums";
8
3
  export * from "./graphql.exception-filter";
9
4
  export * from "./graphql.module";
10
5
  export * from "./interfaces";
11
6
  export * from "./plugins";
12
- export * from "./utils";
13
7
  export { Plugin } from "@nestjs/apollo";
14
8
  export { Args, createUnionType, Field, GraphQLSchemaHost, ID, InputType, Mutation, ObjectType, Query, registerEnumType, ResolveField, Resolver, } from "@nestjs/graphql";
package/dist/index.js CHANGED
@@ -16,17 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Resolver = exports.ResolveField = exports.registerEnumType = exports.Query = exports.ObjectType = exports.Mutation = exports.InputType = exports.ID = exports.GraphQLSchemaHost = exports.Field = exports.createUnionType = exports.Args = exports.Plugin = void 0;
18
18
  __exportStar(require("./complexities"), exports);
19
- __exportStar(require("./connection.builder"), exports);
20
- __exportStar(require("./connection.service"), exports);
21
19
  __exportStar(require("./decorators"), exports);
22
- __exportStar(require("./dtos"), exports);
23
- __exportStar(require("./entity.data-loader"), exports);
24
- __exportStar(require("./enums"), exports);
25
20
  __exportStar(require("./graphql.exception-filter"), exports);
26
21
  __exportStar(require("./graphql.module"), exports);
27
22
  __exportStar(require("./interfaces"), exports);
28
23
  __exportStar(require("./plugins"), exports);
29
- __exportStar(require("./utils"), exports);
30
24
  var apollo_1 = require("@nestjs/apollo");
31
25
  Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return apollo_1.Plugin; } });
32
26
  var graphql_1 = require("@nestjs/graphql");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,uDAAqC;AACrC,uDAAqC;AACrC,+CAA6B;AAC7B,yCAAuB;AACvB,uDAAqC;AACrC,0CAAwB;AACxB,6DAA2C;AAC3C,mDAAiC;AACjC,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AACf,2CAayB;AAZvB,+FAAA,IAAI,OAAA;AACJ,0GAAA,eAAe,OAAA;AACf,gGAAA,KAAK,OAAA;AACL,4GAAA,iBAAiB,OAAA;AACjB,6FAAA,EAAE,OAAA;AACF,oGAAA,SAAS,OAAA;AACT,mGAAA,QAAQ,OAAA;AACR,qGAAA,UAAU,OAAA;AACV,gGAAA,KAAK,OAAA;AACL,2GAAA,gBAAgB,OAAA;AAChB,uGAAA,YAAY,OAAA;AACZ,mGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,+CAA6B;AAC7B,6DAA2C;AAC3C,mDAAiC;AACjC,+CAA6B;AAC7B,4CAA0B;AAC1B,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AACf,2CAayB;AAZvB,+FAAA,IAAI,OAAA;AACJ,0GAAA,eAAe,OAAA;AACf,gGAAA,KAAK,OAAA;AACL,4GAAA,iBAAiB,OAAA;AACjB,6FAAA,EAAE,OAAA;AACF,oGAAA,SAAS,OAAA;AACT,mGAAA,QAAQ,OAAA;AACR,qGAAA,UAAU,OAAA;AACV,gGAAA,KAAK,OAAA;AACL,2GAAA,gBAAgB,OAAA;AAChB,uGAAA,YAAY,OAAA;AACZ,mGAAA,QAAQ,OAAA"}
@@ -0,0 +1,10 @@
1
+ export interface CostThrottleStatus {
2
+ maximumAvailable: number;
3
+ currentlyAvailable: number;
4
+ restoreRate: number;
5
+ }
6
+ export interface CostResponse {
7
+ requestedQueryCost: number;
8
+ actualQueryCost: number;
9
+ throttleStatus?: CostThrottleStatus;
10
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=connection.interface.js.map
3
+ //# sourceMappingURL=cost-response.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-response.interface.js","sourceRoot":"","sources":["../../src/interfaces/cost-response.interface.ts"],"names":[],"mappings":""}
@@ -1,24 +1,21 @@
1
- import { BaseContext, GraphQLRequestContextDidResolveOperation } from "@apollo/server";
2
- import { ApolloServerPluginLandingPageGraphQLPlaygroundOptions } from "@apollo/server-plugin-landing-page-graphql-playground";
1
+ import { BaseContext, GraphQLRequestContext } from "@apollo/server";
3
2
  import { type ApolloDriverConfig } from "@nestjs/apollo";
4
3
  import { type GraphQLWsSubscriptionsConfig } from "@nestjs/graphql";
4
+ import { RedisOptions } from "ioredis";
5
5
  export interface GraphQLModuleComplexityRateLimitOptions {
6
+ connection?: RedisOptions;
6
7
  keyPrefix?: string;
7
8
  restoreRate?: number;
8
9
  maximumAvailable?: number;
9
- getId?: (args: GraphQLRequestContextDidResolveOperation<BaseContext>) => string;
10
+ getId?: (args: GraphQLRequestContext<BaseContext>) => string;
10
11
  }
11
12
  export interface GraphQLModuleComplexityOptions {
12
- logging?: boolean;
13
13
  maxComplexity?: number;
14
14
  defaultComplexity?: number;
15
- rateLimit?: GraphQLModuleComplexityRateLimitOptions | boolean;
15
+ rateLimit?: GraphQLModuleComplexityRateLimitOptions;
16
16
  }
17
17
  export interface GraphQLModuleOptions extends Omit<ApolloDriverConfig, "playground" | "subscriptions"> {
18
- /**
19
- * @deprecated GraphQL Playground 项目已停止使用,推荐使用 ApolloServerPluginLandingPageLocalDefault 插件来替代。
20
- */
21
- playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
22
- subscriptions?: GraphQLWsSubscriptionsConfig | boolean;
23
- complexity?: GraphQLModuleComplexityOptions | boolean;
18
+ playground?: boolean;
19
+ subscriptions?: GraphQLWsSubscriptionsConfig;
20
+ complexity?: GraphQLModuleComplexityOptions;
24
21
  }
@@ -1,6 +1,3 @@
1
- export * from "./connection.interface";
2
- export * from "./connection-args.interface";
1
+ export * from "./cost-response.interface";
3
2
  export * from "./edge.interface";
4
3
  export * from "./graphql-module-options.interface";
5
- export * from "./order.interface";
6
- export * from "./order-field.type";
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./connection.interface"), exports);
18
- __exportStar(require("./connection-args.interface"), exports);
17
+ __exportStar(require("./cost-response.interface"), exports);
19
18
  __exportStar(require("./edge.interface"), exports);
20
19
  __exportStar(require("./graphql-module-options.interface"), exports);
21
- __exportStar(require("./order.interface"), exports);
22
- __exportStar(require("./order-field.type"), exports);
23
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,8DAA4C;AAC5C,mDAAiC;AACjC,qEAAmD;AACnD,oDAAkC;AAClC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,mDAAiC;AACjC,qEAAmD"}
@@ -1,20 +1,21 @@
1
- import { type ApolloServerPlugin, type BaseContext, type GraphQLRequestListener } from "@apollo/server";
2
- import { Redis } from "@nest-boot/redis";
1
+ import { type ApolloServerPlugin, type BaseContext, GraphQLRequestContext, type GraphQLRequestListener } from "@apollo/server";
2
+ import { OnApplicationShutdown } from "@nestjs/common";
3
3
  import { GraphQLSchemaHost } from "@nestjs/graphql";
4
4
  import { GraphQLModuleOptions } from "../interfaces";
5
- export declare class ComplexityPlugin implements ApolloServerPlugin {
5
+ export declare class ComplexityPlugin implements ApolloServerPlugin, OnApplicationShutdown {
6
6
  private readonly options;
7
7
  private readonly gqlSchemaHost;
8
- private readonly redis;
9
- private readonly logger;
10
- private readonly logging;
8
+ private readonly complexityEstimators;
11
9
  private readonly maxComplexity;
12
10
  private readonly defaultComplexity;
13
- private readonly rateLimitEnable;
11
+ private readonly rateLimitRedis?;
14
12
  private readonly rateLimitKeyPrefix;
15
13
  private readonly rateLimitRestoreRate;
16
14
  private readonly rateLimitMaximumAvailable;
17
15
  private readonly rateLimitGetId;
18
- constructor(options: GraphQLModuleOptions, gqlSchemaHost: GraphQLSchemaHost, redis: Redis);
16
+ constructor(options: GraphQLModuleOptions, gqlSchemaHost: GraphQLSchemaHost);
17
+ addPoint(args: GraphQLRequestContext<BaseContext>, point: number): Promise<[boolean, number]>;
18
+ subPoint(args: GraphQLRequestContext<BaseContext>, point: number): Promise<[boolean, number]>;
19
19
  requestDidStart(): Promise<GraphQLRequestListener<BaseContext>>;
20
+ onApplicationShutdown(): Promise<void>;
20
21
  }
@@ -12,15 +12,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
12
12
  var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  return function (target, key) { decorator(target, key, paramIndex); }
14
14
  };
15
- var ComplexityPlugin_1;
16
15
  Object.defineProperty(exports, "__esModule", { value: true });
17
16
  exports.ComplexityPlugin = void 0;
18
- const redis_1 = require("@nest-boot/redis");
19
17
  const apollo_1 = require("@nestjs/apollo");
20
18
  const common_1 = require("@nestjs/common");
21
19
  const graphql_1 = require("@nestjs/graphql");
22
20
  const graphql_2 = require("graphql");
23
21
  const graphql_query_complexity_1 = require("graphql-query-complexity");
22
+ const ioredis_1 = require("ioredis");
24
23
  const graphql_module_definition_1 = require("../graphql.module-definition");
25
24
  // https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity
26
25
  function shopifyEstimator(args, type) {
@@ -29,17 +28,15 @@ function shopifyEstimator(args, type) {
29
28
  return shopifyEstimator(args, type.ofType);
30
29
  }
31
30
  // GraphQL 的 Connection 表示的是一对多的关系,Connection 的消耗是两点加上要返回的对象数量。
32
- if (type instanceof graphql_2.GraphQLObjectType &&
33
- type.name.endsWith("Connection") &&
34
- typeof (args.args.first ?? args.args.last) === "number") {
35
- return 2 + args.childComplexity * (args.args.first ?? args.args.last);
31
+ if (type instanceof graphql_2.GraphQLObjectType && type.name.endsWith("Connection")) {
32
+ return 2 + args.childComplexity * (args.args.first ?? args.args.last ?? 0);
36
33
  }
37
34
  // Object 是查询的基本单位,一般代码一个单次的 server 端操作,可以是一次数据库查询,也可以一次内部服务的访问。
38
35
  // Interface 和 Union 和 Object 类似,只不过是能返回不同类型的 object,所以算一点。
39
36
  if (type instanceof graphql_2.GraphQLObjectType ||
40
37
  type instanceof graphql_2.GraphQLInterfaceType ||
41
38
  type instanceof graphql_2.GraphQLUnionType) {
42
- return 1;
39
+ return 1 + args.childComplexity;
43
40
  }
44
41
  // Scalar 和 Enum 是 Object 本身的一部分,在 Object 里我们已经算过消耗了。
45
42
  // Scalar 和 Enum 其实就是 Object 上的某个字段,一个 Object 上多返回几个字段消耗是比较少的。
@@ -48,16 +45,13 @@ function shopifyEstimator(args, type) {
48
45
  }
49
46
  }
50
47
  const REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME = "GRAPHQL_COMPLEXITY.RATE_LIMIT";
51
- let ComplexityPlugin = ComplexityPlugin_1 = class ComplexityPlugin {
52
- constructor(options, gqlSchemaHost, redis) {
48
+ let ComplexityPlugin = class ComplexityPlugin {
49
+ constructor(options, gqlSchemaHost) {
53
50
  this.options = options;
54
51
  this.gqlSchemaHost = gqlSchemaHost;
55
- this.redis = redis;
56
- this.logger = new common_1.Logger(ComplexityPlugin_1.name);
57
- this.logging = false;
52
+ this.complexityEstimators = [];
58
53
  this.maxComplexity = 1000;
59
54
  this.defaultComplexity = 0;
60
- this.rateLimitEnable = true;
61
55
  this.rateLimitKeyPrefix = "graphql-complexity:rate-limit";
62
56
  this.rateLimitRestoreRate = 50;
63
57
  this.rateLimitMaximumAvailable = 1000;
@@ -65,18 +59,16 @@ let ComplexityPlugin = ComplexityPlugin_1 = class ComplexityPlugin {
65
59
  const req = args.contextValue.req;
66
60
  return req.ips.length ? req.ips[0] : req.ip;
67
61
  };
68
- if (typeof options.complexity !== "boolean" &&
69
- typeof options.complexity !== "undefined") {
70
- this.logging = options.complexity.logging ?? this.logging;
62
+ if (typeof options.complexity !== "undefined") {
71
63
  this.maxComplexity =
72
64
  options.complexity.maxComplexity ?? this.maxComplexity;
73
65
  this.defaultComplexity =
74
66
  options.complexity.defaultComplexity ?? this.defaultComplexity;
75
- if (options.complexity.rateLimit === false) {
76
- this.rateLimitEnable = false;
77
- }
78
- else if (typeof options.complexity.rateLimit !== "boolean" &&
79
- typeof options.complexity.rateLimit !== "undefined") {
67
+ if (typeof options.complexity.rateLimit !== "undefined") {
68
+ this.rateLimitRedis =
69
+ typeof options.complexity.rateLimit.connection !== "undefined"
70
+ ? new ioredis_1.Redis(options.complexity.rateLimit.connection)
71
+ : new ioredis_1.Redis();
80
72
  this.rateLimitKeyPrefix =
81
73
  options.complexity.rateLimit.keyPrefix ?? this.rateLimitKeyPrefix;
82
74
  this.rateLimitRestoreRate =
@@ -88,8 +80,8 @@ let ComplexityPlugin = ComplexityPlugin_1 = class ComplexityPlugin {
88
80
  options.complexity.rateLimit.getId ?? this.rateLimitGetId;
89
81
  }
90
82
  }
91
- if (typeof this.redis !== "undefined" && this.rateLimitEnable) {
92
- this.redis.defineCommand(REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME, {
83
+ if (typeof this.rateLimitRedis !== "undefined") {
84
+ this.rateLimitRedis.defineCommand(REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME, {
93
85
  numberOfKeys: 5,
94
86
  lua: /* lua */ `
95
87
  -- 获取当前时间戳
@@ -144,71 +136,111 @@ let ComplexityPlugin = ComplexityPlugin_1 = class ComplexityPlugin {
144
136
  `,
145
137
  });
146
138
  }
139
+ this.complexityEstimators = [
140
+ (0, graphql_query_complexity_1.directiveEstimator)(),
141
+ (0, graphql_query_complexity_1.fieldExtensionsEstimator)(),
142
+ shopifyEstimator,
143
+ (0, graphql_query_complexity_1.simpleEstimator)({ defaultComplexity: this.defaultComplexity }),
144
+ ];
145
+ }
146
+ async addPoint(args, point) {
147
+ if (typeof this.rateLimitRedis === "undefined") {
148
+ throw new Error("Redis is not defined");
149
+ }
150
+ return (await this.rateLimitRedis[REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME](this.rateLimitKeyPrefix, this.rateLimitMaximumAvailable, this.rateLimitRestoreRate, this.rateLimitGetId(args), -point));
151
+ }
152
+ async subPoint(args, point) {
153
+ if (typeof this.rateLimitRedis === "undefined") {
154
+ throw new Error("Redis is not defined");
155
+ }
156
+ return (await this.rateLimitRedis[REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME](this.rateLimitKeyPrefix, this.rateLimitMaximumAvailable, this.rateLimitRestoreRate, this.rateLimitGetId(args), point));
147
157
  }
148
158
  async requestDidStart() {
149
159
  const { schema } = this.gqlSchemaHost;
160
+ const cost = {
161
+ requestedQueryCost: 0,
162
+ actualQueryCost: 0,
163
+ };
150
164
  return {
151
165
  didResolveOperation: async (args) => {
152
166
  const { request, document } = args;
153
- const complexity = (0, graphql_query_complexity_1.getComplexity)({
167
+ cost.requestedQueryCost = (0, graphql_query_complexity_1.getComplexity)({
154
168
  schema,
155
169
  operationName: request.operationName,
156
170
  query: document,
157
171
  variables: request.variables,
158
- estimators: [
159
- (0, graphql_query_complexity_1.directiveEstimator)({ name: "complexity" }),
160
- (0, graphql_query_complexity_1.fieldExtensionsEstimator)(),
161
- shopifyEstimator,
162
- (0, graphql_query_complexity_1.simpleEstimator)({ defaultComplexity: this.defaultComplexity }),
163
- ],
172
+ estimators: this.complexityEstimators,
164
173
  });
165
- request.extensions = request.extensions ?? {};
166
- request.extensions.cost = {
167
- requestedQueryCost: complexity,
168
- };
169
- if (this.logging) {
170
- this.logger.log("query complexity", {
171
- operationName: request.operationName,
172
- complexity,
173
- });
174
+ if (cost.requestedQueryCost >= this.maxComplexity) {
175
+ throw new common_1.HttpException(`Query is too complex: ${cost.requestedQueryCost}. Maximum allowed complexity: ${this.maxComplexity}`, 429);
174
176
  }
175
- if (complexity >= this.maxComplexity) {
176
- throw new common_1.HttpException(`Query is too complex: ${complexity}. Maximum allowed complexity: ${this.maxComplexity}`, 429);
177
- }
178
- if (typeof this.redis !== "undefined" && this.rateLimitEnable) {
179
- const [blocked, currentlyAvailable] = (await this.redis[REDIS_GRAPHQL_COMPLEXITY_RATE_LIMIT_COMMAND_NAME](this.rateLimitKeyPrefix, this.rateLimitMaximumAvailable, this.rateLimitRestoreRate, this.rateLimitGetId(args), complexity));
180
- request.extensions.cost = {
181
- ...request.extensions.cost,
182
- throttleStatus: {
183
- maximumAvailable: this.rateLimitMaximumAvailable,
184
- currentlyAvailable,
185
- restoreRate: this.rateLimitRestoreRate,
186
- },
177
+ if (typeof this.rateLimitRedis !== "undefined") {
178
+ const [blocked, currentlyAvailable] = await this.subPoint(args, cost.requestedQueryCost);
179
+ cost.throttleStatus = {
180
+ maximumAvailable: this.rateLimitMaximumAvailable,
181
+ currentlyAvailable,
182
+ restoreRate: this.rateLimitRestoreRate,
187
183
  };
188
184
  if (blocked) {
189
185
  throw new common_1.HttpException(`Too Many Requests`, 429);
190
186
  }
191
187
  }
192
188
  },
193
- willSendResponse: async ({ request, response }) => {
194
- if (response.body.kind === "single" &&
195
- "data" in response.body.singleResult &&
196
- typeof request.extensions?.cost !== "undefined") {
197
- response.body.singleResult.extensions = {
198
- ...response.body.singleResult.extensions,
199
- ...request.extensions.cost,
189
+ executionDidStart: async () => {
190
+ return {
191
+ willResolveField: ({ info }) => {
192
+ const parentTypeFields = info.parentType.getFields();
193
+ const field = parentTypeFields[info.fieldName];
194
+ const estimatorArgs = {
195
+ childComplexity: 0,
196
+ args: {},
197
+ field,
198
+ node: info.fieldNodes[0],
199
+ type: info.parentType,
200
+ };
201
+ return (error) => {
202
+ if (error === null) {
203
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
204
+ let fieldCost;
205
+ for (const complexityEstimator of this.complexityEstimators) {
206
+ fieldCost = complexityEstimator(estimatorArgs);
207
+ if (typeof fieldCost === "number" && !isNaN(fieldCost)) {
208
+ cost.actualQueryCost += fieldCost;
209
+ break;
210
+ }
211
+ }
212
+ }
213
+ };
214
+ },
215
+ };
216
+ },
217
+ willSendResponse: async (request) => {
218
+ if (request.response.body.kind === "single" &&
219
+ "data" in request.response.body.singleResult) {
220
+ if (typeof this.rateLimitRedis !== "undefined") {
221
+ const [, currentlyAvailable] = await this.addPoint(request, cost.requestedQueryCost - cost.actualQueryCost);
222
+ cost.throttleStatus = {
223
+ maximumAvailable: this.rateLimitMaximumAvailable,
224
+ currentlyAvailable,
225
+ restoreRate: this.rateLimitRestoreRate,
226
+ };
227
+ }
228
+ request.response.body.singleResult.extensions = {
229
+ ...request.response.body.singleResult.extensions,
230
+ cost,
200
231
  };
201
232
  }
202
233
  },
203
234
  };
204
235
  }
236
+ async onApplicationShutdown() {
237
+ await this.rateLimitRedis?.quit();
238
+ }
205
239
  };
206
240
  exports.ComplexityPlugin = ComplexityPlugin;
207
- exports.ComplexityPlugin = ComplexityPlugin = ComplexityPlugin_1 = __decorate([
241
+ exports.ComplexityPlugin = ComplexityPlugin = __decorate([
208
242
  (0, apollo_1.Plugin)(),
209
243
  __param(0, (0, common_1.Inject)(graphql_module_definition_1.MODULE_OPTIONS_TOKEN)),
210
- __param(2, (0, common_1.Optional)()),
211
- __metadata("design:paramtypes", [Object, graphql_1.GraphQLSchemaHost,
212
- redis_1.Redis])
244
+ __metadata("design:paramtypes", [Object, graphql_1.GraphQLSchemaHost])
213
245
  ], ComplexityPlugin);
214
246
  //# sourceMappingURL=complexity.plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"complexity.plugin.js","sourceRoot":"","sources":["../../src/plugins/complexity.plugin.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;;;;;;;;;;;;;;AAQrD,4CAAyC;AACzC,2CAAwC;AACxC,2CAAyE;AACzE,6CAAoD;AAEpD,qCASiB;AACjB,uEAMkC;AAElC,4EAAoE;AAGpE,sFAAsF;AACtF,SAAS,gBAAgB,CACvB,IAA6B,EAC7B,IAAkB;IAElB,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAE/B,IAAI,IAAI,YAAY,wBAAc,IAAI,IAAI,YAAY,qBAAW,EAAE;QACjE,OAAO,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;KAC5C;IAED,+DAA+D;IAC/D,IACE,IAAI,YAAY,2BAAiB;QACjC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,QAAQ,EACvD;QACA,OAAO,CAAC,GAAG,IAAI,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACvE;IAED,gEAAgE;IAChE,2DAA2D;IAC3D,IACE,IAAI,YAAY,2BAAiB;QACjC,IAAI,YAAY,8BAAoB;QACpC,IAAI,YAAY,0BAAgB,EAChC;QACA,OAAO,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AI,CAAC,cAAc,KAAK,WAAW,EAAE,CAAC;wBAC/C,MAAM,CAAC,EAAE,kBAAkB,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAChD,OAAO,EACP,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,eAAe,CAC/C,CAAC;wBAEF,IAAI,CAAC,cAAc,GAAG;4BACpB,gBAAgB,EAAE,IAAI,CAAC,yBAAyB;4BAChD,kBAAkB;4BAClB,WAAW,EAAE,IAAI,CAAC,oBAAoB;yBACvC,CAAC;oBACJ,CAAC;oBAED,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG;wBAC9C,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU;wBAChD,IAAI;qBACL,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC;IACpC,CAAC;CACF,CAAA;AArQY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,eAAM,GAAE;IAsBJ,WAAA,IAAA,eAAM,EAAC,gDAAoB,CAAC,CAAA;6CAEG,2BAAiB;GAvBxC,gBAAgB,CAqQ5B"}
@@ -0,0 +1,7 @@
1
+ import { type ApolloServerPlugin, type BaseContext, type GraphQLRequestListener } from "@apollo/server";
2
+ import { Logger } from "@nest-boot/logger";
3
+ export declare class LoggingPlugin implements ApolloServerPlugin {
4
+ private readonly logger?;
5
+ constructor(logger?: Logger | undefined);
6
+ requestDidStart(): Promise<GraphQLRequestListener<BaseContext>>;
7
+ }