Skip to content

Commit 2e635fc

Browse files
authored
feature #1001 Allow costume accept headers for GraphQL Endpoint. (Necmttn)
This PR was squashed before being merged into the 3.2.x-dev branch. Discussion ---------- Github has multiple different accept headers for different purposes. Currently, there's no easy way to add/remove the `Accept` header to the client. ref: https://docs.github.com/en/graphql/overview/schema-previews Commits ------- 6362281 Allow costume accept headers for GraphQL Endpoint. dcd725e Update graphql.md 902e9ad Update lib/Github/Api/GraphQL.php 081953c Update lib/Github/Api/GraphQL.php
1 parent 1dce0d3 commit 2e635fc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

doc/graphql.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ $client->authenticate($token, null, Github\Client::AUTH_ACCESS_TOKEN);
1919
$result = $client->api('graphql')->execute($query);
2020
```
2121

22+
#### Use different `Accept` Headers
23+
You can preview upcoming features and changes to the GitHub GraphQL schema before they are added to the GitHub GraphQL API.
24+
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](https://docs.github.com/en/graphql/overview/schema-previews).
25+
26+
To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) with different `Accept` header you can pass third argument to execute method.
27+
28+
```php
29+
$result = $client->api('graphql')->execute($query, [], 'application/vnd.github.starfox-preview+json')
30+
```
31+
> default accept header is `application/vnd.github.v4+json`
32+
33+
34+
2235
#### Use variables
2336

2437
[Variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) allow specifying of requested data without dynamical change of a query on a client side.

lib/Github/Api/GraphQL.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class GraphQL extends AbstractApi
1818
/**
1919
* @param string $query
2020
* @param array $variables
21+
* @param string $acceptHeaderValue
2122
*
2223
* @return array
2324
*/
24-
public function execute($query, array $variables = [])
25+
public function execute($query, array $variables = [], string $acceptHeaderValue = 'application/vnd.github.v4+json')
2526
{
26-
$this->acceptHeaderValue = 'application/vnd.github.v4+json';
27+
$this->acceptHeaderValue = $acceptHeaderValue;
2728
$params = [
2829
'query' => $query,
2930
];

0 commit comments

Comments
 (0)