Skip to content

GH-325 - Use GitHub's GraphQL service - #404

Closed
srgyrn wants to merge 40 commits into
mattermost:masterfrom
srgyrn:feature/graphql
Closed

srgyrn wants to merge 40 commits into
mattermost:masterfrom
srgyrn:feature/graphql

Conversation

@srgyrn

@srgyrn srgyrn commented Nov 11, 2020

Copy link
Copy Markdown

Summary

This pull request adds functionality to use Github GraphQL API and replaces REST API with GraphQL API where pull request details are retrieved.

The new graphql package communicates with GraphQL API via https://github.com/shurcooL/githubv4. Anything related to this third party package are encapsulated for decoupling reasons:

  • Query struct needed by githubv4 can be created in Go code with the new graph/query.
  • Response from githubv4 is converted to a local type Response (server/plugin/internal/graphql/response.go). All githubv4 types are converted to native data types.

Ticket Link

#325

@srgyrn
srgyrn requested a review from hanzei as a code owner November 11, 2020 14:40
@mattermod

Copy link
Copy Markdown
Contributor

Hello @srgyrn,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@codecov-io

codecov-io commented Nov 11, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #404 (cd7f26e) into master (4b4bc21) will increase coverage by 5.08%.
The diff coverage is 49.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
+ Coverage   19.34%   24.42%   +5.08%     
==========================================
  Files          11       21      +10     
  Lines        2766     3132     +366     
==========================================
+ Hits          535      765     +230     
- Misses       2193     2305     +112     
- Partials       38       62      +24     
Impacted Files Coverage Δ
server/plugin/api.go 8.12% <0.00%> (+0.66%) ⬆️
server/plugin/internal/graphql/client.go 0.00% <0.00%> (ø)
server/plugin/plugin.go 4.62% <0.00%> (-0.22%) ⬇️
server/plugin/search/pullrequest.go 0.00% <0.00%> (ø)
server/plugin/search/queries.go 0.00% <0.00%> (ø)
server/plugin/internal/graphql/query/union.go 62.50% <62.50%> (ø)
server/plugin/internal/graphql/response.go 63.33% <63.33%> (ø)
server/plugin/internal/graphql/query/builder.go 72.34% <72.34%> (ø)
server/plugin/internal/graphql/query/node.go 87.50% <87.50%> (ø)
server/plugin/internal/graphql/query/scalar.go 88.23% <88.23%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b4bc21...dccb242. Read the comment docs.

@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Nov 11, 2020
@hanzei

hanzei commented Nov 12, 2020

Copy link
Copy Markdown
Contributor

@srgyrn That you very much for raising this PR! Given the sheer size I will need a few days to properly review it.

@hanzei

hanzei commented Nov 12, 2020

Copy link
Copy Markdown
Contributor

@reflog I'm wondering if you are interested in also reviewing this PR as your worked with GraphQL in the past IIRC.

@reflog

reflog commented Nov 12, 2020

Copy link
Copy Markdown
Contributor

@srgyrn thanks for your contribution!
Before we dive into the review - I wanted to ask - what prompted it?
What are we trying to fix? It seems (from a cursory glance at the code) that quite alot of new code was added, so I want to understand the benefit first.

Thanks again!

@reflog
reflog self-requested a review November 12, 2020 11:24
@larkox

larkox commented Nov 12, 2020

Copy link
Copy Markdown
Contributor

@reflog I was there when the ticket was created. The main problem is that for fetching all the needed information for the PRs and issues we now have to do 3 different calls for each open issue assigned. That can consume the easily the allowed rates and takes significant time to load.

Using GraphQL potentially will solve this, since we are able to get the whole information we need in just one query.

You can get a bit more of insight in the linked GH issue.

@reflog

reflog commented Nov 12, 2020

Copy link
Copy Markdown
Contributor

@larkox - awesome. Thanks for the details. I'll get on the review

@reflog

reflog commented Nov 17, 2020

Copy link
Copy Markdown
Contributor

@srgyrn question - what is the reason for implementing so many 'generic' graphql methods, when all we need to do is to construct a struct with proper tags, like:

var q struct {
	RepositoryOwner struct {
		Login        string
		Organization struct {
			Description string
		} `graphql:"... on Organization"`
		User struct {
			Bio string
		} `graphql:"... on User"`
	} `graphql:"repositoryOwner(login: \"github\")"`
}

and execute it?
I don't see the reason for having this 'query builder' pattern and scalar related stuff in this plugin.

@srgyrn

srgyrn commented Nov 17, 2020

Copy link
Copy Markdown
Author

Hey @reflog,

Having worked in projects before which communicate with Elasticsearch without a client like Elastica, I've seen codebases end up getting polluted with so many, so long and sometimes redundant json queries. Also, using the structs expected by githubv4 within the project's code will make the project very dependent to this third party package. You can see in the example structs given in githubv4's repo, package specific data types like githubv4.String, githubv4.HTML or enums are used. So anyone who wants to contribute to the project will have to know and/or learn about them too.

True, my suggested way makes query creating longer and involves more error checks than just writing down a struct. However, it leaves the project's dependency on a third party package just at the query builder bit. Creating scalar queries is all about copying and pasting names and values from the GraphQL Explorer. More complex queries (object, union...) is all about setting children in them.

