|
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
|
22 |
|
public function getName() |
|
25
|
|
|
{ |
|
26
|
22 |
|
return '__Schema'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
public static function resolveQueryType($value) |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var AbstractSchema|Field $value */ |
|
32
|
4 |
|
return $value->getQueryType(); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
2 |
|
public static function resolveMutationType($value) |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var AbstractSchema|Field $value */ |
|
38
|
2 |
|
return $value->getMutationType()->hasFields() ? $value->getMutationType() : null; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
public static function resolveSubscriptionType() { |
|
42
|
1 |
|
return null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
8 |
|
public function build($config) |
|
46
|
|
|
{ |
|
47
|
|
|
$config |
|
48
|
8 |
|
->addField(new Field([ |
|
49
|
8 |
|
'name' => 'queryType', |
|
50
|
8 |
|
'type' => new QueryType(), |
|
51
|
8 |
|
'resolve' => [get_class($this), 'resolveQueryType'] |
|
52
|
|
|
])) |
|
53
|
8 |
|
->addField(new Field([ |
|
54
|
8 |
|
'name' => 'mutationType', |
|
55
|
8 |
|
'type' => new QueryType(), |
|
56
|
8 |
|
'resolve' => [get_class($this), 'resolveMutationType'] |
|
57
|
|
|
])) |
|
58
|
8 |
|
->addField(new Field([ |
|
59
|
8 |
|
'name' => 'subscriptionType', |
|
60
|
8 |
|
'type' => new ObjectType([ |
|
61
|
8 |
|
'name' => '__Subscription', |
|
62
|
|
|
'fields' => [ |
|
63
|
|
|
'name' => ['type' => TypeMap::TYPE_STRING] |
|
64
|
|
|
] |
|
65
|
|
|
]), |
|
66
|
8 |
|
'resolve' => [get_class($this), 'resolveSubscriptionType'] |
|
67
|
|
|
])) |
|
68
|
8 |
|
->addField(new TypesField()) |
|
69
|
8 |
|
->addField(new Field([ |
|
70
|
8 |
|
'name' => 'directives', |
|
71
|
8 |
|
'type' => new ListType(new DirectiveType()) |
|
72
|
|
|
])); |
|
73
|
8 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
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: