使用Apollo客户端的Shopify“无法解析http响应”

时间:2019-03-11 12:01:03

标签: android shopify apollo-client

我正面临产品查询的解析问题。这是我的查询:

  

query getProducts($ productCount:Int,$ variantsCount:Int){
  产品(第一个:$ productCount){       边缘{         节点{           标题           Variants(First:$ variantsCount){             边缘{               节点{                 标题                 ID                 图片 {                   originalSrc                 }               }             }           }         }       }}

如果我排除image { originalSrc },则此查询工作正常。因此,图像URL解析会引起问题。其他相关信息:

ApolloClient

apolloClient = ApolloClient.builder()
                .serverUrl("https://" + SHOP_URL + "/api/graphql")
                .okHttpClient(okHttpClient)
                .defaultHttpCachePolicy(HttpCachePolicy.NETWORK_ONLY)
                .build();

StackTrace

Caused by: java.lang.IllegalArgumentException: Can't map GraphQL type: URL to: class java.lang.Object. Did you forget to add custom type adapter?
        at com.apollographql.apollo.response.ScalarTypeAdapters.adapterFor(ScalarTypeAdapters.java:29)
        at com.apollographql.apollo.internal.response.RealResponseReader.readCustomType(RealResponseReader.java:192)
        at com.XXX.XXXX.GetProductsQuery$Image$Mapper.map(GetProductsQuery.java:1027)
        at com.XXX.XXXX.GetProductsQuery$Node1$Mapper$1.read(GetProductsQuery.java:935)
        at com.XXX.XXXX.GetProductsQuery$Node1$Mapper$1.read(GetProductsQuery.java:932)
        at com.apollographql.apollo.internal.response.RealResponseReader.readObject(RealResponseReader.java:138)
        at com.XXX.XXXX.GetProductsQuery$Node1$Mapper.map(GetProductsQuery.java:932)
        at com.XXX.XXXX.GetProductsQuery$Edge1$Mapper$1.read(GetProductsQuery.java:803)
        at com.XXX.XXXX.GetProductsQuery$Edge1$Mapper$1.read(GetProductsQuery.java:800)
        at com.apollographql.apollo.internal.response.RealResponseReader.readObject(RealResponseReader.java:138)
        at .GetProductsQuery$Edge1$Mapper.map(GetProductsQuery.java:800)
        at com.XXX.XXXX.GetProductsQuery$Variants$Mapper$1$1.read(GetProductsQuery.java:704)
        at com.XXX.XXXX.GetProductsQuery$Variants$Mapper$1$1.read(GetProductsQuery.java:701)
        at com.apollographql.apollo.internal.response.RealResponseReader$ListItemReader.readObject(RealResponseReader.java:312)
        at com.XXX.XXXX.GetProductsQuery$Variants$Mapper$1.read(GetProductsQuery.java:701)
        at com.XXX.XXXX.GetProductsQuery$Variants$Mapper$1.read(GetProductsQuery.java:698)
        at com.apollographql.apollo.internal.response.RealResponseReader.readList(RealResponseReader.java:165)
        at com.XXX.XXXX.GetProductsQuery$Variants$Mapper.map(GetProductsQuery.java:698)
        at com.XXX.XXXX.GetProductsQuery$Node$Mapper$1.read(GetProductsQuery.java:597)
        at com.XXX.XXXX.GetProductsQuery$Node$Mapper$1.read(GetProductsQuery.java:594)
        at com.apollographql.apollo.internal.response.RealResponseReader.readObject(RealResponseReader.java:138)
        at com.XXX.XXXX.GetProductsQuery$Node$Mapper.map(GetProductsQuery.java:594)
        at com.XXX.XXXX.GetProductsQuery$Edge$Mapper$1.read(GetProductsQuery.java:478)
        at com.XXX.XXXX.GetProductsQuery$Edge$Mapper$1.read(GetProductsQuery.java:475)
        at com.apollographql.apollo.internal.response.RealResponseReader.readObject(RealResponseReader.java:138)
        at com.XXX.XXXX.GetProductsQuery$Edge$Mapper.map(GetProductsQuery.java:475)
        at com.XXX.XXXX.GetProductsQuery$Products$Mapper$1$1.read(GetProductsQuery.java:379)
        at com.XXX.XXXX.GetProductsQuery$Products$Mapper$1$1.read(GetProductsQuery.java:376)
        at com.apollographql.apollo.internal.response.RealResponseReader$ListItemReader.readObject(RealResponseReader.java:312)
        at com.XXX.XXXX.GetProductsQuery$Products$Mapper$1.read(GetProductsQuery.java:376)
        at com.XXX.XXXX.GetProductsQuery$Products$Mapper$1.re

谢谢。

1 个答案:

答案 0 :(得分:0)

在进行通话测试之前,您应该先验证通话。如果使用提供的工具来构建查询并以此方式进行测试,则使用GraphQL会容易得多。然后,一旦您开始获取数据,就将可运行的查询插入代码中以获取结果。比尝试像您一样猜测正确的呼叫结构要容易得多。

例如,此应用程序可能最有用:https://shopify-graphiql-app.shopifycloud.com/login