This example illustrates a custom error raised on rate limit exceeded.
Specify a onLimit
function. Throws a RateLimitError
with contextual information.
yarn install
node index.js
Navigate to http://localhost:4000/graphql
in a browser.
Server is configured to allow each root field to be queried once every 15 seconds.
Sample query:
{
quote
books {
title
author
}
}
Sample rate limited response:
{
"errors": [
{
"message": "Too many requests, please try again shortly.",
"locations": [
{
"line": 7,
"column": 3
}
],
"path": [
"quote"
],
"extensions": {
"code": "RATE_LIMITED",
"resetAt": "2019-02-03T19:34:16.164Z"
}
},
{
"message": "Too many requests, please try again shortly.",
"locations": [
{
"line": 8,
"column": 3
}
],
"path": [
"books"
],
"extensions": {
"code": "RATE_LIMITED",
"resetAt": "2019-02-03T19:34:16.163Z"
}
}
],
"data": {
"quote": null,
"books": null
}
}