I need some recommendations on how to solve the fo...
# compose
a
I need some recommendations on how to solve the following problem: Currenlty building a Social media application with a lot of Screens, each Screen contains a List<Post>. I fetch the data from my GraphQL Backend and I do NOT save it into a Room/SQLite database (No Single Source of Truth). If for example Post with ID 1 in the List of Screen A gets updated by the user, it should also update the Post with ID 1 in List of Screen B. Happens sometimes that the same Post is contained in multiple Lists all around the app. How can I reflect the changes I made on Screen A in Screen B? Screen B doesn’t reload everytime because I have
saveState = true
. When I restart the application it of course fetches the up to date data from my graphql endpoint. Is a SSOT system the only way to solve it? Is it even possible in my case due to the constantly changing and user generated content? P.S I’m using GraphQL Apollo + MVVM + Clean Architecture.
i
We had some nice conversations about this previously, specifically around not actually saving your data in Room, etc. but still using a repository layer as the cache for your local copy of the remote data (which is actually your single source of truth): https://kotlinlang.slack.com/archives/CJLTWPH7S/p1657897289085069?thread_ts=1657844159.552379&amp;cid=CJLTWPH7S
a
I’m not quite sure if I understand correctly. In my app I have a Repository which is fetching all the data from my GraphQL endpoint and returning lists with Post elements. For example : fun getTopPosts(): flow = { finishedList = … emit(Response.Success(finishedList) } fun getTrendingPosts(): flow = { finishedList = … emit(Response.Success(finishedList) } Now it could happen that Post with ID 1 is contained in both those lists but each time as a copy because I don’t have a caching strategy or anything that makes sure those two copys of the Post point to the same object in cache. That means, updating element with ID 1 in TopPosts list doesnt effect element with ID 1 in TrendingPosts list. How can I design my repository to return a singleton of element with ID 1 so it reflects all the changes made to it in all the lists across my app?
l
Have you seen the .watch() method in Apollo GraphQL? https://www.apollographql.com/docs/kotlin/caching/query-watchers/
s
apollo-kotlin comes with a built-in caching mechanism too that it sounds like you’d want to enable. Plus you can get an in-memory cache or a SQL backed one. Or both!