How to fetch Collection and product details (including images, price) in one Storefront query










0















How can i fetch Collection with its product details in one query. What i've done is fetch all collection first then from in it i've fetched the id and one by one step wise i include the id in another query then i got the product details.



But i want all in one query. Check my code



step1) made query for getting collection
step2) call it
step3) made query for getting product details from collection response
step) call it



 Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
.shop(shopQuery -> shopQuery
.collections(arg -> arg.first(10), collectionConnectionQuery -> collectionConnectionQuery
.edges(collectionEdgeQuery -> collectionEdgeQuery
.node(collectionQuery -> collectionQuery
.title()
.products(arg -> arg.first(10), productConnectionQuery -> productConnectionQuery
.edges(productEdgeQuery -> productEdgeQuery
.node(productQuery -> productQuery
.title()
.productType()
.description()
)
)
)
)
)
)
)
);


@Override
public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)

List<Storefront.Collection> collections = new ArrayList<>();

for (Storefront.CollectionEdge collectionEdge : response.data().getShop().getCollections().getEdges())


collections.add(collectionEdge.getNode());


for (Storefront.ProductEdge productEdge : collectionEdge.getNode().getProducts().getEdges())

products.add(productEdge.getNode());



for (int i = 0; i < products.size(); i++)

Log.i("PRODUCTS", String.valueOf(products.get(i).getId().toString()));




getActivity().runOnUiThread(new Runnable()


@Override
public void run()


product_recyclreview.setVisibility(View.VISIBLE);
shimmer.setVisibility(View.GONE);

productAdapter = new ProductAdapter(getActivity(), products);
product_recyclreview.setAdapter(productAdapter);

mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()


@Override
public void onRefresh()


Refresh();
mSwipeRefreshLayout.setRefreshing(false);



);



);




@Override
public void onFailure(@NonNull GraphError error)



});

Storefront.QueryRootQuery querySEC = null;

querySEC = Storefront.query(rootQuery -> rootQuery
.node(new ID(products.get(0).getId().toString()), nodeQuery -> nodeQuery
.onProduct(productQuery -> productQuery
.title()
.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()
.title()
.available()
)
)
)
)
)
);



graphClientsec.queryGraph(querySEC).enqueue(new GraphCall.Callback<Storefront.QueryRoot>()


@Override
public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)


Storefront.Product product = (Storefront.Product) response.data().getNode();

List<Storefront.Image> productImages = new ArrayList<>();

for (final Storefront.ImageEdge imageEdge : product.getImages().getEdges())

productImages.add(imageEdge.getNode());


List<Storefront.ProductVariant> productVariants = new ArrayList<>();

for (final Storefront.ProductVariantEdge productVariantEdge : product.getVariants().getEdges())
productVariants.add(productVariantEdge.getNode());


getActivity().runOnUiThread(new Runnable()


@Override
public void run()


Drawable mDefaultFailed = getResources().getDrawable(R.drawable.notfound);

for (int i = 0; i < productImages.size(); i++)

// String price= String.valueOf(productVariants.get(finalI).getPrice());

if (productImages.get(i).getSrc().isEmpty())

Glide.with(getActivity())
.load(productImages.get(i).getSrc())
.into((ImageView) getActivity().findViewById(R.id.img_prdimg)).
onLoadFailed(null, mDefaultFailed);


else


Glide.with(getActivity())
.load(productImages.get(i).getSrc()).listener(new RequestListener<String, GlideDrawable>()

@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target,
boolean isFirstResource)
return false;



@Override
public boolean onResourceReady(GlideDrawable
resource, String model, Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource)

return false;


)
.into((ImageView) getActivity().findViewById(R.id.img_prdimg));




);



@Override
public void onFailure(@NonNull GraphError error)



);









