execute

suspend fun execute(): ApolloResponse<D>

Retrieves a single ApolloResponse from this ApolloCall.

execute calls toFlow and filters out cache or network errors to return a single success ApolloResponse.

execute throws if more than one success ApolloResponse is returned, for an example, if operation is a subscription or a @defer query. In those cases use toFlow instead.

execute may fail due to an I/O error, a cache miss or other reasons. In that case, check ApolloResponse.exception:

val response = apolloClient.execute(ProductQuery())
if (response.data != null) {
// Handle (potentially partial) data
} else {
// Something wrong happened
if (it.exception != null) {
// Handle non-GraphQL errors
} else {
// Handle GraphQL errors in response.errors
}
}

The work is executed on the dispatcher configured in ApolloClient.Builder.dispatcher or a default dispatcher else. There is no need to change the coroutine context before calling execute. See ApolloClient.Builder.dispatcher for more details.

See also

Throws

if the call returns zero or multiple valid GraphQL responses.