apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Add useFragment

Open willtpwise opened this issue 4 years ago • 2 comments

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

willtpwise avatar Apr 27 '20 04:04 willtpwise

I don't think it's possible to read a fragment reactively.

Akryum avatar Apr 27 '20 08:04 Akryum

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?

batmanhit avatar Sep 15 '23 14:09 batmanhit