Skip to content

Instantly share code, notes, and snippets.

@morgz
Created March 9, 2021 11:54
Show Gist options
  • Save morgz/596b3ee72d2a43f385724e71e379d93d to your computer and use it in GitHub Desktop.
Save morgz/596b3ee72d2a43f385724e71e379d93d to your computer and use it in GitHub Desktop.
ApolloService.shared.client.store.withinReadWriteTransaction({ transaction in
let deletedDroidId = "..."
//
// Update the Query
//
let query = DroidListQuery()
// Update Cache for a Query on a deletion
try transaction.update(query: query) { (data: inout DroidListQuery.Data) in
// Filter out the deleted droid and set the queries entries to be
if let newEntries = data.entries?.filter({$0?.id != deletedDroidId}) {
data.entries? = newEntries
}
}
//
// Update an Object / Fragments which may reference this droid.
//
try transaction.updateObject(ofType: DroidMission.self, withKey: droidMissionId, { (mission: inout DroidMission) in
mission.droid = nil
})
}, callbackQueue: DispatchQueue.global(qos: .background)) { completion in
print("\n\nApollo Cache Completion: \(completion)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment