Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function graphql_query(string $endpoint, string $query, array $variables = [], ?string $token = null): array
- {
- $headers = ['Content-Type: application/json', 'User-Agent: Unknow Agent'];
- if (null !== $token) {
- $headers[] = "Authorization: bearer $token";
- $headers[] = "X-Access-Token: $token";
- }
- if (false === $data = @file_get_contents($endpoint, false, stream_context_create([
- 'http' => [
- 'method' => 'POST',
- 'header' => $headers,
- 'content' => json_encode(['query' => $query, 'variables' => $variables]),
- ]
- ]))) {
- $error = error_get_last();
- throw new \ErrorException($error['message'], $error['type']);
- }
- echo $data;
- //return json_decode($data, true);
- }
- $query = <<<'GRAPHQL'
- query StakeBalances($available: Boolean = false, $vault: Boolean = false) {
- user {
- id
- name
- balances {
- available @include(if: $available) {
- currency
- amount
- }
- vault @include (if: $vault) {
- currency
- amount
- }
- }
- }
- }
- GRAPHQL;
- graphql_query("https://api.stake.com/graphql", $query, ['vault' => false, 'available' => true],"token");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement