I tried to implement optimistic updates into my android app, here is what the docs say:
apolloClient.mutation(SetTodocompletedMutation(id = "1", completed = true))
.optimisticUpdates(
SetTodocompletedMutation.Data(
id = "1",
completed = true,
)
)
.execute()
For me I cannot simply pass my arguments in Data(), in my case I can only pass a Data class:
graphqlAPI.mutation(SetFavoriteMutation(favoritedPost.id))
.optimisticUpdates(
SetFavoriteMutation.Data(
SetFavoriteMutation.SetFavorite(name = "Test", favorites = 20, id = favoritedPost.id, "Post")
)
)
.execute()
Why is it different in my case? I’m also forced to pass a __typename as the last parameter of the data class instance which is also different to the explanation in the docs.
Here is my generated apollo mutation class:
public data class Data(
public val setFavorite: SetFavorite?,
) : Mutation.Data
public data class SetFavorite(
public val name: String,
public val favorites: Int?,
public val id: Int,
public val __typename: String,
)
My watchers get notified but the Post is not getting updated with the name “Test” that I specified in the optimistic SetFavoriteMutation.
Why does my generated class looks different to the one in the docs? Why cant I pass the arguments directly and have to pass a dataclass instead with __typename parameter