Skip to content

GraphQL API #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/Github/Api/GraphQL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Github\Api;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 space line before namespace tag is required


/**
* GraphQL API.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be mention that this is the Early Access program?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* Part of the Github API Early-Access Program
*
* @link https://developer.github.com/early-access/graphql/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be an extra space before this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @author Miguel Piedrafita <soy@miguelpiedrafita.com>
*/
class GraphQL extends AbstractApi
{
/**
* @param string $query
*
* @return array
*/
public function execute($query)
{
$params = array(
'query' => $query
);

return $this->post('/graphql', $params);
}
}
4 changes: 4 additions & 0 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* @method Api\Authorizations authorization()
* @method Api\Authorizations authorizations()
* @method Api\Meta meta()
* @method Api\GraphQL graphql()
*
* @author Joseph Bielawski <stloyd@gmail.com>
*
Expand Down Expand Up @@ -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));
Expand Down
28 changes: 28 additions & 0 deletions test/Github/Tests/Api/GraphQLTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Github\Tests\Api;

class GraphQLTest extends TestCase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should have class comment and namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (I think)

{

/**
* @test
*/
public function shouldTestGraphQL()
{
$api = $this->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;
}
}