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
How to invalidate cahce #837
Comments
what you described is how the client should work. The only fetch policy that should use the cache and ignore the network is My best guess is that you've created optimistic data in the cache somehow, that is being merged into the result you're retrieving from the server. |
Ok, I am not sure what code do you need but here you go client code and fetching code: GraphQLClient createGraphqlClient({
@required String uri,
String subscriptionUri,
}) {
Link link = HttpLink(uri);
var authTokenService = GetIt.instance<AuthTokenService>();
link = LocaleLink().concat(link);
link = authTokenService.graphQLFreshLink.concat(link);
if (subscriptionUri != null) {
final WebSocketLink websocketLink = WebSocketLink(subscriptionUri,
config: SocketClientConfig(
autoReconnect: true,
delayBetweenReconnectionAttempts: Duration(seconds: 2),
inactivityTimeout: null,
initialPayload: () {
return authTokenService.addAuthHeader(EnvVariables.currentHost);
}));
link = Link.split(
(request) => request.isSubscription,
websocketLink,
link,
);
}
link = errorLink.concat(link);
final client = GraphQLClient(
defaultPolicies: DefaultPolicies(query: Policies(fetch: FetchPolicy.noCache)),
cache: GraphQLCache(store: HiveStore()),
link: link,
);
return client;
} I have added locale link class LocaleLink extends Link {
@override
Stream<Response> request(
Request request, [
NextLink forward,
]) async* {
request.variables.putIfAbsent('locale', () => AppLocalizations.locale.languageCode);
yield* forward(request);
}
}
and fresh link if from package fresh_graphql and loke like this FreshLink<OAuth2Token>(
tokenStorage: _inMemoryTokenStorage,
refreshToken: _refreshToken,
tokenHeader: _tokenHeader,
shouldRefresh: (gql_exec.Response result) {
if (!hasToken) {
return false;
}
var hasAuthError = result.errors != null &&
result.errors
.where((e) =>
e.extensions != null &&
e.extensions['code'] != null &&
e.extensions['code'] == 'UNAUTHENTICATED')
.toList()
.length !=
0;
return hasAuthError;
},
) not sure if you need LocaleLink and graphQLFresh links? and gql call look sliek this: var results = await _graphQLClient
.query(QueryOptions(document: getAllInquiries, variables: <String, dynamic>{
'userId': _userStore.id,
'currentPage': _store.currentPage,
})).withTimeout(); where |
|
As i mentioned above i have tried watchQuery also. Second result returns also not updated (cached). More then that - if query does not work with cache it should return not cached result at all. But as i said - it returns not updated data unless i set noCache policy.
It looks like query uses cahce...
|
Check the I consider it highly unlikely that the client is broken in this way, but it is always possible. |
I hear what you are saying and will try soon watchQuery ant paste all responses but for now with query i get this: As you can see DB and postman gives approvedByCustomer: false while gql client gives true It was enough for me to set cacheAndNetwork policy which according to what you said should not work at all with query :( |
well, if you can distill the problem into a test case and PR it against |
Well, I cannot imagine how to do this because I need to host api that you have access do in order to change data and create whole client. But VĮ an site that you have testing env and with all code given above you can easily test it. You can ignore links because I tested without them. I think this c should be a priority one because it looks like swiss issue keeping in mind that v query should not work with cache at all... |
Tests are written with mocks. That is how we isolate and reproduce behavior: https://github.com/zino-app/graphql-flutter/blob/beta/packages/graphql/test/graphql_client_test.dart#L274 I think your issue can be best distilled with two subsequent |
So I think you are the best candidate to test it. I would like to help but have to work on MVP hard. I hopw that before our release (2 month) thi sissue will be resolved and i can get benefits of caching and its invalidation :) |
@vytautas-pranskunas- your time is not more valuable than mine. As you've said, if this is an issue then it is massive, and I will fix it, but I don't know that anyone else has this issue. I don't even know what version you're on. Creating a test case is the only way you can convince me that the mistake is with the library. I consider the way you're behaving here very inconsiderate. You are acting like maintaining this project is my job, as well as interpreting your incredibly sloppy bug description that is almost indecipherable because of your lack of interest in correcting your spelling mistakes. |
wooowww... lets step back a bit :) I did not mean that ;) take things easy... Comming from other side - i am maitainer and owner of 2 state managment libraries for React and Angular and if somebody reports a bug I consider it as mine responsibility to fix it over all. Thats might be the reason why my communication made you think that i am pushing fix on you - but again - if you not an owner then lets step back :) My spelling mistakes - most of the time I am answering from phone with autocompletion... But you are right - i should pay more attention to it. not sure what do you mean "sloppy" description of the bug because it is clear and can be described like this:
I gave enough examples and screenshots but can try to give better one :) server returns this data:
client receives this data:
Did this make more sense? |
btw I am on version: |
And one more thing: Convincing you it is not the purpose of all this ;) I just have reported a bug and it is up to maintainer to investigate and fix it or not. I am not demanding consumers of my librarires to get familiar with code i wrote, write tests and convince me - I just feel responsibility for others who have put trust and chosen my library :) Bwt - I am contributing to less time consuming libraries. For example yesterdays PR: https://github.com/404shades/Gender-Selection-Flutter/pulls |
Apologies if I projected intent on you. I added a test for what we were discussing before (9f3f1dd), but based on your update this is probably expected due to the normalization layer: if I'm understanding correctly tour |
realized that there weren't very good docs for normalization, so I added some https://github.com/zino-app/graphql-flutter/tree/beta/packages/graphql#normalization |
Hmm yes that's a thing. I am not really sure now which way to go because this is just one specific response from big app and to create custom global dataIdFromObject based on id and approvedByCustomer property would be not good. Because other requests does not have property. Unless there is a possibility to provide dataIdFromObject per request? |
There isn't, but if it's a property of the nested object's data type you could just check for it in Actually, what might be best here is for you to use |
Can you give e an example of |
See https://github.com/gql-dart/gql/tree/master/gql#packagegqllanguagedart. The only difference between it and our |
Hmm looks like hacking. Anyway it would be nice to have v some simple solution like type policy for normalization where we could define what is id for example this kind v of map: Where key is path to nested document and value - I'd key |
This actually bigger problem than I thought especially for document db like MongoDB. For example I store profile picture of customer as part of other documents. So if I have orders collection which might contain records with old and new customer profile pictures but I will always get one picture (not sure which old or new) if I send them along with customerId 😕 |
In terms of controlling cache rereads, there is
But I think this is more a deeper-cutting data modeling problem. We base our normalization scheme largely on apollos, so you might find this useful: https://www.apollographql.com/blog/demystifying-cache-normalization/ |
That's exactly what I am taking about - here is no problems with relational DB as they said - target is to not have data duplication. However in document db data duplication is common if that data belongs together... So I have to think how to tackle this... Thank anyway for all 🙂 |
Hello,
query as well as watchQuery returns cashed properties when fetching the list and this list contains other similar records with same ids but different values. (btw - while talking here i realized more about nature of this bug thats why it took more time to put cleaner description)
I gave enough examples and screenshots but can try to give better one :)
server returns this data:
client receives this data:
The text was updated successfully, but these errors were encountered: