I am trying to filter some data in a NextJS app using GraphQL but am quite new to GraphQL and need some help. My query works as I tested it on my repo/graphql page but not sure how to integrate it or how to use variables.
const productQuery = `
query GetFilteredProducts($product_type: String, $style: String, $colour: String, $size: String) {
allProducts(where: {
product_type: $product_type
styles: {style: $style},
colours: {colour: $colour},
sizes: {size: $size}
}) {
edges {
node {
title
description
images {
position
colour
image
}
}
}
}
}
`;
const getProducts = async ({ previewData, queryKey }) => {
const client = createClient({ previewData });
const productType = queryKey[1].productType;
const style = queryKey[1].style;
const colour = queryKey[1].colour;
const size = queryKey[1].size;
// I'm not sure how to use graphQl or how I send the variables above to be used by my query.
const filteredProducts = await client.get({ graphQuery: productQuery });
console.log(filteredProducts);
return filteredProducts;
};
I have also noticed I am getting a CORS error.