@envelop/rate-limiter 3.6.0 → 3.6.1-alpha-20220901205925-b1fd44a9
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 +5 -0
- package/cjs/index.js +5 -4
- package/cjs/utils.js +1 -2
- package/esm/index.js +5 -4
- package/esm/utils.js +1 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ yarn add @envelop/rate-limiter
|
|
|
11
11
|
## Usage Example
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
14
15
|
import { envelop } from '@envelop/core'
|
|
15
16
|
import { useRateLimiter, IdentifyFn } from '@envelop/rate-limiter'
|
|
16
17
|
|
|
@@ -19,6 +20,10 @@ const identifyFn: IdentifyFn = async context => {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const getEnveloped = envelop({
|
|
23
|
+
parse,
|
|
24
|
+
validate,
|
|
25
|
+
execute,
|
|
26
|
+
subscribe,
|
|
22
27
|
plugins: [
|
|
23
28
|
// ... other plugins ...
|
|
24
29
|
useRateLimiter({
|
package/cjs/index.js
CHANGED
|
@@ -20,12 +20,13 @@ const useRateLimiter = (options) => {
|
|
|
20
20
|
});
|
|
21
21
|
},
|
|
22
22
|
async onResolverCalled({ args, root, context, info }) {
|
|
23
|
-
var _a, _b, _c;
|
|
24
23
|
const rateLimitDirectiveNode = (0, utils_js_1.getDirective)(info, options.rateLimitDirectiveName || 'rateLimit');
|
|
25
24
|
if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
|
|
26
|
-
const maxNode =
|
|
27
|
-
const windowNode =
|
|
28
|
-
|
|
25
|
+
const maxNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')?.value;
|
|
26
|
+
const windowNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')
|
|
27
|
+
?.value;
|
|
28
|
+
const messageNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')
|
|
29
|
+
?.value;
|
|
29
30
|
const message = messageNode.value;
|
|
30
31
|
const max = parseInt(maxNode.value);
|
|
31
32
|
const window = windowNode.value;
|
package/cjs/utils.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDirective = void 0;
|
|
4
4
|
function getDirective(info, name) {
|
|
5
|
-
var _a;
|
|
6
5
|
const { parentType, fieldName, schema } = info;
|
|
7
6
|
const schemaType = schema.getType(parentType.name);
|
|
8
7
|
const field = schemaType.getFields()[fieldName];
|
|
9
8
|
const astNode = field.astNode;
|
|
10
|
-
const rateLimitDirective =
|
|
9
|
+
const rateLimitDirective = astNode?.directives?.find(d => d.name.value === name);
|
|
11
10
|
return rateLimitDirective || null;
|
|
12
11
|
}
|
|
13
12
|
exports.getDirective = getDirective;
|
package/esm/index.js
CHANGED
|
@@ -15,12 +15,13 @@ export const useRateLimiter = (options) => {
|
|
|
15
15
|
});
|
|
16
16
|
},
|
|
17
17
|
async onResolverCalled({ args, root, context, info }) {
|
|
18
|
-
var _a, _b, _c;
|
|
19
18
|
const rateLimitDirectiveNode = getDirective(info, options.rateLimitDirectiveName || 'rateLimit');
|
|
20
19
|
if (rateLimitDirectiveNode && rateLimitDirectiveNode.arguments) {
|
|
21
|
-
const maxNode =
|
|
22
|
-
const windowNode =
|
|
23
|
-
|
|
20
|
+
const maxNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'max')?.value;
|
|
21
|
+
const windowNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'window')
|
|
22
|
+
?.value;
|
|
23
|
+
const messageNode = rateLimitDirectiveNode.arguments.find(arg => arg.name.value === 'message')
|
|
24
|
+
?.value;
|
|
24
25
|
const message = messageNode.value;
|
|
25
26
|
const max = parseInt(maxNode.value);
|
|
26
27
|
const window = windowNode.value;
|
package/esm/utils.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export function getDirective(info, name) {
|
|
2
|
-
var _a;
|
|
3
2
|
const { parentType, fieldName, schema } = info;
|
|
4
3
|
const schemaType = schema.getType(parentType.name);
|
|
5
4
|
const field = schemaType.getFields()[fieldName];
|
|
6
5
|
const astNode = field.astNode;
|
|
7
|
-
const rateLimitDirective =
|
|
6
|
+
const rateLimitDirective = astNode?.directives?.find(d => d.name.value === name);
|
|
8
7
|
return rateLimitDirective || null;
|
|
9
8
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/rate-limiter",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1-alpha-20220901205925-b1fd44a9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "2.6.1-alpha-20220901205925-b1fd44a9",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|