【问题标题】:Graphql query results in "Unexpected enum for a scalar" in android using apolloclient使用 apolloclient 在 android 中 Graphql 查询导致“标量的意外枚举”
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 我尝试将$ 前缀为$input。它给出的错误为 error: String 类型的变量输入!用于需要 uuid 的位置
    • 这与您的原始语法错误无关。只需按照错误中的指示更改变量的类型即可。
    • 谢谢你:)。它现在正在工作。 Lint 将其显示为未知字段,所以我认为它是一个错误;)
    猜你喜欢
    • 2017-03-31
    • 2022-10-23
    • 1970-01-01
    • 2016-04-23
    • 2019-06-06
    • 2019-04-09
    • 2018-08-17
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多