apollo
apollo copied to clipboard
Add useFragment
Is your feature request related to a problem? Please describe.
We have useQuery
, useMutation
, etc, but there's no useFragment
.
Describe the solution you'd like
I'd like to be able to call useFragment
with a cache ID and fragment document and then react to changes on that fragment, similar to how reactivity works with useQuery
.
const { result } = useFragment({
id: 'user-123',
fragment: gql`
fragment myUser on User { name }
`
})
Describe alternatives you've considered
I've tried using apolloClient.readFragment
, which is documented here but that's not reactive. Also, it will error if part of the fragment isn't in the cache.
Additional context There's an existing apollo-graphql feature request: https://github.com/apollographql/apollo-feature-requests/issues/198
I don't think it's possible to read a fragment reactively.
https://www.apollographql.com/docs/react/caching/cache-interaction/#usefragment
It seems like apollo client supports useFragment
from v3.8.0. It seems like @vue/apollo-composable
is still using the old version of apollo client. is that possible to upgrade this to the latest version and support useFragment
?