forked from joomla-framework/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphql.php
More file actions
56 lines (49 loc) · 1.19 KB
/
Copy pathGraphql.php
File metadata and controls
56 lines (49 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Part of the Joomla Framework Github Package
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Github\Package;
use Joomla\Github\AbstractPackage;
/**
* GitHub API GraphQL class for the Joomla Framework.
*
* @link https://developer.github.com/v4/
*
* @since 1.6.0
*/
class Graphql extends AbstractPackage
{
/**
* Execute a query against the GraphQL API.
*
* @param string $query The query to perform.
* @param array $variables An optional array of variables to include in the request.
*
* @return string
*
* @since 1.6.0
*/
public function execute($query, array $variables = array())
{
// Build the request path.
$path = '/graphql';
$headers = array(
'Accept' => 'application/vnd.github.v4+json',
'Content-Type' => 'application/json',
);
$data = array(
'query' => $query,
);
if (!empty($variables))
{
$data['variables'] = $variables;
}
// Send the request.
return $this->processResponse(
$this->client->post($this->fetchUrl($path), json_encode($data), $headers)
);
}
}