Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 1.79 KB

graphql.md

File metadata and controls

57 lines (40 loc) · 1.79 KB

GraphQL API

Back to the navigation

Wraps GitHub v4 API (GraphQL API).

Execute a query

$rateLimits = $client->api('graphql')->execute($query);

Authentication

To use GitHub v4 API (GraphQL API) requests must authenticated.

$client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN);

$result = $client->api('graphql')->execute($query);

Use different Accept Headers

You can preview upcoming features and changes to the GitHub GraphQL schema before they are added to the GitHub GraphQL API. To access a schema preview, you'll need to provide a custom media type in the Accept header for your requests. Feature documentation for each preview specifies which custom media type to provide. More info about Schema Previews.

To use GitHub v4 API (GraphQL API) with different Accept header you can pass third argument to execute method.

$result = $client->api('graphql')->execute($query, [], 'application/vnd.github.starfox-preview+json')

default accept header is application/vnd.github.v4+json

Use variables

Variables allow specifying of requested data without dynamical change of a query on a client side.

$query = <<<'QUERY'
query showOrganizationInfo (
  $organizationLogin: String!
) {
  organization(login: $organizationLogin) {
    name
    url
  }
}
QUERY;
$variables = [
    'organizationLogin' => 'KnpLabs'
];

$client->authenticate('<your-token>', null, Github\AuthMethod::ACCESS_TOKEN);

$orgInfo = $client->api('graphql')->execute($query, $variables);