Skip to content

Instantly share code, notes, and snippets.

@felton
Created October 18, 2018 15:22
Show Gist options
  • Save felton/9be78576fbfe78c505d9b02c04c5af74 to your computer and use it in GitHub Desktop.
Save felton/9be78576fbfe78c505d9b02c04c5af74 to your computer and use it in GitHub Desktop.
👶GraphQL
<?php
/**
* To start, run:
* composer require guzzlehttp/guzzle
* Then:
* php babyql.php
*/
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$options = [
'base_uri' => 'https://countries.trevorblades.com/',
'headers' => [
'Content-Type' => 'application/json',
],
];
$query = <<<'QUERY'
{
country(code: "BR") {
name
native
emoji
currency
languages {
code
name
}
}
}
QUERY;
$data = [
'query' => $query,
];
$client = new Client($options);
$response = $client->request('POST', '', ['json' => $data]);
var_dump(json_decode($response->getBody()->getContents(), true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment