You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why doesn't the object update automatically when calling mutation?
My workflow: query setting -> mutation updateSetting. After that, if I query settings, It will return an updated object from cache (updated by updateSetting) if they have the same cache-id. It always works on javascript.
But when I did the same with apollo-ios. Cache doest update, it always returns the value from the first time.
Btw, are there any way to print all existing object?
My swift code
Network.shared.apollo.perform(mutation: UpdateMotherTongueMutation(input: input)) { result in
guard (try? result.get().errors) == nil else {
return
}
// call function to query: `SettingQuery`
}
Network.shared.apollo.fetch(query: SettingQuery()) { [weak self] result in
guard let self = self else { return }
let data = try? result.get().data
// save data...
}
My Operations
query Setting {
setting {
id
activeCourse {
id
}
motherTongue {
id
name
code
}
...more fields
}
}
mutation UpdateMotherTongue($input: UpdateSettingInput!) {
updateSetting(input: $input) {
id
motherTongue {
id
name
code
}
}
}
The text was updated successfully, but these errors were encountered:
Hi @guendev, it sounds like you haven't configured a cache key that Apollo iOS can use to normalize the object from your query and mutation. The web client has a more advanced cache and may be doing some of that automatically for you whereas Apollo iOS requires you to be explicit about identifying similar objects.
I suggest reading the Normalizing responses section of the documentation which explains how responses are normalized without a custom cache key. Then move on to reading the Normalizing objects by cache key section which will guide you how to return a custom cache key for your object. Once you've got the custom cache key configured correctly you should get the behaviour you're looking for.
I'm going to close this issue as there is no action for us to take here but I'm happy to continue the conversation with you here if you can't figure out the cache key.
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.
Question
Why doesn't the object update automatically when calling mutation?
My workflow: query setting -> mutation updateSetting. After that, if I query settings, It will return an updated object from cache (updated by updateSetting) if they have the same cache-id. It always works on javascript.
But when I did the same with
apollo-ios
. Cache doest update, it always returns the value from the first time.Btw, are there any way to print all existing object?
My swift code
My Operations
The text was updated successfully, but these errors were encountered: