Skip to content

2.0 - Update cache after a mutation #3618

@Vincz

Description

@Vincz

Question

Hi guys,

I'm trying to migrate my project to the new API.
My use case is quite simple.
I call a mutation that add an object, then I want to add this object to a list in the cache so I don't have to request the complete list again.

Here is my code converted:

func addList(name: String) async throws -> String? {      
        guard let data = try await mutation(mutation: CreateListMutation(name: name)) else { return nil }
        let newList = data.list

        try await apollo.store.withinReadWriteTransaction { transaction in
            let cacheMutation = ListsLocalCacheMutation()
            try await transaction.update(cacheMutation) { (data: inout ListsLocalCacheMutation.Data) in
                let list = ListsLocalCacheMutation.Data.List(_dataDict: newList.__data)
                data.lists.append(newList)
            }
        } 
    }

So, before the update I was creating an ListsLocalCacheMutation.Data.List object from the data of a CreateListMutation.Data.List object.
I'm not even sure that was the proper way but it worked.
Now, I can't access the __data property anymore cause I get the error '__data' is inaccessible due to '@_spi' protection level

What would be the new and proper way to handle this? Do I have the choice or do I need to recreate manually by resettings all the properties one by one, with something like that:

let list = ListsLocaleCacheMutation.Data.List(name: newList.name, etc....)

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that have a question which should be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions