android - 使用 apolloclient 的 android 中的 Graphql 查询导致“标量的意外枚举”
问题描述
我正在尝试使用带有 ApolloClient 的 Graphql 从 API 获取一些数据。但这会导致"Unexpected enum for a scalar"。请帮我解决错误。下面是我的代码。
项目查询.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()}")
}
}
})
解决方案
您缺少一个$
- 您的变量定义为,$input
但您将其用作input
. 如果没有$
,解析器假定input
是枚举值而不是变量。
推荐阅读
- android-studio - 如何在同一片段中的创建函数上使用 2 个公共类,受保护的 void?
- python - 二进制数转换为整数
- amazon-web-services - AWS EMR Bootstrap 添加或更新
- r - 从其他文件夹导入excel文件慢
- javascript - 具有 2 个参数真/假资格的函数
- mysql - MySQL程序问题,让我上次输入的用户重新输入
- javascript - 在 Mapboxgl.js 的弹出窗口中添加一个按钮
- reactjs - 在执行子组件之前等待对象可用
- amazon-ec2 - 具有 IOT 数据的可扩展超级账本 v1.4 的应用程序架构
- javascript - 如何将 HTML 与 Python 结合起来?