trojanowski / react-apollo-hooks

Use Apollo Client as React hooks
MIT License
2.41k stars 110 forks source link

partialRefetch as an option #128

Open jfrolich opened 5 years ago

jfrolich commented 5 years ago

The partialRefetch option is not available at the moment. Would it be possible to make it available?

More information here: https://www.apollographql.com/docs/react/essentials/queries

jfrolich commented 5 years ago

Actually not having partial refetch enabled will cause issues if you have mutations that return less attributes than a query. The mutation will actually hang the app. I think for useQuery it's probably good to enable partialRefetch by default (it should be default for Query as well, but Apollo didn't enable the default for backwards compatibility reasons).

brabeji commented 5 years ago

Hello @trojanowski! This is actually very necessary functionality according to react-apollo docs:

The default value is false for backwards-compatibility's sake, but should be changed to true for most use-cases.

FWIW linking corresponding code and valuable comment: https://github.com/apollographql/react-apollo/blob/22f8ebf52b26b348d6be905d5b7fbbfea51c1541/src/Query.tsx#L461

layerssss commented 4 years ago

This can be a workaround to manually implement the partialRefetch behaviour.

  // workaround for partialRefetch
  useEffect(() => {
    if (loading) return;
    if (data) return;
    if (error) return;
    // if there's no data, no error or loading, it must be stuck at `partial` state.
    refetch();
  }, [!!data, !!loading, !!error]);