Skip to content

Add support of GraphQL variables #612

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 3 commits into from
Jul 7, 2017
Merged

Add support of GraphQL variables #612

merged 3 commits into from
Jul 7, 2017

Conversation

vkublytskyi
Copy link
Contributor

@vkublytskyi vkublytskyi commented Jul 6, 2017

GitHub GraphQL API supports variables that allow specifying of requested data without dynamical change of a query on a client side.

This PR adds the possibility to send variables with a query to GitHub GraphQL API v4.

Usage:

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

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

*
* @return array
*/
public function execute($query)
public function execute($query, array $variables = null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the default value to an emtpy array, this way each possible value (user input or default) is the same type

@acrobat
Copy link
Collaborator

acrobat commented Jul 6, 2017

One small comment, the rest of the PR looks good to me!

 - fixed default value to be same type if not specified
@vkublytskyi
Copy link
Contributor Author

@acrobat, agree that with an empty array as the default value code will be more maintainable in future. Fixed.

Copy link
Collaborator

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Cool. It looks good with tests and everything =)

Just add a small note in the change log and we'll be happy to merge.

@vkublytskyi
Copy link
Contributor Author

Added item to CHANGELOG.md and usage example to doc/graphql.md

@acrobat
Copy link
Collaborator

acrobat commented Jul 7, 2017

Thanks @vkublytskyi! And congrats on your first contribution on this library!

@acrobat acrobat merged commit 21df374 into KnpLabs:master Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants