-
Notifications
You must be signed in to change notification settings - Fork 104
/
index.php
49 lines (42 loc) · 1.34 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace BlogTest;
use Examples\Blog\Schema\PostType;
use Youshido\GraphQL\Processor;
use Youshido\GraphQL\Schema;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/Schema/PostType.php'; // including PostType definition
$rootQueryType = new ObjectType([
'name' => 'RootQueryType',
]);
$rootQueryType->addField('latestPost', new PostType());
$processor = new Processor();
$processor->setSchema(new Schema([
'query' => new ObjectType([
'name' => 'RootQueryType',
'fields' => [
'latestPost' => new PostType()
]
]),
'mutation' => new ObjectType([
'name' => 'RootMutationType',
'fields' => [
'likePost' => [
'type' => new IntType(),
'resolve' => function () {
die('resolve');
},
'args' => [
'id' => [
'type' => new IntType()
]
]
]
]
])
]));
$payload = '{ latestPost { title, summary } }';
$payload = 'mutation { likePost(id:5) { likeCount } }';
$response = $processor->processRequest($payload, [])->getResponseData();
echo json_encode($response) . "\n\n";