1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Date: 03.12.15 |
4
|
|
|
* |
5
|
|
|
* @author Portey Vasil <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Introspection; |
9
|
|
|
|
10
|
|
|
use Youshido\GraphQL\Field\Field; |
11
|
|
|
use Youshido\GraphQL\Introspection\Field\TypesField; |
12
|
|
|
use Youshido\GraphQL\Schema\AbstractSchema; |
13
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
14
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
15
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
16
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
17
|
|
|
|
18
|
|
|
class SchemaType extends AbstractObjectType |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return String type name |
23
|
|
|
*/ |
24
|
65 |
|
public function getName() |
25
|
|
|
{ |
26
|
65 |
|
return '__Schema'; |
27
|
|
|
} |
28
|
|
|
|
29
|
4 |
|
public function resolveQueryType($value) |
30
|
|
|
{ |
31
|
|
|
/** @var AbstractSchema|Field $value */ |
32
|
4 |
|
return $value->getQueryType(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public function resolveMutationType($value) |
36
|
|
|
{ |
37
|
|
|
/** @var AbstractSchema|Field $value */ |
38
|
2 |
|
return $value->getMutationType()->hasFields() ? $value->getMutationType() : null; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public function resolveSubscriptionType() |
42
|
|
|
{ |
43
|
1 |
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
public function resolveDirectives($value) |
47
|
|
|
{ |
48
|
|
|
/** @var AbstractSchema|Field $value */ |
49
|
2 |
|
$dirs = $value->getDirectiveList()->getDirectives(); |
|
|
|
|
50
|
2 |
|
return $dirs; |
51
|
|
|
} |
52
|
|
|
|
53
|
9 |
|
public function build($config) |
54
|
|
|
{ |
55
|
|
|
$config |
56
|
9 |
|
->addField(new Field([ |
57
|
9 |
|
'name' => 'queryType', |
58
|
9 |
|
'type' => new QueryType(), |
59
|
9 |
|
'resolve' => [$this, 'resolveQueryType'] |
60
|
|
|
])) |
61
|
9 |
|
->addField(new Field([ |
62
|
9 |
|
'name' => 'mutationType', |
63
|
9 |
|
'type' => new QueryType(), |
64
|
9 |
|
'resolve' => [$this, 'resolveMutationType'] |
65
|
|
|
])) |
66
|
9 |
|
->addField(new Field([ |
67
|
9 |
|
'name' => 'subscriptionType', |
68
|
9 |
|
'type' => new QueryType(), |
69
|
9 |
|
'resolve' => [$this, 'resolveSubscriptionType'] |
70
|
|
|
])) |
71
|
9 |
|
->addField(new TypesField()) |
72
|
9 |
|
->addField(new Field([ |
73
|
9 |
|
'name' => 'directives', |
74
|
9 |
|
'type' => new ListType(new DirectiveType()), |
75
|
9 |
|
'resolve' => [$this, 'resolveDirectives'] |
76
|
|
|
])); |
77
|
9 |
|
} |
78
|
|
|
} |
79
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: