News for hackers. Stuff that matters.
Re:Paginating Requests in APIs (2020) by Ambolia on Saturday May 28, 2022 @02:31PM (#31542574)
In the case of hitting multiple REST endpoints for different resources, on each query it's clear what pagination I'm using and combining the data is just appending it to the final list. In each case the partial results are flat and linear.

But in the case of GraphQL, like I may get an incomplete list, or I may get a complete list that will have some fields with missing data, or some combination of both, going down deep depending on the structure of the query. I don't see a clear way to request the missing data without duplicating part of what I already have, and I don't see a clear way to combine the results.

But I may be missing something about GraphQL or something about the tools that makes this simple.

For example something like this:

    {
      users(first: 10000, after: "cursor123") {
        edges {
            cursor
            node {
                id
                name
                friends(first: 10000, after: "cursor235") {
                    edges {
                        cursor
                        node {
                            id
                            name
                        }
                    }
                }
            }
        }
     }
    }
Re:Paginating Requests in APIs (2020) by stevebmark on Saturday May 28, 2022 @04:31PM (#31543534)
Oh. I think you’d handle it the same as rest, make a new individual field query for that friend by ID and ask for the pagination there. I think that would be manual work for graphql or rest, im not aware of anything that does that automatically. It’s also not a case I’ve personally ran into so not sure.
Re:Paginating Requests in APIs (2020) by hamandcheese on Saturday May 28, 2022 @02:57PM (#31542746)
In the relay JS library you can avoid some duplication with fragments. Fragments are pieces of a graphql query that you can include in multiple queries. If you are using flow, the type system will also ensure that you can’t render a component unless you have used the correct fragment in your query.

That said, paginating multiple resources on the same page is still going to be complicated.