@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.
- package/{index.js → cjs/index.js} +25 -20
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +12 -7
- package/package.json +26 -20
- package/typings/index.d.cts +2 -0
- package/typings/index.d.ts +2 -0
- package/index.d.ts +0 -3
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
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
|
|
20
|
+
const typeInfo = new graphql_1.TypeInfo(onExecuteArgs.args.schema);
|
|
23
21
|
const errors = [];
|
|
24
22
|
const jobs = [];
|
|
25
23
|
let remainingFields = 0;
|
|
26
|
-
|
|
27
|
-
const typeMatcher = new
|
|
28
|
-
const fieldMatcher = new
|
|
29
|
-
const identifier =
|
|
30
|
-
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
|
|
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(
|
|
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;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
3
|
+
"version": "1.0.0-alpha-20230420220344-25b6b92bf",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
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
|
-
"@
|
|
11
|
-
"
|
|
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.
|
|
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":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
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
|
+
}
|
package/index.d.ts
DELETED