title: GraphQL query connect to Dutchie API using PHP
body: <p>I have a store in Dutchie.com. I want to access it's products using API key.
  This has to do via Dutchie API using GraphQL integrated with PHP.</p>
  <p><strong>This is the Sample API Key:</strong></p>
  <pre><code>public-eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJBUEktQ0xJRU5UIiwiZXhwIjozMzE4NjM5Mjc0NSwiaWF0IjoxNjI5NDgzOTQ1LCJpc3MiOiJodHRwczovL2R1dGNoY29tIiwianRpIjoiNGMtOTMyOC00MjhkLWEyYTMtOWQzMTc2ZTUwODY0IiwiZW50ZXJwcmlzZV9pZChLWExYTctNDM3OC05NWY4LTNlYzVzBiNSIsInV1aWQiOiI0M2ZlMjdkNy1iZWU2LTQxOTgtYWNhMi03N2Y5Y2I3MjI5MGIifQ.hCQWpcQ5uhKnZOSVQDA5SCMkx5kopC7H3upeU-1jMpg
  </code></pre>
  <p><strong>This is the GraphQL Ping mutation.</strong></p>
  <pre><code>mutation Ping {
    ping {
      id,
      time
    }
  }
  </code></pre>
  <p><strong>Dutchie End Point:</strong> <a href="https://plus.dutchie.com/plus/2021-07/graphql" rel="nofollow noreferrer">https://plus.dutchie.com/plus/2021-07/graphql</a></p>
  <p><strong>http header parameter</strong>
  {
  &quot;Authorization&quot;:&quot;Bearer API KEY HERE&quot;
  }</p>
  <p><strong>Ping output</strong>
  <a href="https://i.stack.imgur.com/CLNR7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CLNR7.png" alt="enter image description here" /></a></p>
  <p>Basically I want to run GraphQL query in my PHP page. I'll add into my WordPress page later.</p>
  <p>I have tried <a href="https://github.com/mghoneimy/php-graphql-client" rel="nofollow noreferrer">php-graphql-client</a> php library.
  Can someone help me to do this using above library or another one really appreciate. I wasted too much time for this as I have only few knowledge of GraphQL.</p>
  <p>This is the code what I have tried.</p>
  <pre><code>$client = new Client(
      'https://plus.dutchie.com/plus/2021-07/graphql',
      ['Authorization =&gt; Bearer API Key here']
  );
   
  
   
  // Create the GraphQL mutation
  $gql = (new Mutation('Ping'))
      -&gt;setSelectionSet(
          [
              'id',
              'time',
          ]
      );
  
  // Run query to get results
  try {
      $results = $client-&gt;runQuery($gql);
  }
  catch (QueryError $exception) {
  
      // Catch query error and desplay error details
      print_r($exception-&gt;getErrorDetails());
      exit;
  }
  
  // Display original response from endpoint
  var_dump($results-&gt;getResponseObject());
  
  // Display part of the returned results of the object
  var_dump($results-&gt;getData()-&gt;pokemon);
  
  // Reformat the results to an array and get the results of part of the array
  $results-&gt;reformatResults(true);
  print_r($results-&gt;getData()['data']);
  </code></pre>
  <p><strong>Error what I got.</strong>
  <a href="https://github.com/guzzle/psr7/blob/master/src/MessageTrait.php" rel="nofollow noreferrer">https://github.com/guzzle/psr7/blob/master/src/MessageTrait.php</a>
  <a href="https://i.stack.imgur.com/EC5Dp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EC5Dp.png" alt="enter image description here" /></a></p>