Android Shopify获取产品详细信息查询错误



当我尝试使用下面给出的代码在shopify android中通过ID获取产品详细信息

   ID id = new ID(productId);
        Storefront.QueryRootQuery query = Storefront.query(rootQueryBuilder ->
                rootQueryBuilder
                        .node(id, nodeQuery ->
                                nodeQuery
                                        .onProduct(productQuery ->
                                                productQuery
                                                        .title()
                                                .description()
        )
    )
);
        QueryGraphCall call = App.graphClient().queryGraph(query);
        call.enqueue(new GraphCall.Callback<Storefront.QueryRoot>() {
            @Override
            public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response) {
            }
            @Override
            public void onFailure(@NonNull GraphError error) {
            }
        });
    }

但是,我正在遇到一个错误,例如参数'ID'在字段'node'中具有无效的值。预期类型的'id!'

我也尝试了另一个代码,但是得到相同的错误

        Storefront.ProductQueryDefinition query = q -> q
                .title()
                .descriptionHtml()
                .tags()
                .images(args ->  args.first(250), imageConnection -> imageConnection
                        .edges(imageEdge -> imageEdge
                                .node(Storefront.ImageQuery::src)
                        )
                )
                .options(option -> option
                        .name()
                        .values()
                )
                .variants(args ->  args.first(250), variantConnection -> variantConnection
                        .edges(variantEdge -> variantEdge
                                .node(variant -> variant
                                        .title()
                                        .availableForSale()
                                        .selectedOptions(selectedOption -> selectedOption
                                                .name()
                                                .value()
                                        )
                                        .price()
                                )
                        )
                );
        GraphCall<Storefront.QueryRoot> call = App.graphClient().queryGraph(Storefront.query(
                root -> root
                        .node(new ID(productId), node -> node
                                .onProduct(query)
                        )
                )
        );

预先感谢。

field'node'上的参数'id'具有无效的值。预期类型的" ID!"。

当您不喂食正确的productid时,会发生此错误。尝试这个 -提取收集-Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery .shop(shopQuery -> shopQuery .collections(arg -> arg.first(30), collectionConnectionQuery -> collectionConnectionQuery .edges(collectionEdgeQuery -> collectionEdgeQuery .node(collectionQuery -> collectionQuery .title() .image(imageConnectionQuery -> imageConnectionQuery .src() ) ) ) ) ) );

现在使用收集ID获取此系列的产品 -

 Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
            .node(new ID(collectionID), nodeQuery -> nodeQuery
                    .onCollection(collectionQuery -> collectionQuery
                            .products(
                                    args -> args
                                            .first(30),
                                    productConnectionQuery -> productConnectionQuery
                                            .pageInfo(pageInfoQuery -> pageInfoQuery
                                                    .hasNextPage()
                                            )
                                            .edges(productEdgeQuery -> productEdgeQuery
                                                    .cursor()
                                                    .node(productQuery -> productQuery
                                                            .title()
                                                            .productType()
                                                            .description()
                                                            .images(arg -> arg.first(10), imageConnectionQuery -> imageConnectionQuery
                                                                    .edges(imageEdgeQuery -> imageEdgeQuery
                                                                            .node(imageQuery -> imageQuery
                                                                                    .src()
                                                                            )
                                                                    )
                                                            )
                                                            .variants(arg -> arg.first(10), variantConnectionQuery -> variantConnectionQuery
                                                                    .edges(variantEdgeQuery -> variantEdgeQuery
                                                                            .node(productVariantQuery -> productVariantQuery
                                                                                    .price()
                                                                                    .compareAtPrice()
                                                                                    .title()
                                                                                    .available()
                                                                            )
                                                                    )
                                                            )
                                                    )
                                            )
                            )
                    )
            )
    );

从响应中获取所有产品ID-

graphClient.queryGraph(query).enqueue(new GraphCall.Callback<Storefront.QueryRoot>() {
        @Override public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response) {
            progress.dismiss();
            Storefront.Collection collection = (Storefront.Collection) response.data().getNode();
            boolean hasNextProductPage = collection.getProducts().getPageInfo().getHasNextPage();
            ArrayList  products = new ArrayList<>();
            String productID = new String[products.size()];
            for (Storefront.ProductEdge productEdge : collection.getProducts().getEdges()) {
                String productPageCursor = productEdge.getCursor();
                products.add(productEdge.getNode());
            }
        for(int count=0;count<products.size();count++){
        productID[count] = products.get(count).getId().toString();
        }
        @Override
        public void onFailure(@NonNull GraphError error) {
        }
    });

在您的代码中使用这些产品ID。

相关内容

  • 没有找到相关文章

最新更新