Rate Limiting
💡
This page is currently under construction and expected to change. Please feel free to reach out to us directly in case you are having any troubles.
Rate limiting is a technique for reducing server load by limiting the number of requests that can be made to a subgraph.
You can use @graphql-mesh/plugin-rate-limit
plugin in order to limit the rate of calling queries
and mutations.
npm i @graphql-mesh/plugin-rate-limit
Example Configuration
mesh.config.ts
import useRateLimit from '@graphql-mesh/plugin-rate-limit'
import { defineConfig } from '@graphql-mesh/serve-cli'
export const serveConfig = defineConfig({
plugins: pluginCtx => [
useRateLimit({
...pluginCtx,
rules: [
{
type: 'Query',
field: 'foo',
max: 5, // requests limit for a time period
ttl: 5000, // time period
// You can use any value from the context
identifier: '{context.headers.authorization}'
}
]
})
]
})
💡
If you want to use schema-first approach with @rateLimit
directive, you can check the Rate
Limiting through @rateLimit
directive documentation.