When making a GQL Query with variables, the variables won’t be used. Have I done something wrong? My code below:
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 [];
}
};
Mutations with variables haven’t been a problem for me. Locally making the query with variables on the graphiql playground doesn’t cause any issues and returns expected result.
Server Logs:
Error fetching products: GraphqlQueryError: Variable $first of type Int! was provided invalid value

