使用 apolloclient 的 android 中的 Graphql 查询导致“标量的意外枚举”

Ram*_*gde 1 android kotlin graphql apollo-client

我正在尝试使用 Graphql 和 ApolloClient 从 API 获取一些数据。但它导致“标量的意外枚举”。请帮我解决错误。下面是我的代码。

ItemsQuery.graphql

query fetchCategoryItems($input : String!) {
__typename
items(where: {categoryUuid: {_eq: input}}) {
    categoryUuid
    description
    image
    name
    ..... // some more items
}
Run Code Online (Sandbox Code Playgroud)

}

活动代码。

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()}")
                }
            }
        })
Run Code Online (Sandbox Code Playgroud)

Dan*_*den 7

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