SHARE
TWEET

Untitled

a guest Jan 14th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function graphql_query(string $endpoint, string $query, array $variables = [], ?string $token = null): array
  4. {
  5.     $headers = ['Content-Type: application/json', 'User-Agent: Unknow Agent'];
  6.     if (null !== $token) {
  7.         $headers[] = "Authorization: bearer $token";
  8.         $headers[] = "X-Access-Token: $token";
  9.     }
  10.  
  11.     if (false === $data = @file_get_contents($endpoint, false, stream_context_create([
  12.         'http' => [
  13.             'method' => 'POST',
  14.             'header' => $headers,
  15.             'content' => json_encode(['query' => $query, 'variables' => $variables]),
  16.         ]
  17.     ]))) {
  18.         $error = error_get_last();
  19.         throw new \ErrorException($error['message'], $error['type']);
  20.     }
  21.  
  22.     echo $data;
  23.     //return json_decode($data, true);
  24. }
  25.  
  26. $query = <<<'GRAPHQL'
  27. query StakeBalances($available: Boolean = false, $vault: Boolean = false) {
  28.    user {
  29.     id
  30.     name
  31.     balances {
  32.         available @include(if: $available) {
  33.             currency
  34.             amount
  35.         }
  36.         vault @include (if: $vault) {
  37.             currency
  38.             amount
  39.         }
  40.     }
  41.   }
  42. }
  43. GRAPHQL;
  44.  
  45. graphql_query("https://api.stake.com/graphql", $query, ['vault' => false, 'available' => true],"token");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top