diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php new file mode 100644 index 00000000000..90974015463 --- /dev/null +++ b/lib/Github/Api/GraphQL.php @@ -0,0 +1,28 @@ + + */ +class GraphQL extends AbstractApi +{ + /** + * @param string $query + * + * @return array + */ + public function execute($query) + { + $params = array( + 'query' => $query + ); + + return $this->post('/graphql', $params); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index eb7f3e727dd..ecb94f971de 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -54,6 +54,7 @@ * @method Api\Authorizations authorization() * @method Api\Authorizations authorizations() * @method Api\Meta meta() + * @method Api\GraphQL graphql() * * @author Joseph Bielawski * @@ -267,6 +268,9 @@ public function api($name) case 'meta': $api = new Api\Meta($this); break; + case 'graphql': + $api = new Api\GraphQL($this); + break; default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php new file mode 100644 index 00000000000..c209a733b75 --- /dev/null +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -0,0 +1,28 @@ +getApiMock(); + + $api->expects($this->once()) + ->method('post') + ->with($this->equalTo('/graphql'), $this->equalTo(['query'=>'bar'])) + ->will($this->returnValue('foo')); + + $result = $api->execute('bar'); + $this->assertEquals('foo', $result); + } + + protected function getApiClass() + { + return \Github\Api\GraphQL::class; + } +}