docs icon indicating copy to clipboard operation
docs copied to clipboard

GraphQL errors, and especially rate limit errors, are not documented

Open FiloSottile opened this issue 2 years ago • 5 comments
trafficstars

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/graphql

What part(s) of the article would you like to see updated?

There seems to be no documentation for what the GraphQL API returns on error conditions.

In particular, I can't find what error code to expect once the rate limit is exceeded. I see I can use the rateLimit query field to get information on how many points I have left when a query succeeds, but I can't rely on that alone as I might have a few points left and then make a very large request.

I assume a rate limit error will also provide a resetAt field, but I have no idea under what name or path. The only way I can see to develop an app that will handle rate limits gracefully is to burn 5000 points and hit the error to learn how it looks like.

Additional information

No response

FiloSottile avatar Dec 10 '22 17:12 FiloSottile

Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

welcome[bot] avatar Dec 10 '22 17:12 welcome[bot]

@FiloSottile Thanks so much for opening an issue! I'll triage this for the team to take a look :eyes:

cmwilson21 avatar Dec 12 '22 21:12 cmwilson21

The response code will be 200, and the errors field will indicate that you have a rate error. For example:

With GitHub CLI, a rate limited response looks like:

% gh api graphql -f query='{
  viewer {
    login
    isSiteAdmin
  }
}'
{
  "errors": [
    {
      "type": "RATE_LIMITED",
      "message": "API rate limit exceeded for user ID 9961."
    }
  ]
}
gh: API rate limit exceeded for user ID 9961.

With curl, a rate limited response looks like:

curl -w "%{http_code}" https://api.github.com/graphql \
  -H "Authorization: token $GITHUB_TOKEN" \
  --compressed \
  --data-binary '{"query":"{\n\t__schema{\n queryType {\n fields{\n name\n }\n }\n }\n}"}'
{"errors":[{"type":"RATE_LIMITED","message":"API rate limit exceeded for user ID 9961."}]}
200

You or anyone else is welcome to add this info to the docs.

skedwards88 avatar Dec 14 '22 00:12 skedwards88

Thank you. Is there a response header for the retryAt time or some other way to acquire it?

FiloSottile avatar Dec 14 '22 01:12 FiloSottile

yes, there's an x-ratelimit-reset, along with some other useful headers

% curl -vvv https://api.github.com/graphql \
  -H "Authorization: token $GITHUB_TOKEN" \
  --compressed \
  --data-binary '{"query":"{\n\t__schema{\n queryType {\n fields{\n name\n }\n }\n }\n}"}' \
  2> >(grep x-ratelimit)
< x-ratelimit-limit: 5000
< x-ratelimit-remaining: 0
< x-ratelimit-reset: 1670985544
< x-ratelimit-used: 5000
< x-ratelimit-resource: graphql

mmrobins avatar Dec 14 '22 01:12 mmrobins

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/graphql

What part(s) of the article would you like to see updated?

There seems to be no documentation for what the GraphQL API returns on error conditions.

In particular, I can't find what error code to expect once the rate limit is exceeded. I see I can use the rateLimit query field to get information on how many points I have left when a query succeeds, but I can't rely on that alone as I might have a few points left and then make a very large request.

I assume a rate limit error will also provide a resetAt field, but I have no idea under what name or path. The only way I can see to develop an app that will handle rate limits gracefully is to burn 5000 points and hit the error to learn how it looks like.

Additional information

No response

Hello are you there

china170 avatar Mar 08 '23 04:03 china170

I'm trying to use this query to fetch a single file from my repo:

{
  repository(owner: "myorg", name: "myrepo") {
    content: object(expression: "develop:src/locale_files/de/LC_MESSAGES/django.po") {
      ... on Blob {
        text
      }
    }
  }
}

And the resulting text is truncated at 510292 - there's a flag in the result that confirms that the contents are truncated, but it would've been nice to know that in advance, instead of spending time getting this to work only to find it's completely useless.

pgcd avatar Mar 31 '23 14:03 pgcd

@pgcd - you might find this article useful when you're doing future work using the GraphQL API: Resource limitations - GitHub Docs.

felicitymay avatar Sep 19 '23 13:09 felicitymay