Khan / Khan/genqlient

Support for pagination when using relay pattern

Open
#357 3 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted needs design
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

**Describe the solution you'd like**
i would like the generated file to expose a function such as:
```
func queryPaged(
ctx context.Context,
client graphql.Client,
pageSize int,
pf func(T) error,
) error {
var cursor *string
resp, err := query(ctx, client, pageSize, cursor)
if err != nil {
return nil
}

for _, edge := range resp.X.Edges {
if err := pf(edge.GetNode()); err != nil {
return err
}
}
return nil
}
```
The issue I have is that this needs to be generated as the "X" is the query endpoint so it's not fixed.
One possibility is to add a generic method to the root query that returns the node inside "data",
Then we can write a generic pager with interfaces and generics.

**Describe alternatives you've considered**
Writing a pager function for every query, but that sort of defeats the purpose of the generator.

**Additional context**
The relay connection paging pattern is described here: https://relay.dev/graphql/connections.htm and here: https://graphql.org/learn/pagination/.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how the generated file exposes the root query and how the relay connection's query endpoint is represented. Review the relay pagination references and compare the proposed generic root-query method with the per-query pager alternative; done means generated clients support reusable pagination without requiring a separate pager for every query.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.