EDIT: now with working code below
I have this query to fetch a gatsby-image:
query getImages($fileName: String) {
la
So to pass variables you have to use following syntax
graphql(`<your_query_with_variable>`, { indexPage: <value_of_variable> })
So query will come something like this
export const query = grapqhl(
`query getImages($fileName: String) {
landscape: file(relativePath: {eq: $fileName}) {
childImageSharp {
fluid(maxWidth: 1000) {
base64
tracedSVG
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
originalImg
originalName
}
}
}
}
`,
{fileName: "knight.jpg"}
)
The two answers (from Bens and Nimish) are wrong in this context, they're not specific to Gatsby.
If you want to use variables in the GraphQL queries, you have to pass them via context in the createPage
function in gatsby-node.js
as explained here:
https://www.gatsbyjs.org/docs/programmatically-create-pages-from-data/
You currently can't use variables outside of that, e.g. have a look at this discussion: https://spectrum.chat/?t=abee4d1d-6bc4-4202-afb2-38326d91bd05