Shopify с клиентом Apollo «Не удалось проанализировать http-ответ»

#android #shopify #apollo-client

#Android #Shopify #apollo-client

Вопрос:

Я столкнулся с проблемой синтаксического анализа в запросе products. Вот мой запрос:

запрос GetProducts($productCount: Int, $variantsCount: Int) {
продукты (сначала: $productCount) { ребра { узел { варианты заголовка (сначала: $variantsCount) { ребра { узел { изображение идентификатора заголовка { originalSrc } } } } } } } }

Этот запрос отлично работает, если я исключу image { originalSrc } . Таким образом, синтаксический анализ URL-адреса изображения вызывает проблему. Другая информация по теме:

ApolloClient

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

Отслеживание стека

 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:

Перед тестированием с помощью вызовов вы должны сначала проверить свои вызовы. Использовать GraphQL намного проще, если вы используете предоставленные инструменты для построения своих запросов и тестирования их таким образом. Затем, как только вы начнете получать данные обратно, вставьте рабочие запросы в свой код, чтобы получить результаты. Намного проще, чем пытаться угадать правильные структуры вызовов, как вы.

В качестве примера это приложение может быть наиболее полезным:https://shopify-graphiql-app.shopifycloud.com/login