Question:
im having issues querying my wix studio with graphql
Product:
Wix Studio Editor
What are you trying to achieve:
export async function fetchAllProducts() {
try {
const { data, errors } = await wix.graphql(
`
query {
Products(queryInput: {}) {
items {
name
}
}
}
`
);
if (errors) {
console.error("GraphQL errors:", errors);
return [];
}
console.log("Fetched data:", data); // Debugging log to inspect the structure
// Adjust the path to the items array if necessary
if (
!data ||
!data.storesProductsV1Products ||
!data.storesProductsV1Products.items
) {
console.error("Unexpected response structure:", data);
return [];
}
return data.storesProductsV1Products.items;
} catch (error) {
console.error("Error fetching products:", error);
return [];
}
}