With the query builder, you don't need to worry about package specific data types at all once required ones are added to the decorator/scalartypes.go. The same thing goes for struct tags as well. You can simply add a new one with validations so there won't be an unnecessary call to the GraphQL API if an unexpected value is set.

@reflog

reflog commented Nov 24, 2020

Copy link
Copy Markdown
Contributor

@srgyrn - in general, I agree with you. Having better abstractions is great for large projects.
This is however seems to me like an overkill for this plugin. But I am about 0/5 on this.
Let's pull a couple more people in for the discussion. cc @ethervoid @agnivade

@agnivade

Copy link
Copy Markdown
Contributor

I really don't have any knowledge about GraphQL, but from a software design perspective - the tradeoff here is codebase size vs too many abstractions. For a big project that heavily uses GraphQL queries, it makes sense to write a low-level library to manage boilerplates in a proper way. But for a small project which uses GraphQL sparingly, I would lean towards using the structs to keep things simple and maintainable.

There is a cost to more code that we add. That has more chance of bugs, more lines of code to maintain and debug. The benefits of additional code should outweigh these costs.

I really don't have much context on the future direction that this plugin will take or how much more GraphQL might be used in future, so I will leave it to the plugin owners to take a call on that.

@srgyrn -
In any case, it is wonderful to see the effort that you have put in to write so much code and also tests for it. Thank you for your time 👍

@ethervoid

Copy link
Copy Markdown

First of all, I love the work you've done here, and seeing the number of tests you made to cover it is amazing. Thank you very much

Regarding the PR itself, I agree with you in the base, it's really useful to decouple third-party libraries and I like the idea but I also agree with the comment from other reviewers, this looks a little overkill for this plugin.

If I may suggest I'd do something like this. Decouple the library using a service so we can mock that up and test it properly. You can also encapsulate the queries inside and in case the situation explodes as you said from past experiences we can connect a new "Client" and use the builder.

Again I want to stress that I think this is amazing work and has a lot of effort poured into it. Thank you

@srgyrn

srgyrn commented Nov 25, 2020

Copy link
Copy Markdown
Author

@reflog @agnivade @ethervoid Thank you for your time and feedback :)

@ethervoid Shall I remove the query builder and integrate the package like the example you've suggested or close the PR?

@reflog

reflog commented Nov 25, 2020

Copy link
Copy Markdown
Contributor

@srgyrn thank you!
Please don't close the PR, just simplify it if possible. @ethervoid suggestion sounds good

@ethervoid

Copy link
Copy Markdown

Agree with @reflog , you can work on this PR :) . Thank you!

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Dec 4, 2020

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking on the discussion point above to get this out of my review queue.

Please ping me once the changes are in.

@mattermod

Copy link
Copy Markdown
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

@jfrerich

Copy link
Copy Markdown
Contributor

Can we get a consensus or proposal from the reviewers that will provide actionable items for the PR author.

Thanks for your work, @srgyrn

@agnivade

Copy link
Copy Markdown
Contributor

The suggested proposal is right here #404 (comment).

@hanzei hanzei added 3: QA Review Requires review by a QA tester and removed 3: QA Review Requires review by a QA tester Lifecycle/1:stale labels Mar 16, 2021
@mattermod

Copy link
Copy Markdown
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

@DHaussermann

Copy link
Copy Markdown

/update-branch

@mattermod

Copy link
Copy Markdown
Contributor

Error trying to update the PR.
Please do it manually.

@DHaussermann

Copy link
Copy Markdown

@hanzei and @srgyrn I'm very sorry. I did not realize this was now only waiting on me.
Can one of you please review the merge conflicts. I'll get this tested.

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Jul 8, 2021
@codecov-commenter

codecov-commenter commented Jul 8, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #404 (c83cc6a) into master (78560ef) will increase coverage by 1.17%.
The diff coverage is 53.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
+ Coverage   19.03%   20.21%   +1.17%     
==========================================
  Files          11       13       +2     
  Lines        3173     3181       +8     
==========================================
+ Hits          604      643      +39     
+ Misses       2529     2495      -34     
- Partials       40       43       +3     
Impacted Files Coverage Δ
server/plugin/api.go 9.17% <0.00%> (+0.62%) ⬆️
server/plugin/plugin.go 4.39% <0.00%> (-0.04%) ⬇️
server/plugin/internal/graphql/client.go 9.09% <9.09%> (ø)
server/plugin/internal/graphql/pullrequest.go 90.24% <90.24%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78560ef...c83cc6a. Read the comment docs.

@DHaussermann

Copy link
Copy Markdown

/update-branch

@mattermod

Copy link
Copy Markdown
Contributor

Error trying to update the PR.
Please do it manually.

@larkox

larkox commented Jul 27, 2021

Copy link
Copy Markdown
Contributor

@srgyrn Would you mind resolving the conflicts? Thanks!

@hanzei

hanzei commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

I've pushed master to this branch, but while testing it a couple of issue were found:

  1. The number of reviews is missing in the RHS
  2. The PR CI information is missing.

Before
Screenshot from 2021-09-03 21-46-15

After
Screenshot from 2021-09-03 21-47-09

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.