Variables in graphQL queries

后端 未结 2 463
遇见更好的自我
遇见更好的自我 2020-12-11 02:50

EDIT: now with working code below

The GraphiQL version

I have this query to fetch a gatsby-image:

query getImages($fileName: String) {
  la         


        
2条回答
  •  失恋的感觉
    2020-12-11 03:15

    So to pass variables you have to use following syntax

    graphql(``, { indexPage:  })
    

    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"}
    

    )

提交回复
热议问题