@graphql-mesh/plugin-rate-limit 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf

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.
@@ -1,13 +1,11 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- const stringInterpolation = require('@graphql-mesh/string-interpolation');
6
- const crossHelpers = require('@graphql-mesh/cross-helpers');
7
- const utils = require('@graphql-tools/utils');
8
- const minimatch = _interopDefault(require('minimatch'));
9
- const graphql = require('graphql');
10
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const graphql_1 = require("graphql");
5
+ const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
6
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
7
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
8
+ const utils_1 = require("@graphql-tools/utils");
11
9
  function deleteNode(parent, remaining, currentKey) {
12
10
  const nextKey = remaining.shift();
13
11
  if (nextKey) {
@@ -19,19 +17,19 @@ function deleteNode(parent, remaining, currentKey) {
19
17
  function useMeshRateLimit(options) {
20
18
  return {
21
19
  async onExecute(onExecuteArgs) {
22
- const typeInfo = new graphql.TypeInfo(onExecuteArgs.args.schema);
20
+ const typeInfo = new graphql_1.TypeInfo(onExecuteArgs.args.schema);
23
21
  const errors = [];
24
22
  const jobs = [];
25
23
  let remainingFields = 0;
26
- graphql.visit(onExecuteArgs.args.document, graphql.visitInParallel(options.config.map(config => {
27
- const typeMatcher = new minimatch.Minimatch(config.type);
28
- const fieldMatcher = new minimatch.Minimatch(config.field);
29
- const identifier = stringInterpolation.stringInterpolator.parse(config.identifier, {
30
- env: crossHelpers.process.env,
24
+ (0, graphql_1.visit)(onExecuteArgs.args.document, (0, graphql_1.visitInParallel)(options.config.map(config => {
25
+ const typeMatcher = new minimatch_1.default.Minimatch(config.type);
26
+ const fieldMatcher = new minimatch_1.default.Minimatch(config.field);
27
+ const identifier = string_interpolation_1.stringInterpolator.parse(config.identifier, {
28
+ env: cross_helpers_1.process.env,
31
29
  root: onExecuteArgs.args.rootValue,
32
30
  context: onExecuteArgs.args.contextValue,
33
31
  });
34
- return graphql.visitWithTypeInfo(typeInfo, {
32
+ return (0, graphql_1.visitWithTypeInfo)(typeInfo, {
35
33
  Field: (fieldNode, key, parent, path) => {
36
34
  const parentType = typeInfo.getParentType();
37
35
  if (typeMatcher.match(parentType.name)) {
@@ -45,8 +43,16 @@ function useMeshRateLimit(options) {
45
43
  remainingTokens = config.max;
46
44
  }
47
45
  if (remainingTokens === 0) {
48
- errors.push(utils.createGraphQLError(`Rate limit of "${parentType.name}.${fieldDef.name}" exceeded for "${identifier}"`, {
46
+ errors.push((0, utils_1.createGraphQLError)(`Rate limit of "${parentType.name}.${fieldDef.name}" exceeded for "${identifier}"`, {
49
47
  path: [((_a = fieldNode.alias) === null || _a === void 0 ? void 0 : _a.value) || fieldDef.name],
48
+ extensions: {
49
+ http: {
50
+ status: 429,
51
+ headers: {
52
+ 'Retry-After': config.ttl,
53
+ },
54
+ },
55
+ },
50
56
  }));
51
57
  deleteNode(parent, [...path]);
52
58
  remainingFields--;
@@ -87,5 +93,4 @@ function useMeshRateLimit(options) {
87
93
  },
88
94
  };
89
95
  }
90
-
91
- module.exports = useMeshRateLimit;
96
+ exports.default = useMeshRateLimit;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,9 +1,8 @@
1
- import { stringInterpolator } from '@graphql-mesh/string-interpolation';
1
+ import { TypeInfo, visit, visitInParallel, visitWithTypeInfo } from 'graphql';
2
+ import minimatch from 'minimatch';
2
3
  import { process } from '@graphql-mesh/cross-helpers';
4
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
3
5
  import { createGraphQLError } from '@graphql-tools/utils';
4
- import minimatch from 'minimatch';
5
- import { TypeInfo, visit, visitInParallel, visitWithTypeInfo } from 'graphql';
6
-
7
6
  function deleteNode(parent, remaining, currentKey) {
8
7
  const nextKey = remaining.shift();
9
8
  if (nextKey) {
@@ -12,7 +11,7 @@ function deleteNode(parent, remaining, currentKey) {
12
11
  }
13
12
  delete parent[currentKey];
14
13
  }
15
- function useMeshRateLimit(options) {
14
+ export default function useMeshRateLimit(options) {
16
15
  return {
17
16
  async onExecute(onExecuteArgs) {
18
17
  const typeInfo = new TypeInfo(onExecuteArgs.args.schema);
@@ -43,6 +42,14 @@ function useMeshRateLimit(options) {
43
42
  if (remainingTokens === 0) {
44
43
  errors.push(createGraphQLError(`Rate limit of "${parentType.name}.${fieldDef.name}" exceeded for "${identifier}"`, {
45
44
  path: [((_a = fieldNode.alias) === null || _a === void 0 ? void 0 : _a.value) || fieldDef.name],
45
+ extensions: {
46
+ http: {
47
+ status: 429,
48
+ headers: {
49
+ 'Retry-After': config.ttl,
50
+ },
51
+ },
52
+ },
46
53
  }));
47
54
  deleteNode(parent, [...path]);
48
55
  remainingFields--;
@@ -83,5 +90,3 @@ function useMeshRateLimit(options) {
83
90
  },
84
91
  };
85
92
  }
86
-
87
- export default useMeshRateLimit;
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-mesh/plugin-rate-limit",
3
- "version": "1.0.0-alpha-20220804093904-8e2e41f7f",
3
+ "version": "1.0.0-alpha-20230420220344-25b6b92bf",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-20220804093904-8e2e41f7f",
7
- "graphql": "*"
6
+ "@graphql-mesh/cross-helpers": "^0.3.4",
7
+ "@graphql-mesh/types": "1.0.0-alpha-20230420220344-25b6b92bf",
8
+ "@graphql-tools/utils": "^9.2.1",
9
+ "graphql": "*",
10
+ "tslib": "^2.4.0"
8
11
  },
9
12
  "dependencies": {
10
- "@envelop/core": "^2.3.2",
11
- "@graphql-mesh/cross-helpers": "0.2.0",
12
- "@graphql-mesh/string-interpolation": "0.3.0",
13
- "@graphql-tools/utils": "8.9.0",
14
- "minimatch": "5.1.0",
15
- "tslib": "^2.4.0"
13
+ "@graphql-mesh/string-interpolation": "0.4.4",
14
+ "minimatch": "8.0.4"
16
15
  },
17
16
  "repository": {
18
17
  "type": "git",
@@ -20,21 +19,28 @@
20
19
  "directory": "packages/plugins/response-cache"
21
20
  },
22
21
  "license": "MIT",
23
- "main": "index.js",
24
- "module": "index.mjs",
25
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
26
25
  "typescript": {
27
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
28
27
  },
28
+ "type": "module",
29
29
  "exports": {
30
30
  ".": {
31
- "require": "./index.js",
32
- "import": "./index.mjs"
33
- },
34
- "./*": {
35
- "require": "./*.js",
36
- "import": "./*.mjs"
31
+ "require": {
32
+ "types": "./typings/index.d.cts",
33
+ "default": "./cjs/index.js"
34
+ },
35
+ "import": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ },
39
+ "default": {
40
+ "types": "./typings/index.d.ts",
41
+ "default": "./esm/index.js"
42
+ }
37
43
  },
38
44
  "./package.json": "./package.json"
39
45
  }
40
- }
46
+ }
@@ -0,0 +1,2 @@
1
+ import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
2
+ export default function useMeshRateLimit(options: MeshPluginOptions<YamlConfig.RateLimitPluginConfig>): MeshPlugin<any>;
@@ -0,0 +1,2 @@
1
+ import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
2
+ export default function useMeshRateLimit(options: MeshPluginOptions<YamlConfig.RateLimitPluginConfig>): MeshPlugin<any>;
package/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
2
- import { Plugin } from '@envelop/core';
3
- export default function useMeshRateLimit(options: MeshPluginOptions<YamlConfig.RateLimitPluginConfig>): Plugin;