Fix invalid graphql for github enterprise, Fixes 1381#1382
Fix invalid graphql for github enterprise, Fixes 1381#1382RMacfarlane merged 1 commit intomicrosoft:masterfrom yulrizka:fix-github-enterprise
Conversation
|
This functionality is not fully tested for github enterprise, This is because it's now start using graphQL instead of the REST API. However batch comments and PR pending review now works! For example, at the time of writing, there is a bug when loading the Description page I think best to do regression test before releasing this commit. |
|
The error about isDraft I think because enterprise doesn't support this yet |
RMacfarlane
left a comment
There was a problem hiding this comment.
Awesome work @yulrizka, thanks for debugging this.
I don't have access to a GitHub Enterprise instance right now but am working on getting one to test with
src/github/queries.gql
Outdated
There was a problem hiding this comment.
I'm wondering if we could still allow fetching this property in cases where it is supported. One option could be to have two different queries for PullRequest - if the first one fails with error about isDraft not existing, fall back to the second that doesn't have it. It's also possible to have a query to see what fields are available (https://developer.github.com/v4/guides/intro-to-graphql/#discovering-the-graphql-api)
There was a problem hiding this comment.
interesting, so there is now way to basically request with is draft field, and server can response with something like null if they couldn't provide it?
I mean we basically need to use 2 different query?
There was a problem hiding this comment.
yeah, the server will just throw instead of sending back a null or undefined value. It looks like there is a way to conditionally include things in the query: https://graphql.org/learn/queries/#directives
So we could use that, after either querying to see if the 'isDraft' field shows up for the endpoint, or just based on whether this is enterprise or github.com
There was a problem hiding this comment.
Hmm this won't be great for future maintainability I'm afraid. I Could imagine if there are 5 version of the API. Each one is adding a new field it's going to get hairy. But I couldn't think of a better solution at the moment
There was a problem hiding this comment.
Yeah, graphql is supposed to be "versionless", but since GitHub enterprise will ship with certain versions of each schema, it makes it really hard to work with. (At least this is my understanding, maybe older enterprise versions eventually get the new fields added to them?) I think the most correct fix would be to first run the query to see what the current schema looks like
query {
__type(name: "PullRequest") {
fields {
name
}
}
}
and then run the actual pull request query with the subset of fields that we want to fetch that are part of that result. This would be very annoying to have to do before every query though. I think isDraft is the only thing we are likely to have a problem with right now, it's currently marked as a preview feature: https://developer.github.com/v4/object/pullrequest/
There was a problem hiding this comment.
Hi @RMacfarlane sorry I didn't not follow up. I was trying something but didn't finish it. Feel free to pick this up. Unfortunately I'm a bit swamp these and the next couple of weeks. Not sure if I can pick it up.
There was a problem hiding this comment.
What I did try is to have different schema for github (existing query.gql) and another one (enterprise.gql). And in the credentials.js detect which version this is running (the enterprise return a header with a version). Based on that it will figure the correct schema and store this on the GithHub interface
The benefit of this is that the controller or the view logic is simpler because it doesn't have to do extra or introspection query. and easily support different version of the API in the future. But unfortunately didn't manage to get it to work yet.
There was a problem hiding this comment.
Hmm I think i managed to get it to work: https://github.com/yulrizka/vscode-pull-request-github/pull/1/files
There was a problem hiding this comment.
what do think @RMacfarlane? or is it maybe too much?
There was a problem hiding this comment.
I think it looks pretty good! I'm a little bit worried about potentially having to maintain separate .gql files for different enterprise versions, but I actually like that this makes it very explicit what properties we expect for both cases. Right now I think there is very little API difference between enterprise versions and we could always use the schema of the oldest supported version. I think this change would be reasonable to merge.
|
@RMacfarlane, I think this PR is ready, but i couldn't test it in GH enterprise. Unfortunately I don't have any instance to test it wih. |
RMacfarlane
left a comment
There was a problem hiding this comment.
Thank you @yulrizka!
see #1381