Ad

Shopify With Apollo Client "Failed To Parse Http Response"

- 1 answer

I'm facing a parsing issue on products query. Here's my query:

query getProducts($productCount: Int, $variantsCount: Int) {
products(first: $productCount) { edges { node { title variants(first: $variantsCount) { edges { node { title id image { originalSrc } } } } } } } }

This query works fine if i exclude image { originalSrc }. So image URL parsing is causing an issue. Other related info:

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

Thanks.

Ad

Answer

Before testing with calls, you should validate your calls first. Using GraphQL is much easier if you use the tools provided to build your queries and test them that way. Then once you start getting data back, plug the working queries into your code to get results. Much easier than trying to guess correct call structures like you are.

As an example, this App can be most helpful: https://shopify-graphiql-app.shopifycloud.com/login

Ad
source: stackoverflow.com
Ad