Replies: 1 comment 1 reply
-
@benjie I know that Relay supports a custom directive |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The GraphQL Cursor Connections Specification is awesome! For me, it's one of the best practices in GraphQL.
A common way of satisfying
hasNextPage
is to attempt to fetch an additional node, if it exists then we have a next page:Now consider we want to stream edges from our connection:
Streaming these edges is not particularly useful, because in order to calculate
hasNextPage
we have to fetch all the rows up front anyway. (There is still some utility, but not as much as we would get with a plain list.)I imagine this must have come up at Facebook, perhaps @Keweiqu can shed some light. My guess is instead of streaming like this you simply defer the entire
allUsers
field.This issue I think actually surfaces a larger modelling problem. In resolver-land, it's the
allUsers
field that actually performs the fetch, andedges
/pageInfo
are calculated on the result. Ideally we'd have a way for the connection field itself (allUsers
) to stream:we want its resolver to yield an async iterable, such that the edges come in one by one, and when done, the pageInfo populates.
However, that definitely doesn't mesh with what we've designed so far. A workaround would be to wrap the
pageInfo
in@defer
:If
allUsers
returns an async iterable as part of the result of its resolver, thenedges
can consume this iterable directly, andpageInfo
can wait for the iterable to end and then populate. But I'm concerned it's not very ergonomic, and that people are going to fall in the "pit of failure" by streaming the edges but not deferring the other selections. Connections are such a common pattern, it feels like we should make sure it's well supported by@stream
without requiring a lot of user education.Would love to get your thoughts on this.
Beta Was this translation helpful? Give feedback.
All reactions