首页 > 解决方案 > 使用 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()}")
                }
            }
        })

标签: androidkotlingraphqlapollo-client

解决方案


您缺少一个$- 您的变量定义为,$input但您将其用作input. 如果没有$,解析器假定input是枚举值而不是变量。


推荐阅读