Repository navigation
Description
Currently, our GraphQL query implementations use at least three different libraries:
-
api.Client.GraphQL()- our rudimentary, in-house query approach that executes string queries and parses them to Go structs. This approach supports dynamic queries at the cost of the caller having to construct them by hand, usually by string interpolation, which lends itself well for queries that look up a variable number of objects in bulk. The downsides are that the queries are not guaranteed to match the server schema and that the query input variables are not type-checked. -
https://github.com/cli/shurcooL-graphql - our fork of https://github.com/shurcooL/graphql, an unmaintained library that is able to generate queries from statically-defined structs. The upside is that the query is generated from the receiver struct itself, making this approach simpler for static queries. The downside is that dynamic or bulk queries are practically infeasible with this library. Wherever we have to make conditional queries for backwards compatibility with older GitHub Enterprise Server instances, we have to revert to
Client.GraphQL(). -
https://github.com/shurcooL/githubv4 - we inconsistently use use types and mutation inputs from this companion to the https://github.com/shurcooL/graphql library, which gives us some assurances that we match types in GitHub's own schema. However, this library is generated from schema from GitHub.com and would not be safe to use for GHES.
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.
Activity
yuvi3005 commentedon Apr 11, 2022
indrora commentedon Sep 7, 2022
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".