forked from youshido-php/GraphQL
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIssue109Schema.php
More file actions
72 lines (67 loc) · 2.84 KB
/
Copy pathIssue109Schema.php
File metadata and controls
72 lines (67 loc) · 2.84 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Youshido\Tests\Issues\Issue109;
use Youshido\GraphQL\Config\Schema\SchemaConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Schema\AbstractSchema;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;
class Issue109Schema extends AbstractSchema
{
#[\Override]
public function build(SchemaConfig $config)
{
$config->setQuery(
new ObjectType([
'name' => 'RootQueryType',
'fields' => [
'latestPost' => [
'type' => new ObjectType([
'name' => 'Post',
'fields' => [
'id' => [
'type' => new IntType(),
'args' => [
'comment_id' => new IntType()
]
],
'comments' => [
'type' => new ListType(new ObjectType([
'name' => 'Comment',
'fields' => [
'comment_id' => new IntType()
]
])),
'args' => [
'comment_id' => new IntType()
]
]
]
]),
'resolve' => function ($source, array $args, ResolveInfo $info) {
$internalArgs = [
'comment_id' => 200
];
if ($field = $info->getFieldAST('comments')->hasArguments()) {
$internalArgs['comment_id'] = $info->getFieldAST('comments')->getArgumentValue('comment_id');
}
return [
"id" => 1,
"title" => "New approach in API has been revealed",
"summary" => "In two words - GraphQL Rocks!",
"comments" => [
[
"comment_id" => $internalArgs['comment_id']
]
]
];
},
'args' => [
'id' => new IntType()
]
]
]
])
);
}
}