githubv4 icon indicating copy to clipboard operation
githubv4 copied to clipboard

Consider support for Schema Previews.

Open dmitshur opened this issue 6 years ago • 8 comments

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:

  • Support all of GitHub GraphQL API v4 via code generation from schema.

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 avatar Apr 26 '18 15:04 dmitshur

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.

dmitshur avatar Apr 26 '18 16:04 dmitshur

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

ItsMeWithTheFace avatar Jun 27 '19 15:06 ItsMeWithTheFace

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!

dmitshur avatar Jun 27 '19 15:06 dmitshur

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... :(

christophermancini avatar Aug 07 '19 18:08 christophermancini

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

AlekSi avatar May 08 '20 08:05 AlekSi

Any update on this?

gleich avatar Sep 02 '20 15:09 gleich

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".

caquino avatar Jan 28 '22 12:01 caquino

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 😄

ashleydavies avatar Jul 28 '23 23:07 ashleydavies