You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type Movie {
id: ID!
...
numberOfReviews: Int!
reviews: [Review!]!
}
and that reviews are extremely costly to fetch. Often one would therefore just display numberOfReviews, and fetch the full list only when needed. However, also both fields can be selected in the same query.
Now, since numberOfReviews needs to be fast, it is cached a bit somewhere and only updated periodically or when the full list is requested. The problem is that numberOfReviews is fetched first and during the slow operation of fetching the list, an additional review can be posted and returned. The count field would then not match the actual number of reviews returned.
This is expected to happen if these were independent services. And it can also be explained by the way GraphQL works. But the returned object is nonetheless inconsistent and it would be easy to correct by simply adjusting the count field in a post-process step. Does such a mechanism exist?
On a similar note: If fetching numberOfReviews itself was also not too cheap, and since it can be calculated from the list of reviews, is there a mechanism to skip fetching it if both fields are selected?
I know that one could put everything into the Movie fetcher, but at least for the first case SelectionSet acrobatics seems like an ugly solution for a simple problem. Is there a better way?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
Let's assume we have the following type:
and that
reviews
are extremely costly to fetch. Often one would therefore just displaynumberOfReviews
, and fetch the full list only when needed. However, also both fields can be selected in the same query.Now, since
numberOfReviews
needs to be fast, it is cached a bit somewhere and only updated periodically or when the full list is requested. The problem is thatnumberOfReviews
is fetched first and during the slow operation of fetching the list, an additional review can be posted and returned. The count field would then not match the actual number of reviews returned.This is expected to happen if these were independent services. And it can also be explained by the way GraphQL works. But the returned object is nonetheless inconsistent and it would be easy to correct by simply adjusting the count field in a post-process step. Does such a mechanism exist?
On a similar note: If fetching
numberOfReviews
itself was also not too cheap, and since it can be calculated from the list of reviews, is there a mechanism to skip fetching it if both fields are selected?I know that one could put everything into the
Movie
fetcher, but at least for the first case SelectionSet acrobatics seems like an ugly solution for a simple problem. Is there a better way?Beta Was this translation helpful? Give feedback.
All reactions