gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
593 stars 113 forks source link

Manually update the ferry data #596

Open simplenotezy opened 3 months ago

simplenotezy commented 3 months ago

Let's say you have a normal query (https://ferrygraphql.com/docs/queries) but you wish to programatically update the data, depending on some other logic; how can this be done?

Or even build a request with som predefined data / set the cache with some predefined data?

The issue is that I have a query to fetch all genres, and for each genre, there's 10 movies. When you scroll further in the movie list, I need to load 10 more movies (but not 10 more genres).

One way to achieve this would be to have a query to fetch movies for a genre; and when you fetch the genres list, the cache for the queries to fetch movies is set to the data from the genres query.

knaeckeKami commented 3 months ago

Yes, there are multiple points where you could hook in. I'm not sure what your schema and queries look like, so it's difficult to give concrete advice.

But general pointers are: The .request() method returns a stream, and the stream keeps listening to cache updates.

So you can