2017 © Pedro Peláez
 

library graphql-client-php

A graphql client for php.

image

goltzchristian/graphql-client-php

A graphql client for php.

  • Sunday, February 11, 2018
  • by christiangoltz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 240 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 10 Versions
  • 131 % Grown

The README.md

GraphQL Client for PHP

A client made for testing and consuming GraphQL endpoints, (*1)

Targeting Symfony and Laravel GraphQL implementations, (*2)

Installation

composer require goltzchristian/graphql-client-php, (*3)

Setup

Laravel

use GraphQLClient\Client;

abstract class TestCase extends \Laravel\Lumen\Testing\TestCase
{
  /** @var Client */
  protected $graphql;

  public function setUp()
  {
    parent::setUp();
    $this->graphql = new LaravelTestGraphQLClient(
      $this->app,
      '/graphql'
    );
  }

}

Symfony

class RegistrationTest extends TestCase
{
  /** @var Client */
  protected $graphql;

  public function setUp()
  {
    parent::setUp();
    $this->graphql = new \GraphQLClient\SymfonyWebTestGraphQLClient(
      new Symfony\Bundle\FrameworkBundle\Client,
      '/graphql'  // change it to your endpoint's URI
    );
  }
}

Examples

Mutations

public function testRegistrationSuccess()
{
  $params = [
    'secret' => 'mySecret',
    'password' => $this->getFaker()->password()
    'email' => $this->getFaker()->email()
  ];  // build a query
  $query = new Query('registerUser', $params, [
    new Field('id'),
    new Field('email'),
    new Field('id'),
  ]);  // execute the query
  $fields = $this->graphql->mutate($query)->getData();  // check if the server returned values for all requested fields
  $this->graphql->assertGraphQlFields($fields, $query);  // check if the user was created in the db
  $user = User::query()->where([
    'email' => $params['email'],
  ])->first();
  $this->assertNotNull($user);
}

Queries


public function testReadProfile() { // build the query $query = new Query('viewer', [ 'token' => 'myToken', [ new Field('profile', [ new Field('id'), new Field('email'), new Query('posts', [ 'first' => 10 ], [ new Field('edges', [ new Field('node', [ new Field('id'), new Field('content') ]) ]) ]) ]) ]); // execute the query $fields = $this->graphql->query($query)->getData(); // check if the server returned all requested fields $this->assertGraphQlFields($fields, $query); // check some simple field $this->assertEquals( $this->getUser()->getId(), $result['profile']['id'] ); // retrieve post ids from response $postIds = array_map(function(array $item) { return $item['node']['id']; }, $fields['profile']['posts']['edges']); // check if all user posts were contained in the response foreach ($this->getUser()->getPosts() as $post) { $this->assertNotFalse(array_search($post->getId(), $postIds)); }

You can also checkout this link for detailed instructions, (*4)

The Versions

11/02 2018

dev-master

9999999-dev

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

11/02 2018

1.0.8

1.0.8.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

11/02 2018

1.0.7

1.0.7.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

22/01 2018

1.0.5

1.0.5.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

22/01 2018

1.0.6

1.0.6.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

20/01 2018

1.0.4

1.0.4.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

20/01 2018

1.0.3

1.0.3.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

20/01 2018

1.0.2

1.0.2.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.0

 

The Development Requires

by Christian Goltz

testing graphql

17/01 2018

1.0.0

1.0.0.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Christian Goltz

testing graphql

17/01 2018

1.0.1

1.0.1.0

A graphql client for php.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Christian Goltz

testing graphql