Setting the file. One moment.
Subchapter 5.3
references/operations.mdMarkdown2 KBView on GitHub
This reference covers queries, mutations, subscriptions, and response handling.
.graphql files under src/main/graphql/ (or src/commonMain/graphql/ for multiplatform).GetUserQueryUpdateUserMutationOnMessageReceivedSubscription.graphql file, and name it with the operation name, e.g. GetUserQuery.graphql for GetUserQuery.Use generated query classes and call them with .execute().
suspend fun loadUser(id: String): User {
val response = apolloClient.query(GetUserQuery(id)).execute()
val data = response.dataOrThrow()
return data.user.toDomain()
}.execute() which can only accept one emission, instead use toFlow().fun observeMessages() {
apolloClient.subscription(GetMessagesSubscription()).toFlow().collect { response ->
val messages = response.dataOrThrow().messages
// Update UI
}
}response.exception.response.errors.data may be present even if there are errors, but data will be null if exception is present.