Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request for clarification/examples of nested cursor pagination #972

Open
rafaelvanoni opened this issue Jul 18, 2022 · 1 comment
Open

Comments

@rafaelvanoni
Copy link

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.

@giosueDelgado
Copy link

Up this question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants