PHP code example of adeey / graphql-php
1. Go to this page and download the library: Download adeey/graphql-php 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' );
adeey / graphql-php example snippets
axGraphQL\Types\Query;
use MaxGraphQL \Types \Mutation ;
$mutation->addSelect('name' );
$mutation->addSelect('test' );
$mutation->getSelect();
Mutation::getPreparedQueryFrom('nameOfYourMutation' , $selected, $arguments);
Query::getPreparedQueryFrom('nameOfYourQuery' , $selected, $arguments);
$query = new Query('HEREYOURNAME' );
$arguments = [
'argument' => 'ITS MY ARGUMENT'
];
$select = [
'HERE SELECT'
];
$query->addSelect($select);
$query->addArguments($arguments);
$query->getPreparedQuery();
use MaxGraphQL \FieldTypes \Enum ;
$whatIWantToSelect = [
'id' ,
'name' ,
'code' ,
'password' ,
'channels' => [
'id' ,
'titles' => [
'id'
]
],
'... on UserAdmin' => [
'userAdminLevel'
]
];
$filteringArguments = [
'format' => new Enum('ALL' ),
'filter' => [
'activeUsers' => true ,
'userIds' => [1 ,2 ]
]
];
$query = new Query('users' );
$query->addSelect($whatIWantToSelect);
$query->addArguments($filteringArguments);
echo $query->getPreparedQuery();
$whatIWantToSelect = [
'id' ,
'name' ,
'code' ,
'password' ,
'channels' => [
'id' ,
'titles' => [
'id'
]
],
'... on UserAdmin' => [
'userAdminLevel'
]
];
$mutationArguments = [
'id' => '321' ,
'data' => [
'name' => 'Test' ,
'age' => 32 ,
'admin' => false
]
];
$mutation = new Mutation('updateUser' );
$mutation->addSelect($whatIWantToSelect);
$mutation->addArguments($mutationArguments);
echo $mutation->getPreparedQuery();
$whatWeNeedToSelect = [
'all(pageSize: 25)' => [
'name' ,
...
]
];
composer
$mutation->addArguments(['test' => 123 ]);