-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update cache with mutations #13
Comments
Yes, the documentation definitely needs to be improved. Any PRs to improve it would be greatly appreciated. You'll need to implement an For example: final UpdateCacheHandler<$MyMutation> myMutationHandler = (
CacheProxy proxy,
QueryResponse<$MyMutation> response,
) {
final query = MyQueryToUpdate();
final result = proxy.readQuery(query);
/// update the result
proxy.writeQuery(query, result);
};
class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FlatButton(
child: Text("Click me"),
onPressed: () {
final mutation = MyMutation(
updateCacheHandlerKey: "myMutationHandler",
optimisticResponse: {
/// JSON for optimistic response
},
);
},
);
}
} Then in your config: import 'path/to/file/with/handler';
final updateCacheHandlers = <dynamic, Function>{
"myMutationHandler": myMutationHandler,
};
final options = ClientOptions(updateCacheHandlers: updateCacheHandlers);
final client = Client(
link: link,
options: options,
); |
Hello, thank you! Your package is awesome, really enjoy it :) I'll make an example with mutations, links updates, cache updates within 2 weeks. How do you prefer to do it? Inside your package as standalone app or ..? |
When tried to implement your example has such behavior: CASE 1
Works ok, CASE 2
|
Great! Feel free to open a PR to the existing example or add a second example if you prefer. |
@awaik can you post your full |
Hello, after your last answer, I made the handler that gets info from the cache and from the results of Response.
And I have the mutation
It works like a charm! BUT :) With this code, we get time lag. We should wait for For me, an ideal algorithm should immediately update the cache and, after getting The demo of the time lag is on the attached gif. |
Ferry already does this. You need to pass an |
Thank you! |
Hello guys, one more question - after we make a mutation, what is the best way to update the cache?
Right now in your documentation is example
But for me, it is not clear, how to implement it. Maybe there are obvious approaches, but I just started to use graphql and will be appreciated for example.
Documentation. When I finished things in my app I ready to create one more example for your package for demonstrating mutations, links updates, and cache updates. I quests, that it will be topical questions from your users.
The text was updated successfully, but these errors were encountered: