Skip to content

Commit 22d967d

Browse files
authored
Merge pull request #510 from m1guelpf/glaphql-api
GraphQL API
2 parents 6838d82 + 21138e6 commit 22d967d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

lib/Github/Api/GraphQL.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Github\Api;
4+
5+
/**
6+
* GraphQL API.
7+
*
8+
* Part of the Github API Early-Access Program
9+
*
10+
* @link https://developer.github.com/early-access/graphql/
11+
* @author Miguel Piedrafita <[email protected]>
12+
*/
13+
class GraphQL extends AbstractApi
14+
{
15+
/**
16+
* @param string $query
17+
*
18+
* @return array
19+
*/
20+
public function execute($query)
21+
{
22+
$params = array(
23+
'query' => $query
24+
);
25+
26+
return $this->post('/graphql', $params);
27+
}
28+
}

lib/Github/Client.php

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* @method Api\Authorizations authorization()
5555
* @method Api\Authorizations authorizations()
5656
* @method Api\Meta meta()
57+
* @method Api\GraphQL graphql()
5758
*
5859
* @author Joseph Bielawski <[email protected]>
5960
*
@@ -267,6 +268,9 @@ public function api($name)
267268
case 'meta':
268269
$api = new Api\Meta($this);
269270
break;
271+
case 'graphql':
272+
$api = new Api\GraphQL($this);
273+
break;
270274

271275
default:
272276
throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));

test/Github/Tests/Api/GraphQLTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
class GraphQLTest extends TestCase
6+
{
7+
8+
/**
9+
* @test
10+
*/
11+
public function shouldTestGraphQL()
12+
{
13+
$api = $this->getApiMock();
14+
15+
$api->expects($this->once())
16+
->method('post')
17+
->with($this->equalTo('/graphql'), $this->equalTo(['query'=>'bar']))
18+
->will($this->returnValue('foo'));
19+
20+
$result = $api->execute('bar');
21+
$this->assertEquals('foo', $result);
22+
}
23+
24+
protected function getApiClass()
25+
{
26+
return \Github\Api\GraphQL::class;
27+
}
28+
}

0 commit comments

Comments
 (0)