githubkit icon indicating copy to clipboard operation
githubkit copied to clipboard

Differences between regular GH and GHES API graphql endpoints

Open fau-st opened this issue 1 year ago • 4 comments
trafficstars

Hello,

I'm successfully using this library to interact with a GitHub Enterprise Server through the REST API. As you may know, for GHES, the REST API endpoint is located at https://[hostname]/api/v3/ instead of https://api.github.com/. So far so good as I can use the base_url parameter when building a GitHub object.

However, the troubles appear when I try to make a request using the graphql endpoint. Indeed, GHES uses this endpoint for graphql : https://[hostname]/api/graphql/ (the v3/ suffix is no longer present) and I can no longer use base_url because it's different whether I use the REST or graphql API.

Sample code :

from githubkit import (
    AppAuthStrategy,
    GitHub,
)

INSTALLATION_ID: int = ...
auth_strategy: AppAuthStrategy = ...

gh = GitHub(
    auth_strategy.as_installation(INSTALLATION_ID),
    base_url='https://ghes-hostname/api/v3',
)

gh.graphql('query { viewer { login } }')
# >>> githubkit.exception.RequestFailed: Response(404 Not Found, data_model=typing.Any)

Here, githubkit successfully retrieves a token through the REST API to use for the graphql query but then this query is made against https://ghes-hostname/api/v3/graphql and a 404 response is returned.

I'd like to know your opinion on this as supporting GHES might not be your priority. Let me know if you need more information.

fau-st avatar Sep 19 '24 10:09 fau-st