I’m trying to inject a variable into a query filter:
query getProductsByTag($tag: String!) {
products(query: "tag:$tag" first: 20) {
edges {
node {
title
id
}
}
}
}
This doesn’t seem to work. Getting
GraphQL error: Variable $tag is declared by getProductsByTag but not used
Is there a trick to fix this or do I need to accomplish this via String interpolation, e.g.
const t = "bag";
const GET_PRODUCTS_BY_TAG = gql`
query getProductsByTag {
products(query: "tag:${t}" first: 20) {
edges {
node {
title
id
}
}
}
}
`;
Asked also on stackoverflow
Thanks
Zin