Skip to content

Fix invalid graphql for github enterprise, Fixes 1381#1382

Merged
RMacfarlane merged 1 commit intomicrosoft:masterfrom
yulrizka:fix-github-enterprise
Oct 30, 2019
Merged

Fix invalid graphql for github enterprise, Fixes 1381#1382
RMacfarlane merged 1 commit intomicrosoft:masterfrom
yulrizka:fix-github-enterprise

Conversation

@yulrizka
Copy link
Contributor

see #1381

@yulrizka
Copy link
Contributor Author

yulrizka commented Oct 14, 2019

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

[Debug 130796s 117ms] PullRequestOverviewPanel> initialized without PR
[Debug 130796s 320ms] GitHubRepository> Fetch available merge methods - done
[Debug 130796s 328ms] GithubRepository> Unable to fetch PR: Error: GraphQL error: Field 'isDraft' doesn't exist on type 'PullRequest'

I think best to do regression test before releasing this commit.

@yulrizka
Copy link
Contributor Author

The error about isDraft I think because enterprise doesn't support this yet

Copy link
Contributor

@RMacfarlane RMacfarlane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@yulrizka yulrizka Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do think @RMacfarlane? or is it maybe too much?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yulrizka
Copy link
Contributor Author

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

@yulrizka yulrizka changed the title Fix invalid graphql url for github enterprise, Fixes 1381 Fix invalid graphql for github enterprise, Fixes 1381 Oct 28, 2019
Copy link
Contributor

@RMacfarlane RMacfarlane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yulrizka!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants