title: How to use PHP variables in a Graphql query?
body: <p>This is using WPGraphql with WordPress but I believe it's a general PHP and/or Graphql issue. I've been searching for 2 days now, and everything I've found is specific to some library or framework or otherwise not helpful. Any help with this is super appreciated.</p>
  <p>The code below creates a variable $post_slug which contains the slug of the current post.</p>
  <p>If I replace id: $post_slug with an actual post slug (id: &quot;my-groovy-post&quot;) it works, but apparently $post_slug is undefined within the query.</p>
  <pre><code>&lt;?php
  
  $post_slug = get_post_field( 'post_name', get_post() );
  
  $graphql = graphql([
      'query' =&gt; ' {
    post(idType: SLUG, id: $post_slug) {
      title
      content
      date
    }
  }'
  ]);
  
  
  echo '&lt;pre&gt;';
  var_dump($graphql);
  echo '&lt;/pre&gt;';
  ?&gt;
  </code></pre>
  <p>The results of my query</p>
  <pre><code>array(2) {
    [&quot;errors&quot;]=&gt;
    array(1) {
      [0]=&gt;
      array(3) {
        [&quot;message&quot;]=&gt;
        string(37) &quot;Variable &quot;$post_slug&quot; is not defined.&quot;
        [&quot;extensions&quot;]=&gt;
        array(1) {
          [&quot;category&quot;]=&gt;
          string(7) &quot;graphql&quot;
        }
        [&quot;locations&quot;]=&gt;
        array(2) {
          [0]=&gt;
          array(2) {
            [&quot;line&quot;]=&gt;
            int(2)
            [&quot;column&quot;]=&gt;
            int(27)
          }
          [1]=&gt;
          array(2) {
            [&quot;line&quot;]=&gt;
            int(1)
            [&quot;column&quot;]=&gt;
            int(2)
          }
        }
      }
    }
    [&quot;extensions&quot;]=&gt;
    array(1) {
      [&quot;debug&quot;]=&gt;
      array(1) {
        [0]=&gt;
        array(2) {
          [&quot;type&quot;]=&gt;
          string(19) &quot;DEBUG_LOGS_INACTIVE&quot;
          [&quot;message&quot;]=&gt;
          string(86) &quot;GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled.&quot;
        }
      }
    }
  }
  </code></pre>