PHP code example of cfpinto / graphql
1. Go to this page and download the library: Download cfpinto/graphql library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cfpinto / graphql example snippets
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name')
->friends
->use('name')
->root()
->query();
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name')
->friends(['first'=>2])
->use('name')
->root()
->query();
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name')
->friends(['first'=>2])
->use('name')
->prev()
->costumes
->color
->root()
->query();
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name')
->on('FlyingHero')
->use('hasCape')
->prev()
->on('StrongHero')
->use('strengthLevel')
->prev()
->friends(['first'=>2])
->use('name')
->prev()
->costumes
->color
->root()
->query();
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name')
->alias('call_me_this', 'name')
->friends(['first'=>2])
->alias('partners_in_good')
->use('name')
->prev()
->costumes
->color
->root()
->query();
$fragment = new GraphQL\Entities\Fragment('properties', 'Hero');
$fragment->use('id', 'age');
$hero = new \GraphQL\Actions\Query('hero');
echo $hero->use('name', $fragment)->query();
echo $fragment->query();
$variable = new GraphQL\Entities\Variable('name', 'String');
$hero = new \GraphQL\Actions\Query('hero', ['name' => $variable]);
echo $hero->use('name')->query();
$variable = new GraphQL\Entities\Variable('name', 'String');
$hero = new \GraphQL\Actions\Query('hero', ['name' => $variable]);
echo $hero->use('name', '__typename')->query();
$variable = new GraphQL\Entities\Variable('name', 'String');
$hero = new \GraphQL\Actions\Query('hero', ['name' => $variable]);
echo $hero->use('name', '__typename')
->alias('type', '__typename')
->query();
$mutation = new GraphQL\Actions\Mutation('changeHeroCostumeColor', ['id' => 'theHeroId', 'color'=>'red']);
$mutation
->hero
->use('name')
->costumes
->use('color')
->root()
->query();
$mutation = new GraphQL\Actions\Mutation('changeHeroCostumeColor', ['id' => new GraphQL\Entities\Variable('uuid', 'String', ''), new GraphQL\Entities\Variable('color', 'String', '')]);
$mutation
->hero
->use('name')
->costumes
->use('color')
->root()
->query();