@envelop/resource-limitations 2.4.0 → 2.4.1-alpha-88024a80.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 +6 -6
- package/cjs/index.js +11 -4
- package/esm/index.js +11 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ yarn add @envelop/resource-limitations
|
|
|
11
11
|
## Usage Example
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { envelop } from '@envelop/core'
|
|
15
|
-
import { useResourceLimitations } from '@envelop/resource-limitations'
|
|
14
|
+
import { envelop } from '@envelop/core'
|
|
15
|
+
import { useResourceLimitations } from '@envelop/resource-limitations'
|
|
16
16
|
|
|
17
17
|
const getEnveloped = envelop({
|
|
18
18
|
plugins: [
|
|
@@ -22,8 +22,8 @@ const getEnveloped = envelop({
|
|
|
22
22
|
paginationArgumentMaximum: 100, // optional, default to 100
|
|
23
23
|
paginationArgumentMinimum: 1, // optional, default to 1
|
|
24
24
|
paginationArgumentScalars: ['ConnectionInt'], // optional, use if connections use a different scalar type as the argument instead of `Int`
|
|
25
|
-
extensions: false
|
|
26
|
-
})
|
|
27
|
-
]
|
|
28
|
-
})
|
|
25
|
+
extensions: false // set this to `true` in order to add the calculated const to the response of queries
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
29
|
```
|
package/cjs/index.js
CHANGED
|
@@ -11,7 +11,8 @@ const getWrappedType = (graphqlType) => {
|
|
|
11
11
|
}
|
|
12
12
|
return graphqlType;
|
|
13
13
|
};
|
|
14
|
-
const isValidArgType = (type, paginationArgumentTypes) => type === graphql_1.GraphQLInt ||
|
|
14
|
+
const isValidArgType = (type, paginationArgumentTypes) => type === graphql_1.GraphQLInt ||
|
|
15
|
+
((0, graphql_1.isScalarType)(type) && !!paginationArgumentTypes && paginationArgumentTypes.includes(type.name));
|
|
15
16
|
const hasFieldDefConnectionArgs = (field, argumentTypes) => {
|
|
16
17
|
let hasFirst = false;
|
|
17
18
|
let hasLast = false;
|
|
@@ -30,7 +31,11 @@ const hasFieldDefConnectionArgs = (field, argumentTypes) => {
|
|
|
30
31
|
};
|
|
31
32
|
const buildMissingPaginationFieldErrorMessage = (params) => `Missing pagination argument for field '${params.fieldName}'. ` +
|
|
32
33
|
`Please provide ` +
|
|
33
|
-
(params.hasFirst && params.hasLast
|
|
34
|
+
(params.hasFirst && params.hasLast
|
|
35
|
+
? "either the 'first' or 'last'"
|
|
36
|
+
: params.hasFirst
|
|
37
|
+
? "the 'first'"
|
|
38
|
+
: "the 'last'") +
|
|
34
39
|
' field argument.';
|
|
35
40
|
const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field ${params.fieldName}. ` +
|
|
36
41
|
`The value for the '${params.argumentName}' argument must be an integer within ${params.paginationArgumentMinimum}-${params.paginationArgumentMaximum}.`;
|
|
@@ -70,7 +75,8 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
|
|
|
70
75
|
}), fieldNode));
|
|
71
76
|
}
|
|
72
77
|
else if ('first' in argumentValues === true && 'last' in argumentValues === false) {
|
|
73
|
-
if (argumentValues.first < paginationArgumentMinimum ||
|
|
78
|
+
if (argumentValues.first < paginationArgumentMinimum ||
|
|
79
|
+
argumentValues.first > paginationArgumentMaximum) {
|
|
74
80
|
context.reportError(new graphql_1.GraphQLError(buildInvalidPaginationRangeErrorMessage({
|
|
75
81
|
paginationArgumentMaximum,
|
|
76
82
|
paginationArgumentMinimum,
|
|
@@ -84,7 +90,8 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
else if ('last' in argumentValues === true && 'false' in argumentValues === false) {
|
|
87
|
-
if (argumentValues.last < paginationArgumentMinimum ||
|
|
93
|
+
if (argumentValues.last < paginationArgumentMinimum ||
|
|
94
|
+
argumentValues.last > paginationArgumentMaximum) {
|
|
88
95
|
context.reportError(new graphql_1.GraphQLError(buildInvalidPaginationRangeErrorMessage({
|
|
89
96
|
paginationArgumentMaximum,
|
|
90
97
|
paginationArgumentMinimum,
|
package/esm/index.js
CHANGED
|
@@ -8,7 +8,8 @@ const getWrappedType = (graphqlType) => {
|
|
|
8
8
|
}
|
|
9
9
|
return graphqlType;
|
|
10
10
|
};
|
|
11
|
-
const isValidArgType = (type, paginationArgumentTypes) => type === GraphQLInt ||
|
|
11
|
+
const isValidArgType = (type, paginationArgumentTypes) => type === GraphQLInt ||
|
|
12
|
+
(isScalarType(type) && !!paginationArgumentTypes && paginationArgumentTypes.includes(type.name));
|
|
12
13
|
const hasFieldDefConnectionArgs = (field, argumentTypes) => {
|
|
13
14
|
let hasFirst = false;
|
|
14
15
|
let hasLast = false;
|
|
@@ -27,7 +28,11 @@ const hasFieldDefConnectionArgs = (field, argumentTypes) => {
|
|
|
27
28
|
};
|
|
28
29
|
const buildMissingPaginationFieldErrorMessage = (params) => `Missing pagination argument for field '${params.fieldName}'. ` +
|
|
29
30
|
`Please provide ` +
|
|
30
|
-
(params.hasFirst && params.hasLast
|
|
31
|
+
(params.hasFirst && params.hasLast
|
|
32
|
+
? "either the 'first' or 'last'"
|
|
33
|
+
: params.hasFirst
|
|
34
|
+
? "the 'first'"
|
|
35
|
+
: "the 'last'") +
|
|
31
36
|
' field argument.';
|
|
32
37
|
const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field ${params.fieldName}. ` +
|
|
33
38
|
`The value for the '${params.argumentName}' argument must be an integer within ${params.paginationArgumentMinimum}-${params.paginationArgumentMaximum}.`;
|
|
@@ -67,7 +72,8 @@ export const ResourceLimitationValidationRule = (params) => (context, executionA
|
|
|
67
72
|
}), fieldNode));
|
|
68
73
|
}
|
|
69
74
|
else if ('first' in argumentValues === true && 'last' in argumentValues === false) {
|
|
70
|
-
if (argumentValues.first < paginationArgumentMinimum ||
|
|
75
|
+
if (argumentValues.first < paginationArgumentMinimum ||
|
|
76
|
+
argumentValues.first > paginationArgumentMaximum) {
|
|
71
77
|
context.reportError(new GraphQLError(buildInvalidPaginationRangeErrorMessage({
|
|
72
78
|
paginationArgumentMaximum,
|
|
73
79
|
paginationArgumentMinimum,
|
|
@@ -81,7 +87,8 @@ export const ResourceLimitationValidationRule = (params) => (context, executionA
|
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
else if ('last' in argumentValues === true && 'false' in argumentValues === false) {
|
|
84
|
-
if (argumentValues.last < paginationArgumentMinimum ||
|
|
90
|
+
if (argumentValues.last < paginationArgumentMinimum ||
|
|
91
|
+
argumentValues.last > paginationArgumentMaximum) {
|
|
85
92
|
context.reportError(new GraphQLError(buildInvalidPaginationRangeErrorMessage({
|
|
86
93
|
paginationArgumentMaximum,
|
|
87
94
|
paginationArgumentMinimum,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/resource-limitations",
|
|
3
|
-
"version": "2.4.0",
|
|
3
|
+
"version": "2.4.1-alpha-88024a80.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": "2.4.1-alpha-88024a80.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": "1.7.1-alpha-88024a80.0",
|
|
12
12
|
"@graphql-tools/utils": "^8.8.0"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|