zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 622 forks source link

Relay-style `useFragment` hook #1372

Open satvikpendem opened 1 year ago

satvikpendem commented 1 year ago

Is your feature request related to a problem? Please describe. I am currently using the graphql_flutter package for GraphQL in my Flutter application. However, I've used Relay before in React and I like its philosophy of compiling fragments into a full query so that the application never over or underfetches data. It uses a useFragment hook to do so. This feature allows components to specify their data requirements and automatically subscribe to updates to the fragment data.

Describe the solution you'd like I would like to see the addition of a useFragment hook or a similar feature in the graphql_flutter package. This feature should allow Flutter components to specify their data requirements using GraphQL fragments. The components should then be automatically subscribed to updates to the fragment data. If the data for the specified fragment is updated anywhere in the app, the component should automatically re-render with the latest updated data.

Describe alternatives you've considered While there are other GraphQL packages available for Flutter, none of them seem to offer a feature similar to Relay's useFragment hook. I have not been able to find something similar.

There's a good article on the benefits of a Relay style approach over the more popular Apollo approach, and even Apollo is creating their own useFragment hook and implementation, as well as the team behind GraphQL codegen designing a similar approach too.