-
Notifications
You must be signed in to change notification settings - Fork 107
Recipes
Alexandr Viniychuk edited this page Jul 29, 2016
·
1 revision
<?php
namespace Sandbox;
use Youshido\GraphQL\Execution\Processor;
use Youshido\GraphQL\Schema\Schema;
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\StringType;
require_once 'vendor/autoload.php';
$processor = new Processor(new Schema([
'query' => new ObjectType([
'name' => 'RootQueryType',
'fields' => [
'labels' => [
'type' => new ListType(new StringType()),
'resolve' => function () {
return ['one', 'two'];
}
]
]
])
]));
$payload = '{ labels }';
$processor->processPayload($payload);
echo json_encode($processor->getResponseData()) . "\n";
<?php
namespace Sandbox;
use Youshido\GraphQL\Execution\Processor;
use Youshido\GraphQL\Schema\Schema;
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\StringType;
require_once 'vendor/autoload.php';
class UserProperties extends AbstractInputObjectType
{
public function build($config)
{
$config->addFields([
'name' => [
'type' => new StringType(),
],
'email' => [
'type' => new StringType(),
]
]);
}
}
$processor = new Processor(new Schema([
'query' => new ObjectType([
'name' => 'RootQueryType',
'fields' => [
'me' => [
'type' => new UserProperties(),
'resolve' => function() {
return [
'name' => 'Alex',
'email' => 'alex@gmail.com'
];
}
]
]
]),
'mutation' => new ObjectType([
'name' => 'RootMutation',
'fields' => [
'createUser' => [
'type' => new UserProperties(),
'args' => [
'user' => new UserProperties()
],
'resolve' => function($value, $args, $info) {
return $args['user'];
}
]
]
])
]));
//$payload = '{ me {name, email} }';
$payload = 'mutation { createUser(user: { name: "Robot", email: "robot@gmail.com"} ) {name, email} }';
$processor->processPayload($payload);
echo json_encode($processor->getResponseData()) . "\n";