-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Report of inconsistent cache results after update from mutation #788
Comments
final defaultPolicies = Policies(fetch: FetchPolicy.networkOnly);
final _client = GraphQLClient(
cache: InMemoryCache(),
link: Link.from(...)
defaultPolicies: DefaultPolicies(
watchQuery: defaultPolicies,
query: defaultPolicies,
mutate: defaultPolicies,
),
); |
@reilem what do you mean by "manually inserting?" If you want changes persisted to the cache, you need to use Here's an example, but you'd need to read the query, modify it, then write it again: |
It's a bit complicated to explain. We did not build our app from the ground up using this library and migrated to GraphQL recently. We already used providers (https://pub.dev/packages/provider) to notify widgets of changes and sembast (https://pub.dev/packages/sembast) to store local changes. We simply changed it to sync these changes using graphql-flutter to our GraphQL backend instead of using a REST API. So, we already had a data access layer before migrating to graphql and so we were unable to use any of the // In some service function
final result = await _graphqlClient.query(QueryOptions(documentNode: UserQueries.getUser));
if (result.hasException) {
// ... etc. any error logic here
}
final user = result.data['user'];
return user; This is not 100% how our app works, but basically the data is returned to the providers and they will notify widgets of the changes. I could not find lots of documentation on how to work with graphQL client directly so lots of this I just discovered by trial and error + github issues. I am assuming that maybe I need to add a call to some update function on the graphQL client to update the cache? Then we could also put this in the docs for people like me using the client directly. |
@reilem ok – in that case it sounds like disabling the cache via Basically what was happening here was that the In the v4 beta, Alternatively, it's possible that you'd be better served building a custom client around your design using the
Anyhow, it seems like this isn't really a bug and more of a design challenge, so I'm gunna go ahead and close this |
Is there a simple way to disable the cache on the client? It's giving us issues, and kinda strange API client would have cache by default...
|
@OllyDixon, take a look at the different policies or implement your own store. If you want a client without a cache, you can use standard libraries for HTTP requests. This client would provide little value without the caching. |
I figured it out, for anyone else who needs help. It still provides value @budde377 :-)
Would be nice if there was just a |
@OllyDixon at one point I looked at making the cache optional, but it created a significant amount of complexity when such usecases are probably better served by using gql_link directly. But, if you wanted to implement a noop store, the interface is pretty small, and you'd basically just make everything a noop I think. |
@reilem mentions in #692 (comment):
@reilem:
update
/ what causes the UI to show[A, B, C, D]
(mutation or query result?)networkOnly
? Is it to force refetch the results from the network using the firstquery
?Broke the documentation aspect into #787
The text was updated successfully, but these errors were encountered: