knplabs/github-api
Lightweight, well-tested PHP wrapper for GitHub APIs v3 (REST) and v4 (GraphQL). PSR-17/PSR-18 compatible via HTTPlug, with easy setup using Guzzle, Symfony HttpClient, or other PSR clients. Supports framework integrations (Laravel via graham-campbell/github).
Wraps GitHub v4 API (GraphQL API).
$rateLimits = $client->api('graphql')->execute($query);
To use GitHub v4 API (GraphQL API) requests must authenticate.
$client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN);
$result = $client->api('graphql')->execute($query);
Accept HeadersYou 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
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);
How can I help you explore Laravel packages today?