types.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { ComplexityEstimator } from 'graphql-query-complexity';
  2. /**
  3. * @description
  4. * Options that can be passed to the `.init()` static method of the HardenPlugin.
  5. *
  6. * @docsCategory core plugins/HardenPlugin
  7. */
  8. export interface HardenPluginOptions {
  9. /**
  10. * @description
  11. * Defines the maximum permitted complexity score of a query. The complexity score is based
  12. * on the number of fields being selected as well as other factors like whether there are nested
  13. * lists.
  14. *
  15. * A query which exceeds the maximum score will result in an error.
  16. *
  17. * @default 1000
  18. */
  19. maxQueryComplexity?: number;
  20. /**
  21. * @description
  22. * An array of custom estimator functions for calculating the complexity of a query. By default,
  23. * the plugin will use the {@link defaultVendureComplexityEstimator} which is specifically
  24. * tuned to accurately estimate Vendure queries.
  25. */
  26. queryComplexityEstimators?: ComplexityEstimator[];
  27. /**
  28. * @description
  29. * When set to `true`, the complexity score of each query will be logged at the Verbose
  30. * log level, and a breakdown of the calculation for each field will be logged at the Debug level.
  31. *
  32. * This is very useful for tuning your complexity scores.
  33. *
  34. * @default false
  35. */
  36. logComplexityScore?: boolean;
  37. /**
  38. * @description
  39. * This object allows you to tune the complexity weight of specific fields. For example,
  40. * if you have a custom `stockLocations` field defined on the `ProductVariant` type, and
  41. * you know that it is a particularly expensive operation to execute, you can increase
  42. * its complexity like this:
  43. *
  44. * @example
  45. * ```ts
  46. * HardenPlugin.init({
  47. * maxQueryComplexity: 650,
  48. * customComplexityFactors: {
  49. * 'ProductVariant.stockLocations': 10
  50. * }
  51. * }),
  52. * ```
  53. */
  54. customComplexityFactors?: {
  55. [path: string]: number;
  56. };
  57. /**
  58. * @description
  59. * Graphql-js will make suggestions about the names of fields if an invalid field name is provided.
  60. * This would allow an attacker to find out the available fields by brute force even if introspection
  61. * is disabled.
  62. *
  63. * Setting this option to `true` will prevent these suggestion error messages from being returned,
  64. * instead replacing the message with a generic "Invalid request" message.
  65. *
  66. * @default true
  67. */
  68. hideFieldSuggestions?: boolean;
  69. /**
  70. * @description
  71. * When set to `'prod'`, the plugin will disable dev-mode features of the GraphQL APIs:
  72. *
  73. * - introspection
  74. * - GraphQL playground
  75. *
  76. * @default 'prod'
  77. */
  78. apiMode?: 'dev' | 'prod';
  79. }