apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.34k stars 2.65k forks source link

[Data masking] Conditionally suspend `useFragment` depending on source of query #11680

Closed jerelmiller closed 1 month ago

jerelmiller commented 6 months ago

useFragment should only suspend if used with a suspenseful hook (e.g. useSuspenseQuery). If it originates from useQuery, we should not suspend.

We will need to determine if we need to provide a loading or pending field in the event it is used with useQuery. If so, this field should not be available when used with useSuspenseQuery.

jerelmiller commented 1 month ago

Discussing this further with the team, we believe this might cause too much confusion, so we aren't planning to pursue this at the moment.

If implemented, this would mean that useFragment would have different behavior depending on its surrounding environment. Determining whether a fragment would suspend or not means traversing the React tree to find the query that produced the data to see if that query is a suspenseful query or not. We believe this has too much unpredictability.

Instead, we plan to add a suspensePolicy option (or something like it) that would allow someone to determine whether to suspend on missing/pending fragment data. This would allow us to provide better type support and behave more predictably, regardless of where the query originated.

github-actions[bot] commented 1 month ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] commented 1 week ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.