3 ms·
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 append
by Ambolia 4y ago
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
}
}
}
}
}
}
}
- hamandcheese 4y agoIn 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.
- stevebmark 4y agoOh. 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.