2022-01-21 08:23:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Github\Api;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GraphQL API.
|
|
|
|
*
|
|
|
|
* Part of the Github v4 API
|
|
|
|
*
|
|
|
|
* @link https://developer.github.com/v4/
|
|
|
|
*
|
|
|
|
* @author Miguel Piedrafita <soy@miguelpiedrafita.com>
|
|
|
|
*/
|
|
|
|
class GraphQL extends AbstractApi
|
|
|
|
{
|
|
|
|
use AcceptHeaderTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $query
|
|
|
|
* @param array $variables
|
2022-01-24 08:08:35 +00:00
|
|
|
* @param string $acceptHeaderValue
|
2022-01-21 08:23:52 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-01-24 08:08:35 +00:00
|
|
|
public function execute($query, array $variables = [], string $acceptHeaderValue = 'application/vnd.github.v4+json')
|
2022-01-21 08:23:52 +00:00
|
|
|
{
|
2022-01-24 08:08:35 +00:00
|
|
|
$this->acceptHeaderValue = $acceptHeaderValue;
|
2022-01-21 08:23:52 +00:00
|
|
|
$params = [
|
|
|
|
'query' => $query,
|
|
|
|
];
|
|
|
|
if (!empty($variables)) {
|
|
|
|
$params['variables'] = json_encode($variables);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->post('/graphql', $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file
|
|
|
|
* @param array $variables
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fromFile($file, array $variables = [])
|
|
|
|
{
|
|
|
|
return $this->execute(file_get_contents($file), $variables);
|
|
|
|
}
|
|
|
|
}
|