|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BlogSchema.php |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Examples\Blog\Schema; |
|
7
|
|
|
|
|
8
|
|
|
use Youshido\GraphQL\AbstractSchema; |
|
9
|
|
|
use Youshido\GraphQL\Type\Config\Schema\SchemaConfig; |
|
10
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
|
11
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
12
|
|
|
|
|
13
|
|
|
class BlogSchema extends AbstractSchema |
|
14
|
|
|
{ |
|
15
|
|
|
public function build(SchemaConfig $config) |
|
16
|
|
|
{ |
|
17
|
|
|
$config->getQuery()->addFields([ |
|
18
|
|
|
'latestPost' => new PostType(), |
|
19
|
|
|
'randomBanner' => [ |
|
20
|
|
|
'type' => new BannerType(), |
|
21
|
|
|
'resolve' => function () { |
|
22
|
|
|
return DataProvider::getBanner(rand(1, 10)); |
|
23
|
|
|
} |
|
24
|
|
|
], |
|
25
|
|
|
'pageContentUnion' => [ |
|
26
|
|
|
'type' => new ListType(new ContentBlockUnion()), |
|
27
|
|
|
'resolve' => function () { |
|
28
|
|
|
return [DataProvider::getPost(1), DataProvider::getBanner(1)]; |
|
29
|
|
|
} |
|
30
|
|
|
], |
|
31
|
|
|
'pageContentInterface' => [ |
|
32
|
|
|
'type' => new ListType(new ContentBlockInterface()), |
|
33
|
|
|
'resolve' => function () { |
|
34
|
|
|
return [DataProvider::getPost(2), DataProvider::getBanner(3)]; |
|
35
|
|
|
} |
|
36
|
|
|
] |
|
37
|
|
|
]); |
|
38
|
|
|
$config->getMutation()->addFields([ |
|
39
|
|
|
'likePost' => new LikePost(), |
|
40
|
|
|
'createPost' => [ |
|
41
|
|
|
'type' => new PostType(), |
|
42
|
|
|
'args' => [ |
|
43
|
|
|
'post' => new PostInputType(), |
|
44
|
|
|
'author' => new StringType() |
|
45
|
|
|
], |
|
46
|
|
|
'resolve' => function($value, $args, $type) { |
|
|
|
|
|
|
47
|
|
|
return DataProvider::getPost(10); |
|
48
|
|
|
} |
|
49
|
|
|
] |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.