Skip to content

Instantly share code, notes, and snippets.

@mohamedhafezqo
Last active March 3, 2024 22:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mohamedhafezqo/f813a871d5324a867ecea7baba136b38 to your computer and use it in GitHub Desktop.
Save mohamedhafezqo/f813a871d5324a867ecea7baba136b38 to your computer and use it in GitHub Desktop.
GraphQL Client For PHP Using Guzzle
<?php
$endPoint = 'https://api.github.com/graphql';
$query = <<<'GRAPHQL'
query getUsers {
user {
id
name
}
}
GRAPHQL;
graphqlQuery($endPoint, $query, 'oauth-token');
<?php
function graphqlQuery($endPoint, $query, $accessToken);
{
$response = new Client([
'base_uri' => $endPoint,
'headers' => [
'Authorization' => 'Bearer '.$accessToken,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'query' => $query,
]),
]);
return new ArrayCollection(json_decode($response->getBody()->getContents(), true));
}
@Akposieyefa
Copy link

So how do i pass variables to my Query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment