|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OverblogGraphQLPhpGenerator package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLGenerator\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\Type; |
|
15
|
|
|
|
|
16
|
|
|
abstract class Resolver |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Type */ |
|
19
|
|
|
private static $humanType; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Type */ |
|
22
|
|
|
private static $droidType; |
|
23
|
|
|
|
|
24
|
|
|
private function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function getHumanType() |
|
29
|
|
|
{ |
|
30
|
|
|
return self::$humanType; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function getDroidType() |
|
34
|
|
|
{ |
|
35
|
|
|
return self::$droidType; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Type $humanType |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function setHumanType($humanType) |
|
42
|
|
|
{ |
|
43
|
|
|
self::$humanType = $humanType; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Type $droidType |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function setDroidType($droidType) |
|
50
|
|
|
{ |
|
51
|
|
|
self::$droidType = $droidType; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public static function resolveType($obj) |
|
55
|
|
|
{ |
|
56
|
|
|
$humans = StarWarsData::humans(); |
|
57
|
|
|
$droids = StarWarsData::droids(); |
|
58
|
|
|
if (isset($humans[$obj['id']])) { |
|
59
|
|
|
return static::getHumanType(); |
|
60
|
|
|
} |
|
61
|
|
|
if (isset($droids[$obj['id']])) { |
|
62
|
|
|
return static::getDroidType(); |
|
63
|
|
|
} |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function getFriends($droidOrHuman) |
|
68
|
|
|
{ |
|
69
|
|
|
return StarWarsData::getFriends($droidOrHuman); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public static function getHero($root, $args) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
return StarWarsData::getHero(isset($args['episode']['name']) ? $args['episode']['name'] : null); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function getHuman($root, $args) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$humans = StarWarsData::humans(); |
|
80
|
|
|
return isset($humans[$args['id']]) ? $humans[$args['id']] : null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function getDroid($root, $args) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$droids = StarWarsData::droids(); |
|
86
|
|
|
return isset($droids[$args['id']]) ? $droids[$args['id']] : null; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public static function getDateTime($root, $args) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
return isset($args['dateTime']) ? $args['dateTime'] : new \DateTime('2016-11-28 12:00:00'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.