@envelop/resource-limitations 2.4.0-alpha-aca44e1.0 → 3.0.0-alpha-d0d0776.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/README.md +1 -1
- package/index.js +6 -8
- package/index.mjs +6 -8
- package/package.json +20 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## `@envelop/resource-limitations`
|
|
2
2
|
|
|
3
|
-
This plugins uses `extended-valiations` concept ([details here](https://github.com/
|
|
3
|
+
This plugins uses `extended-valiations` concept ([details here](https://github.com/n1ru4l/envelop/tree/main/packages/plugins/extended-validation#envelopextended-validation)) for implemeting a resource-limitations rate-limit similar to GitHub GraphQL API (see https://docs.github.com/en/graphql/overview/resource-limitations for more details)
|
|
4
4
|
|
|
5
5
|
## Getting Started
|
|
6
6
|
|
package/index.js
CHANGED
|
@@ -120,24 +120,22 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
|
|
|
120
120
|
},
|
|
121
121
|
Document: {
|
|
122
122
|
leave(documentNode) {
|
|
123
|
-
var _a;
|
|
124
123
|
if (totalNodeCost === 0) {
|
|
125
124
|
totalNodeCost = 1;
|
|
126
125
|
}
|
|
127
126
|
if (totalNodeCost > params.nodeCostLimit) {
|
|
128
127
|
context.reportError(new graphql.GraphQLError(`Cannot request more than ${params.nodeCostLimit} nodes in a single document. Please split your operation into multiple sub operations or reduce the amount of requested nodes.`, documentNode));
|
|
129
128
|
}
|
|
130
|
-
|
|
129
|
+
params.reportNodeCost?.(totalNodeCost, executionArgs);
|
|
131
130
|
},
|
|
132
131
|
},
|
|
133
132
|
};
|
|
134
133
|
};
|
|
135
134
|
const useResourceLimitations = (params) => {
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const extensions = (_d = params === null || params === void 0 ? void 0 : params.extensions) !== null && _d !== void 0 ? _d : false;
|
|
135
|
+
const paginationArgumentMaximum = params?.paginationArgumentMaximum ?? defaultPaginationArgumentMaximum;
|
|
136
|
+
const paginationArgumentMinimum = params?.paginationArgumentMinimum ?? defaultPaginationArgumentMinimum;
|
|
137
|
+
const nodeCostLimit = params?.nodeCostLimit ?? defaultNodeCostLimit;
|
|
138
|
+
const extensions = params?.extensions ?? false;
|
|
141
139
|
const nodeCostMap = new WeakMap();
|
|
142
140
|
const handleResult = ({ result, args }) => {
|
|
143
141
|
const nodeCost = nodeCostMap.get(args);
|
|
@@ -158,7 +156,7 @@ const useResourceLimitations = (params) => {
|
|
|
158
156
|
nodeCostLimit,
|
|
159
157
|
paginationArgumentMaximum,
|
|
160
158
|
paginationArgumentMinimum,
|
|
161
|
-
paginationArgumentTypes: params
|
|
159
|
+
paginationArgumentTypes: params?.paginationArgumentScalars,
|
|
162
160
|
reportNodeCost: extensions
|
|
163
161
|
? (nodeCost, ref) => {
|
|
164
162
|
nodeCostMap.set(ref, nodeCost);
|
package/index.mjs
CHANGED
|
@@ -116,24 +116,22 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
|
|
|
116
116
|
},
|
|
117
117
|
Document: {
|
|
118
118
|
leave(documentNode) {
|
|
119
|
-
var _a;
|
|
120
119
|
if (totalNodeCost === 0) {
|
|
121
120
|
totalNodeCost = 1;
|
|
122
121
|
}
|
|
123
122
|
if (totalNodeCost > params.nodeCostLimit) {
|
|
124
123
|
context.reportError(new GraphQLError(`Cannot request more than ${params.nodeCostLimit} nodes in a single document. Please split your operation into multiple sub operations or reduce the amount of requested nodes.`, documentNode));
|
|
125
124
|
}
|
|
126
|
-
|
|
125
|
+
params.reportNodeCost?.(totalNodeCost, executionArgs);
|
|
127
126
|
},
|
|
128
127
|
},
|
|
129
128
|
};
|
|
130
129
|
};
|
|
131
130
|
const useResourceLimitations = (params) => {
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const extensions = (_d = params === null || params === void 0 ? void 0 : params.extensions) !== null && _d !== void 0 ? _d : false;
|
|
131
|
+
const paginationArgumentMaximum = params?.paginationArgumentMaximum ?? defaultPaginationArgumentMaximum;
|
|
132
|
+
const paginationArgumentMinimum = params?.paginationArgumentMinimum ?? defaultPaginationArgumentMinimum;
|
|
133
|
+
const nodeCostLimit = params?.nodeCostLimit ?? defaultNodeCostLimit;
|
|
134
|
+
const extensions = params?.extensions ?? false;
|
|
137
135
|
const nodeCostMap = new WeakMap();
|
|
138
136
|
const handleResult = ({ result, args }) => {
|
|
139
137
|
const nodeCost = nodeCostMap.get(args);
|
|
@@ -154,7 +152,7 @@ const useResourceLimitations = (params) => {
|
|
|
154
152
|
nodeCostLimit,
|
|
155
153
|
paginationArgumentMaximum,
|
|
156
154
|
paginationArgumentMinimum,
|
|
157
|
-
paginationArgumentTypes: params
|
|
155
|
+
paginationArgumentTypes: params?.paginationArgumentScalars,
|
|
158
156
|
reportNodeCost: extensions
|
|
159
157
|
? (nodeCost, ref) => {
|
|
160
158
|
nodeCostMap.set(ref, nodeCost);
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/resource-limitations",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha-d0d0776.0",
|
|
4
4
|
"description": "A rate-limit implementation based on resource limitations and static calculation of the score (similar to GitHub GraphQL API)",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@envelop/core": "
|
|
7
|
+
"@envelop/core": "3.0.0-alpha-d0d0776.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@envelop/extended-validation": "
|
|
11
|
+
"@envelop/extended-validation": "2.0.0-alpha-d0d0776.0",
|
|
12
12
|
"@graphql-tools/utils": "^8.6.1"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/n1ru4l/envelop.git",
|
|
17
17
|
"directory": "packages/plugins/resource-limitations"
|
|
18
18
|
},
|
|
19
19
|
"author": "Laurin Quast <laurinquast@googlemail.com>",
|
|
@@ -26,12 +26,24 @@
|
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"require":
|
|
30
|
-
|
|
29
|
+
"require": {
|
|
30
|
+
"default": "./index.js",
|
|
31
|
+
"types": "./index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"default": "./index.mjs",
|
|
35
|
+
"types": "./index.d.ts"
|
|
36
|
+
}
|
|
31
37
|
},
|
|
32
38
|
"./*": {
|
|
33
|
-
"require":
|
|
34
|
-
|
|
39
|
+
"require": {
|
|
40
|
+
"default": "./*.js",
|
|
41
|
+
"types": "./*.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"import": {
|
|
44
|
+
"default": "./*.mjs",
|
|
45
|
+
"types": "./*.d.ts"
|
|
46
|
+
}
|
|
35
47
|
},
|
|
36
48
|
"./package.json": "./package.json"
|
|
37
49
|
}
|