How to get second page in GraphiQL

tima4ka1
New Member
3 0 0

Hey!
I am developing an application and faced such a problem as limiting the receipt of products from the store.
Now I started using GraphiQL queries to get information about the products of the store, but I was faced with such complexity that I cannot go to the second page with products. I've tried different methods already, but somehow nothing helps.
I would be very happy at least for advice in which direction to look in order to get all the groceries.

Below I will write down what I have already tried to do.

Tried creating mutation

products (@ myProducts @)
In code, this is the first time
const body = JSON.stringify (MYSHOPPRODUCTS) .replace (/ @ myProducts @ /, "first: 3");

Starting from the second time
const body = JSON.stringify (MYSHOPPRODUCTS) .replace (/ @ myProducts @ /, `" first: 3, after: "$ {nextProduct}" `);

However, this method does not work, since the second attempt displays an error 400.

Tried writing this in 2 separate loops but also doesn't work. Rather, it shows two pages, but it doesn’t work to get the third and further pages. Writes that nextProduct cannot be earlier than the assignment of this variable, but it was assigned and remained from the previous function, which is located above (The first function is the parent of the second)

 

My function code is:

 

   const body = JSON.stringify(MYSHOPPRODUCTS).replace(/@myProducts@@/"first: 3");
   const method = 'POST';
   const headers = getShopifyHeaders(accessToken);
   const response = await fetch(`https://${shop}/admin/api/2020-10/graphql.json`{ methodheadersbody });
   const responseJson = await response.json();
0 Likes