I have a page creatin function wuth this:
createPage({
context: { productId: String(productId) },
As you see, I even forced the ID to be a string, but the page template still receives a number
const Template = ({ pageContext, data }) => {
console.log(pageContext.productId) // number
And the following query that expects a string fails:
export const query = graphql`
myStuff(filter: {productIdentifier: {eq: $productId}}) {
nodes {
id
}
}
}
`
Any ideas how I can force the productId to be a string?
Have you tried toString()?
createPage({
context: { productId: productId.toString() },
Even the productId is not being casted, you can also try defining it as a String or Int:
export const query = graphql`
query($productId: String!) {
myStuff(filter: {productIdentifier: {eq: $productId}}) {
nodes {
id
}
}
}
}
Use $productId: Int! otherwise but I don't know if this will match the filter though.
Another alternative is casting a new string variable before passing it to the context:
let productIdStringified = productId.toString()
createPage({
context: { productId: productIdStringified },