graphql / graphql/graphql-spec

request for clarification/examples of nested cursor pagination

Open
#972 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi folks, I tried asking this both in slack and discord but got no replies. I'm new to GraphQL and am trying to figure out the correct way of implementing query resolvers with cursor based pagination beyond what's currently in the documentation. Here's my sample schema:
```
type Foo {
fooId: ID!
bars: [BarConnection!]!
}

type FooConnection {
pageInfo: PageInfo!
edges: [FooEdge!]!
}

type FooEdge {
node: Foo
cursor: Cursor!
}

type Bar {
fooId: ID!
barId: ID!
}

type BarConnection {
pageInfo: PageInfo!
edges: [BarEdge!]!
}

type BarEdge {
node: Bar
cursor: Cursor!
}

type Query {
foos(after: Cursor, first: Int): FooConnection!
bars(fooID: ID!, after: Cursor, first: Int): BarConnection!
}
```
I'm using gqlgen and implementing all of this in Go. I have pagination working fine for the `bars()` query, but I don't know what the right way to implement the `foos()` query is in respect to the bars field. Both Foo and Bar are tables in my DB but the `Foo.Bars` field is not a DB column - I'm running that select as part of the query.

In my `foos()` resolver I have some basic code that queries the Foo table with pagination. But I'll need to paginate through a list of Bar items for each of those results. I'm not sure how to do that in GraphQL.. I could call the `bars()` resolver from the `foos()` resolver but I''d have to keep a second set of cursor information somewhere.

Does that make sense? I haven't been able to find any examples in the wild, so I'm wondering if there's a better pattern for this use case.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.