Skip to content

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

Open

Description

@mickmister

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

Activity

  1. added
    Help Wanted
    Up For Grabs
    Difficulty/2:Medium
    Type/Enhancement
    on Jul 12, 2020
  2. removed
    Up For Grabs
    on Mar 3, 2021
  3. added
    Up For Grabs
    on Feb 20, 2023
  4. akshat-khosya commented on Dec 18, 2025

    @akshat-khosya
    Contributor

    I would like to work on it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty/2:MediumHacktoberfestHelp WantedTech/GoTech/ReactJSType/EnhancementUp For Grabs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions