Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GitHub's GraphQL service to fetch PR details #325

Open
mickmister opened this issue Jul 12, 2020 · 0 comments
Open

Use GitHub's GraphQL service to fetch PR details #325

mickmister opened this issue Jul 12, 2020 · 0 comments
Labels
Difficulty/2:Medium Medium ticket Hacktoberfest Help Wanted Community help wanted Tech/Go Tech/ReactJS Type/Enhancement New feature or improvement of existing feature Up For Grabs Ready for help from the community. Removed when someone volunteers

Comments

@mickmister
Copy link
Contributor

As noted in #170 (comment) , we are making 3 API calls to GitHub's REST API for each PR when we want to display detailed info about each PR in the RHS. Using GitHub's GraphQL API, we can ideally fetch all information in one request.

We can use GitHub's GraphQL explorer to test queries:
https://developer.github.com/v4/explorer

Here is an example query that fetches some of the required data:

query { 
	your_prs: search(first: 100, query: "author:mickmister is:pr is:open archived:false", type: ISSUE) {
        issueCount
        nodes {
            ... on PullRequest {
                id
                title
                body
                mergeable
                reviewDecision
                state
                repository {
                    name
                    nameWithOwner
                }
            
                reviewRequests(first:10) {
                    totalCount 
                }

                reviews(first:10) {
                    totalCount
                    edges {
                        node {
                            state
                        }
                    }
                }
            }
        }
    }

   # your_review_requests: search(first: 100, query: "...", type: ISSUE) { {
   #    ...
   # }
}

One strategy would be to:

  • on page load, fetch all details for all relevant RHS tabs/categories in one GraphQL request
  • do the same when the page "wakes up" or when the user clicks the GitHub refresh button
  • when the user navigates to a specific category, have the backend fetch all up-to-date PRs and details about this category

This is the same basic logic as it currently works, but I think if the backend takes care of the "PR details" logic, the frontend can just say "give me all data I need for this category", the backend can use one GraphQL query without worrying about which specific PR IDs need the details etc. That's taken care of by GitHub in the query.

We can compose queries using https://github.com/shurcooL/githubv4 , which is a Go driver for GitHub's GraphQL service. Much of the querying logic has overlap between the categories, so there should be an opportunity to reuse the querying logic with the structures we create with this library. This is useful for performing the "all-in-one" query versus the "one category" query.

A couple things to note:

  • the org will need to be injected into the query if the config value for the org-scope is set
  • the Unread Messages will still need to be fetched via GitHub's REST API, as they are not supported in their GraphQL implementation
@mickmister mickmister added Help Wanted Community help wanted Up For Grabs Ready for help from the community. Removed when someone volunteers Tech/Go Tech/ReactJS Difficulty/2:Medium Medium ticket Type/Enhancement New feature or improvement of existing feature labels Jul 12, 2020
@mickmister mickmister removed the Up For Grabs Ready for help from the community. Removed when someone volunteers label Mar 3, 2021
@hanzei hanzei added the Up For Grabs Ready for help from the community. Removed when someone volunteers label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty/2:Medium Medium ticket Hacktoberfest Help Wanted Community help wanted Tech/Go Tech/ReactJS Type/Enhancement New feature or improvement of existing feature Up For Grabs Ready for help from the community. Removed when someone volunteers
Projects
None yet
Development

No branches or pull requests

4 participants