shurcooL / githubv4

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
MIT License
1.11k stars 89 forks source link

Consider support for Schema Previews. #34

Open dmitshur opened 6 years ago

dmitshur commented 6 years ago

Similar to GitHub REST API v3, GitHub GraphQL API v4 also has preview APIs that let users try out new features and changes before they become part of the official GitHub API:

https://developer.github.com/v4/previews/

One of the core focuses of this library is:

There are two relevant parts. One, we might want to support the preview APIs, since they're in a way a part of the API. Two, we want to try to do this in an automated way, rather than manually.

Finding a way to support these without in an automated way is very important, because otherwise, this could create a very significant amount of manual work (compared to the work required to develop and maintain the rest of this library).

dmitshur commented 6 years ago

Since this library is largely generated, a viable possibility to consider is creating a separate package that includes support for the schema previews (doing this isn't as viable in go-github because that library is mostly written by hand).

I just want to point that out, but whether or not it's a good idea to split off preview functionality into a different package (e.g., githubv4preview) will need to be determined when investigating this issue. It might not be a good idea.

ItsMeWithTheFace commented 5 years ago

Hey @dmitshur! Are there any updates on this issue?

dmitshur commented 5 years ago

There are no updates on this from my side yet, but there is some new demand for this feature (see #44). I won't have time to work on this in the short term.

If you need this implemented, my recommendation is to experiment with finding a good solution in a fork. It will be helpful if you report your findings in this issue, so that it can eventually be upstreamed. Thank you!

christophermancini commented 5 years ago

We encountered this issue while working on a PR / Fork for the Concourse github-pr-resource. Our internal GHE appliance is currently on 2.16 and we are experimenting with features that are behind the preview Accept header... :(

AlekSi commented 4 years ago

It is also required for https://developer.github.com/v4/mutation/deletepackageversion/

gleich commented 4 years ago

Any update on this?

caquino commented 2 years ago

Hi, I see we have other issues/prs/forks to solve this issue but I'm curious if we had any progress on a official way to handle schema previews, I have no issues with any of the options but as the discussion has been going for a while I wanted to try to get any updates before working on something that feels like a "workaround".

ashleydavies commented 1 year ago

For future readers, I ended up doing this, which seems to be a functioning work-around:

type headerInjector struct {
    base http.RoundTripper
}

func (h *headerInjector) RoundTrip(req *http.Request) (*http.Response, error) {
    req.Header.Add("Accept", "application/vnd.github.merge-info-preview+json")
    return h.base.RoundTrip(req)
}

token := &TokenSource{
    AccessToken: "My OAuth token",
}

...

oauthClient := oauth2.NewClient(context.Background(), token)
oauthClient.Transport = &headerInjector{
    base: oauthClient.Transport,
}

ghQlClient := githubql.NewClient(
    oauthClient,
)

Parameterising the header injector on the previews you are interested in is left as an exercise to the reader 😄