forked from ardatan/graphql-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Rate Limit plugin (ardatan#2292)
* Refactor Rate Limit plugin * chore(dependencies): updated changesets for modified dependencies * Ignore changesets * .. * Fix field identity support --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ba368ba
commit c3dd2c3
Showing
14 changed files
with
633 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@envelop/rate-limiter": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`graphql-rate-limit@^3.3.0` ↗︎](https://www.npmjs.com/package/graphql-rate-limit/v/3.3.0) (from `3.3.0`, in `dependencies`) | ||
- Added dependency [`@graphql-tools/utils@^10.5.4` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.5.4) (to `dependencies`) | ||
- Added dependency [`minimatch@^10.0.1` ↗︎](https://www.npmjs.com/package/minimatch/v/10.0.1) (to `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
'@envelop/rate-limiter': minor | ||
--- | ||
|
||
Now you can define a custom string interpolation function to be used in the rate limit message. This | ||
is useful when you want to include dynamic values in the message. | ||
|
||
```ts | ||
useRateLimiter({ | ||
configByField: [ | ||
{ | ||
type: 'Query', | ||
field: 'search', // You can also use glob patterns | ||
max: 10, | ||
window: '1m', | ||
message: | ||
'My custom message with interpolated values: ${args.searchTerm} and ${context.user.id}' | ||
} | ||
], | ||
interpolateMessage: (message, args, context) => { | ||
return message.replace(/\${(.*?)}/g, (_, key) => { | ||
return key.split('.').reduce((acc, part) => acc[part], { args, context }) | ||
}) | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@envelop/on-resolve': patch | ||
--- | ||
|
||
Refactor the plugin to avoid extra promises with \`mapMaybePromise\` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'@envelop/rate-limiter': minor | ||
--- | ||
|
||
New directive SDL; | ||
|
||
```graphql | ||
directive @rateLimit( | ||
max: Int | ||
window: String | ||
message: String | ||
identityArgs: [String] | ||
arrayLengthField: String | ||
readOnly: Boolean | ||
uncountRejected: Boolean | ||
) on FIELD_DEFINITION | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
'@envelop/rate-limiter': minor | ||
--- | ||
|
||
Programmatic API to define rate limit configuration in addition to directives | ||
|
||
```ts | ||
useRateLimiter({ | ||
configByField: [ | ||
{ | ||
type: 'Query', | ||
field: 'search', // You can also use glob patterns | ||
max: 10, | ||
window: '1m' | ||
} | ||
] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@envelop/core': patch | ||
--- | ||
|
||
Export `mapMaybePromise` and `isPromise` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ examples/sveltekit | |
.next | ||
pnpm-lock.yaml | ||
.husky | ||
.changeset/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.