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.23k stars 613 forks source link

How to return partial data from cache? #1389

Open jaromirkrotky opened 9 months ago

jaromirkrotky commented 9 months ago

Hello,

I would like to ask you for an advice. I have an application that uses GraphQL with Hive cache. So active users already have in storage object (of course they have a lot of another objects there also): {id: 654c05b10fb2816b81002592, email: null, phone: null, createdAt: 2023-11-08 23:03:29.678, updatedAt: 2023-11-08 23:03:29.678, deletedAt: null, __typename: User}

Now I add new nullable attribute "allowDelete" to schema and regenerate objects with graphql_codegen. For new installation of the app everything works correctly and data look like this: {id: 654c05b10fb2816b81002592, email: null, phone: null, createdAt: 2023-11-08 23:03:29.678, updatedAt: 2023-11-08 23:03:29.678, deletedAt: null, allowDelete: true, __typename: User}

Problem is with the old users who updated previous version of the app, because readFragment$User returns null. I checked that the old user json (the first one) is still in Hive and problem is that it is not loaded because of PartialDataException. It is checking all keys and "allowDelete" is not there.

I investigate that returnPartialData is strictly set to false and should be used just for testing (setting to true will solve it, but I understand that it may cause another problems). So what is the correct way to solve this situation? I need to be able to load older data to start the app and load new data. Create another fragment (with new attribute) do not seems ideal to me, because it means to change a lot of parts of the app (the update is not just about one attribute of one object but a lot of new attributes in a lot of object - all new attributes are nullable).

Thank you, Jaromir