Skip to content

Improve our GraphQL client approach #5163

Open

Description

@mislav

Currently, our GraphQL query implementations use at least three different libraries:

This is a mess, both for project maintainers and those who would wish to contribute to GitHub CLI. Furthermore, these different libraries parse and handle GraphQL errors differently and don't always allow access to the full HTTP response, forcing us to have to introduce hacks like #5054 (review)

For the long-term health of this project, I propose that we incrementally migrate over to a single query approach that would satisfy all our needs:

  • Easily write relatively simple, static queries, and define where the parsed data should end up in.
  • Conditionally define that certain GraphQL fields/connections should not be requested based on whether the GHES schema supports them or not.
  • Perform bulk lookups; for example, looking up the GraphQL IDs of N GitHub users specified by their login handle.
  • Ensure that the queries, mutations, and their input types always conform to the GitHub API schema and that the data is never passed around as interface{}.
  • Support partial responses to a query that encountered a resolver error; i.e. support returning the data for parts of the query that succeeded at the same time as returning errors for parts of the query that failed.
  • Access HTTP headers of the response.

Based on my searches, such client library for Go doesn't exist. The one that looks promising is https://github.com/Khan/genqlient which guarantees strict conformity to the server schema, but doesn't seem to allow queries that are dynamic at runtime, nor bulk lookups via GraphQL aliases.

Supersedes #757
Ref. #3549

Activity

  1. added
    tech-debt
    core
    on Feb 3, 2022
  2. yuvi3005 commented on Apr 11, 2022

    @yuvi3005
  3. indrora commented on Sep 7, 2022

    @indrora

    As a dev (and someone who uses the github CLI), I'd like it if this ended up as a GitHub-official library that wasn't "draw the rest of the owl".

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

    coretech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions