【发布时间】:2020-05-27 21:30:17
【问题描述】:
我正在尝试使用带有 ApolloClient 的 Graphql 从 API 获取一些数据。但这会导致 “标量的意外枚举”。请帮我解决错误。下面是我的代码。
ItemsQuery.graphql
query fetchCategoryItems($input : String!) {
__typename
items(where: {categoryUuid: {_eq: input}}) {
categoryUuid
description
image
name
..... // some more items
}
}
活动代码。
val client = ApolloClientInstance.getInstance()
val categoryId = "random_id"
client.query(FetchCategoryItemsQuery.builder().input(categoryId.toString()).build())
.responseFetcher(ApolloResponseFetchers.NETWORK_FIRST)
.enqueue(object : ApolloCall.Callback<FetchCategoryItemsQuery.Data>() {
override fun onFailure(exception: ApolloException) {
Logger.debug(TAG, "${exception.message}")
}
override fun onResponse(response: Response<FetchCategoryItemsQuery.Data>) {
Logger.debug(TAG, "${response.data()?.items()?.size}")
Logger.debug(TAG, "error: ${response.errors()[0].message()}")
}
}
})
【问题讨论】:
标签: android kotlin graphql apollo-client