share|improve this question


























    0















    How can i fetch Collection with its product details in one query. What i've done is fetch all collection first then from in it i've fetched the id and one by one step wise i include the id in another query then i got the product details.



    But i want all in one query. Check my code



    step1) made query for getting collection
    step2) call it
    step3) made query for getting product details from collection response
    step) call it



     Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
    .shop(shopQuery -> shopQuery
    .collections(arg -> arg.first(10), collectionConnectionQuery -> collectionConnectionQuery
    .edges(collectionEdgeQuery -> collectionEdgeQuery
    .node(collectionQuery -> collectionQuery
    .title()
    .products(arg -> arg.first(10), productConnectionQuery -> productConnectionQuery
    .edges(productEdgeQuery -> productEdgeQuery
    .node(productQuery -> productQuery
    .title()
    .productType()
    .description()
    )
    )
    )
    )
    )
    )
    )
    );


    @Override
    public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)

    List<Storefront.Collection> collections = new ArrayList<>();

    for (Storefront.CollectionEdge collectionEdge : response.data().getShop().getCollections().getEdges())


    collections.add(collectionEdge.getNode());


    for (Storefront.ProductEdge productEdge : collectionEdge.getNode().getProducts().getEdges())

    products.add(productEdge.getNode());



    for (int i = 0; i < products.size(); i++)

    Log.i("PRODUCTS", String.valueOf(products.get(i).getId().toString()));




    getActivity().runOnUiThread(new Runnable()


    @Override
    public void run()


    product_recyclreview.setVisibility(View.VISIBLE);
    shimmer.setVisibility(View.GONE);

    productAdapter = new ProductAdapter(getActivity(), products);
    product_recyclreview.setAdapter(productAdapter);

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()


    @Override
    public void onRefresh()


    Refresh();
    mSwipeRefreshLayout.setRefreshing(false);



    );



    );




    @Override
    public void onFailure(@NonNull GraphError error)



    });

    Storefront.QueryRootQuery querySEC = null;

    querySEC = Storefront.query(rootQuery -> rootQuery
    .node(new ID(products.get(0).getId().toString()), nodeQuery -> nodeQuery
    .onProduct(productQuery -> productQuery
    .title()
    .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()
    .title()
    .available()
    )
    )
    )
    )
    )
    );



    graphClientsec.queryGraph(querySEC).enqueue(new GraphCall.Callback<Storefront.QueryRoot>()


    @Override
    public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)


    Storefront.Product product = (Storefront.Product) response.data().getNode();

    List<Storefront.Image> productImages = new ArrayList<>();

    for (final Storefront.ImageEdge imageEdge : product.getImages().getEdges())

    productImages.add(imageEdge.getNode());


    List<Storefront.ProductVariant> productVariants = new ArrayList<>();

    for (final Storefront.ProductVariantEdge productVariantEdge : product.getVariants().getEdges())
    productVariants.add(productVariantEdge.getNode());


    getActivity().runOnUiThread(new Runnable()


    @Override
    public void run()


    Drawable mDefaultFailed = getResources().getDrawable(R.drawable.notfound);

    for (int i = 0; i < productImages.size(); i++)

    // String price= String.valueOf(productVariants.get(finalI).getPrice());

    if (productImages.get(i).getSrc().isEmpty())

    Glide.with(getActivity())
    .load(productImages.get(i).getSrc())
    .into((ImageView) getActivity().findViewById(R.id.img_prdimg)).
    onLoadFailed(null, mDefaultFailed);


    else


    Glide.with(getActivity())
    .load(productImages.get(i).getSrc()).listener(new RequestListener<String, GlideDrawable>()

    @Override
    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
    boolean isFirstResource)
    return false;



    @Override
    public boolean onResourceReady(GlideDrawable
    resource, String model, Target<GlideDrawable> target,
    boolean isFromMemoryCache, boolean isFirstResource)

    return false;


    )
    .into((ImageView) getActivity().findViewById(R.id.img_prdimg));




    );



    @Override
    public void onFailure(@NonNull GraphError error)



    );









    share|improve this question
























      0












      0








      0








      How can i fetch Collection with its product details in one query. What i've done is fetch all collection first then from in it i've fetched the id and one by one step wise i include the id in another query then i got the product details.



      But i want all in one query. Check my code



      step1) made query for getting collection
      step2) call it
      step3) made query for getting product details from collection response
      step) call it



       Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
      .shop(shopQuery -> shopQuery
      .collections(arg -> arg.first(10), collectionConnectionQuery -> collectionConnectionQuery
      .edges(collectionEdgeQuery -> collectionEdgeQuery
      .node(collectionQuery -> collectionQuery
      .title()
      .products(arg -> arg.first(10), productConnectionQuery -> productConnectionQuery
      .edges(productEdgeQuery -> productEdgeQuery
      .node(productQuery -> productQuery
      .title()
      .productType()
      .description()
      )
      )
      )
      )
      )
      )
      )
      );


      @Override
      public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)

      List<Storefront.Collection> collections = new ArrayList<>();

      for (Storefront.CollectionEdge collectionEdge : response.data().getShop().getCollections().getEdges())


      collections.add(collectionEdge.getNode());


      for (Storefront.ProductEdge productEdge : collectionEdge.getNode().getProducts().getEdges())

      products.add(productEdge.getNode());



      for (int i = 0; i < products.size(); i++)

      Log.i("PRODUCTS", String.valueOf(products.get(i).getId().toString()));




      getActivity().runOnUiThread(new Runnable()


      @Override
      public void run()


      product_recyclreview.setVisibility(View.VISIBLE);
      shimmer.setVisibility(View.GONE);

      productAdapter = new ProductAdapter(getActivity(), products);
      product_recyclreview.setAdapter(productAdapter);

      mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()


      @Override
      public void onRefresh()


      Refresh();
      mSwipeRefreshLayout.setRefreshing(false);



      );



      );




      @Override
      public void onFailure(@NonNull GraphError error)



      });

      Storefront.QueryRootQuery querySEC = null;

      querySEC = Storefront.query(rootQuery -> rootQuery
      .node(new ID(products.get(0).getId().toString()), nodeQuery -> nodeQuery
      .onProduct(productQuery -> productQuery
      .title()
      .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()
      .title()
      .available()
      )
      )
      )
      )
      )
      );



      graphClientsec.queryGraph(querySEC).enqueue(new GraphCall.Callback<Storefront.QueryRoot>()


      @Override
      public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)


      Storefront.Product product = (Storefront.Product) response.data().getNode();

      List<Storefront.Image> productImages = new ArrayList<>();

      for (final Storefront.ImageEdge imageEdge : product.getImages().getEdges())

      productImages.add(imageEdge.getNode());


      List<Storefront.ProductVariant> productVariants = new ArrayList<>();

      for (final Storefront.ProductVariantEdge productVariantEdge : product.getVariants().getEdges())
      productVariants.add(productVariantEdge.getNode());


      getActivity().runOnUiThread(new Runnable()


      @Override
      public void run()


      Drawable mDefaultFailed = getResources().getDrawable(R.drawable.notfound);

      for (int i = 0; i < productImages.size(); i++)

      // String price= String.valueOf(productVariants.get(finalI).getPrice());

      if (productImages.get(i).getSrc().isEmpty())

      Glide.with(getActivity())
      .load(productImages.get(i).getSrc())
      .into((ImageView) getActivity().findViewById(R.id.img_prdimg)).
      onLoadFailed(null, mDefaultFailed);


      else


      Glide.with(getActivity())
      .load(productImages.get(i).getSrc()).listener(new RequestListener<String, GlideDrawable>()

      @Override
      public boolean onException(Exception e, String model, Target<GlideDrawable> target,
      boolean isFirstResource)
      return false;



      @Override
      public boolean onResourceReady(GlideDrawable
      resource, String model, Target<GlideDrawable> target,
      boolean isFromMemoryCache, boolean isFirstResource)

      return false;


      )
      .into((ImageView) getActivity().findViewById(R.id.img_prdimg));




      );



      @Override
      public void onFailure(@NonNull GraphError error)



      );









      share|improve this question














      How can i fetch Collection with its product details in one query. What i've done is fetch all collection first then from in it i've fetched the id and one by one step wise i include the id in another query then i got the product details.



      But i want all in one query. Check my code



      step1) made query for getting collection
      step2) call it
      step3) made query for getting product details from collection response
      step) call it



       Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
      .shop(shopQuery -> shopQuery
      .collections(arg -> arg.first(10), collectionConnectionQuery -> collectionConnectionQuery
      .edges(collectionEdgeQuery -> collectionEdgeQuery
      .node(collectionQuery -> collectionQuery
      .title()
      .products(arg -> arg.first(10), productConnectionQuery -> productConnectionQuery
      .edges(productEdgeQuery -> productEdgeQuery
      .node(productQuery -> productQuery
      .title()
      .productType()
      .description()
      )
      )
      )
      )
      )
      )
      )
      );


      @Override
      public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)

      List<Storefront.Collection> collections = new ArrayList<>();

      for (Storefront.CollectionEdge collectionEdge : response.data().getShop().getCollections().getEdges())


      collections.add(collectionEdge.getNode());


      for (Storefront.ProductEdge productEdge : collectionEdge.getNode().getProducts().getEdges())

      products.add(productEdge.getNode());



      for (int i = 0; i < products.size(); i++)

      Log.i("PRODUCTS", String.valueOf(products.get(i).getId().toString()));




      getActivity().runOnUiThread(new Runnable()


      @Override
      public void run()


      product_recyclreview.setVisibility(View.VISIBLE);
      shimmer.setVisibility(View.GONE);

      productAdapter = new ProductAdapter(getActivity(), products);
      product_recyclreview.setAdapter(productAdapter);

      mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()


      @Override
      public void onRefresh()


      Refresh();
      mSwipeRefreshLayout.setRefreshing(false);



      );



      );




      @Override
      public void onFailure(@NonNull GraphError error)



      });

      Storefront.QueryRootQuery querySEC = null;

      querySEC = Storefront.query(rootQuery -> rootQuery
      .node(new ID(products.get(0).getId().toString()), nodeQuery -> nodeQuery
      .onProduct(productQuery -> productQuery
      .title()
      .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()
      .title()
      .available()
      )
      )
      )
      )
      )
      );



      graphClientsec.queryGraph(querySEC).enqueue(new GraphCall.Callback<Storefront.QueryRoot>()


      @Override
      public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response)


      Storefront.Product product = (Storefront.Product) response.data().getNode();

      List<Storefront.Image> productImages = new ArrayList<>();

      for (final Storefront.ImageEdge imageEdge : product.getImages().getEdges())

      productImages.add(imageEdge.getNode());


      List<Storefront.ProductVariant> productVariants = new ArrayList<>();

      for (final Storefront.ProductVariantEdge productVariantEdge : product.getVariants().getEdges())
      productVariants.add(productVariantEdge.getNode());


      getActivity().runOnUiThread(new Runnable()


      @Override
      public void run()


      Drawable mDefaultFailed = getResources().getDrawable(R.drawable.notfound);

      for (int i = 0; i < productImages.size(); i++)

      // String price= String.valueOf(productVariants.get(finalI).getPrice());

      if (productImages.get(i).getSrc().isEmpty())

      Glide.with(getActivity())
      .load(productImages.get(i).getSrc())
      .into((ImageView) getActivity().findViewById(R.id.img_prdimg)).
      onLoadFailed(null, mDefaultFailed);


      else


      Glide.with(getActivity())
      .load(productImages.get(i).getSrc()).listener(new RequestListener<String, GlideDrawable>()

      @Override
      public boolean onException(Exception e, String model, Target<GlideDrawable> target,
      boolean isFirstResource)
      return false;



      @Override
      public boolean onResourceReady(GlideDrawable
      resource, String model, Target<GlideDrawable> target,
      boolean isFromMemoryCache, boolean isFirstResource)

      return false;


      )
      .into((ImageView) getActivity().findViewById(R.id.img_prdimg));




      );



      @Override
      public void onFailure(@NonNull GraphError error)



      );






      shopify storefront






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 12:13









      satani ketansatani ketan

      14




      14






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319268%2fhow-to-fetch-collection-and-product-details-including-images-price-in-one-sto%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319268%2fhow-to-fetch-collection-and-product-details-including-images-price-in-one-sto%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3