Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
import { authenticate } from "../shopify.server";
export const fetchAllProducts = async (request) => {
try {
const { admin } = await authenticate.admin(request);
// let hasNextPage = true;
let afterCursor = null;
let allProducts = [];
for (let i = 0; i <= 7; i++) {
const response = await admin.graphql(`#graphql
query allProducts($first: Int!, $after: String) {
products(first: $first, after: $after, reverse: true) {
edges {
node {
id
}
}
pageInfo {
hasNextPage
startCursor
endCursor
}
}
}
`, {
first: 10,
after: afterCursor
});
const { data } = await response.json();
const products = data.products.edges.map(edge => edge.node.id);
allProducts = [...allProducts, ...products];
// hasNextPage = data.products.pageInfo.hasNextPage;
afterCursor = data.products.pageInfo.endCursor;
}
return allProducts;
} catch (error) {
console.error('Error fetching products:', error);
return [];
}
};
When making a GQL Query with variables, the variables won't be used. Have I done something wrong?
Mutations with variables haven't been a problem for me.
Server Logs:
Error fetching products: GraphqlQueryError: Variable $first of type Int! was provided invalid value
Solved! Go to the solution
This is an accepted solution.
Apologies, post was made to wrong topic.
This is an accepted solution.
Apologies, post was made to wrong topic.