title: how to pass a variable to graphql query?
body: <p>I have a question.
  There is a function that returns the result of a graphql query. In this function, I want to pass the arguments that will be used in the request, for example, to control order direction.
  How can i do this?</p>
  
  <p>1) Fucntion query</p>
  
  <pre><code>import { useStaticQuery, graphql } from "gatsby";
  
  export const useSiteMetadata = (dir) =&gt; {
  
    const {allContentfulBlogPost:{edges}} = useStaticQuery(
      graphql`
          query {
              allContentfulBlogPost(
                  sort:{
                      fields: published,
                      order: $dir
  
                  }
              ){
                  edges{
                      node{
                          name,                        
                          alias,
                          published,
                          id
                      }
                  }
              }
          }
      `
    );
    return edges;
  };
  </code></pre>
  
  <p>2)Function call</p>
  
  <pre><code>const res = useSiteMetadata('ASC');
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/y5HZS.png." rel="nofollow noreferrer">exempel code</a></p>