From 63622816442f8018fefb77b63f4e58f1fe7ac76c Mon Sep 17 00:00:00 2001 From: Necmettin Karakaya Date: Thu, 29 Apr 2021 14:49:21 +0800 Subject: [PATCH 1/4] Allow costume accept headers for GraphQL Endpoint. 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 --- lib/Github/Api/GraphQL.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 9d66b5123fb..1ffca4103cd 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -21,9 +21,9 @@ class GraphQL extends AbstractApi * * @return array */ - public function execute($query, array $variables = []) + public function execute($query, array $variables = [], $acceptHeaderValue = 'application/vnd.github.v4+json') { - $this->acceptHeaderValue = 'application/vnd.github.v4+json'; + $this->acceptHeaderValue = $acceptHeaderValue; $params = [ 'query' => $query, ]; From dcd725e11de1a2870714182bea4b16f5fdd0b668 Mon Sep 17 00:00:00 2001 From: Necmettin Karakaya Date: Thu, 29 Apr 2021 21:13:04 +0800 Subject: [PATCH 2/4] Update graphql.md --- doc/graphql.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/graphql.md b/doc/graphql.md index 4151012342c..99e653bf87a 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -19,6 +19,19 @@ $client->authenticate($token, null, Github\Client::AUTH_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](https://docs.github.com/en/graphql/overview/schema-previews). + +To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) with different `Accept` header you can pass third argument to execute method. + +```php +$result = $client->api('graphql')->execute($query, [], 'application/vnd.github.starfox-preview+json') +``` +> default accept header is `application/vnd.github.v4+json` + + + #### Use variables [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. From 902e9add10ed99f86d35137421ee3aeaa274f667 Mon Sep 17 00:00:00 2001 From: Necmettin Karakaya Date: Fri, 30 Apr 2021 11:22:29 +0800 Subject: [PATCH 3/4] Update lib/Github/Api/GraphQL.php Co-authored-by: Markus Staab --- lib/Github/Api/GraphQL.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 1ffca4103cd..fead5eebf4b 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -18,6 +18,7 @@ class GraphQL extends AbstractApi /** * @param string $query * @param array $variables + * @param string $acceptHeaderValue * * @return array */ From 081953c82766e5cf639ddea7a3cdf29da20bde1b Mon Sep 17 00:00:00 2001 From: Necmettin Karakaya Date: Fri, 30 Apr 2021 11:22:43 +0800 Subject: [PATCH 4/4] Update lib/Github/Api/GraphQL.php Co-authored-by: Jeroen Thora --- lib/Github/Api/GraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index fead5eebf4b..02499ad8ef7 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -22,7 +22,7 @@ class GraphQL extends AbstractApi * * @return array */ - public function execute($query, array $variables = [], $acceptHeaderValue = 'application/vnd.github.v4+json') + public function execute($query, array $variables = [], string $acceptHeaderValue = 'application/vnd.github.v4+json') { $this->acceptHeaderValue = $acceptHeaderValue; $params = [