-
-
Save dougkusanagi/f4bd1bf8a0097f7a28f907c76130b7ff to your computer and use it in GitHub Desktop.
GraphQL Client For PHP Using Guzzle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$endPoint = 'https://api.github.com/graphql'; | |
$query = <<<'GRAPHQL' | |
query getUsers { | |
user { | |
id | |
name | |
} | |
} | |
GRAPHQL; | |
graphqlQuery($endPoint, $query, 'oauth-token'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment