@@ -13,6 +13,9 @@ |
||
13 | 13 | |
14 | 14 | trait ResolvableObjectTrait { |
15 | 15 | |
16 | + /** |
|
17 | + * @param string|boolean $value |
|
18 | + */ |
|
16 | 19 | public function resolve($value, array $args, ResolveInfo $info) |
17 | 20 | { |
18 | 21 | if ($this->resolveFunctionCache === null) { |
@@ -13,34 +13,34 @@ |
||
13 | 13 | |
14 | 14 | trait ResolvableObjectTrait { |
15 | 15 | |
16 | - public function resolve($value, array $args, ResolveInfo $info) |
|
17 | - { |
|
16 | + public function resolve($value, array $args, ResolveInfo $info) |
|
17 | + { |
|
18 | 18 | if ($this->resolveFunctionCache === null) { |
19 | - $this->resolveFunctionCache = $this->getConfig()->getResolveFunction(); |
|
19 | + $this->resolveFunctionCache = $this->getConfig()->getResolveFunction(); |
|
20 | 20 | |
21 | - if (!$this->resolveFunctionCache) { |
|
21 | + if (!$this->resolveFunctionCache) { |
|
22 | 22 | $this->resolveFunctionCache = false; |
23 | - } |
|
23 | + } |
|
24 | 24 | } |
25 | 25 | if ($this->resolveFunctionCache) { |
26 | - $resolveFunction = $this->resolveFunctionCache; |
|
26 | + $resolveFunction = $this->resolveFunctionCache; |
|
27 | 27 | |
28 | - return $resolveFunction($value, $args, $info); |
|
28 | + return $resolveFunction($value, $args, $info); |
|
29 | 29 | } else { |
30 | - if (is_array($value) && array_key_exists($this->getName(), $value)) { |
|
30 | + if (is_array($value) && array_key_exists($this->getName(), $value)) { |
|
31 | 31 | return $value[$this->getName()]; |
32 | - } elseif (is_object($value)) { |
|
32 | + } elseif (is_object($value)) { |
|
33 | 33 | return TypeService::getPropertyValue($value, $this->getName()); |
34 | - } elseif ($this->getType()->getNamedType()->getKind() == TypeMap::KIND_SCALAR) { |
|
34 | + } elseif ($this->getType()->getNamedType()->getKind() == TypeMap::KIND_SCALAR) { |
|
35 | 35 | return null; |
36 | - } else { |
|
36 | + } else { |
|
37 | 37 | throw new \Exception(sprintf('Property "%s" not found in resolve result', $this->getName())); |
38 | - } |
|
38 | + } |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | |
42 | 42 | |
43 | - public function getResolveFunction() { |
|
43 | + public function getResolveFunction() { |
|
44 | 44 | return $this->getConfig()->getResolveFunction(); |
45 | - } |
|
45 | + } |
|
46 | 46 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function testSetVariableParseJson() |
54 | 54 | { |
55 | 55 | $variables = '{"foo": "bar"}'; |
56 | - $expectedVariableArray = [ 'foo' => 'bar' ]; |
|
56 | + $expectedVariableArray = ['foo' => 'bar']; |
|
57 | 57 | |
58 | 58 | $request = new Request([], $variables); |
59 | 59 | $this->assertEquals($expectedVariableArray, $request->getVariables()); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | 'args' => [ |
37 | 37 | 'episode' => ['type' => new EpisodeEnum()] |
38 | 38 | ], |
39 | - 'resolve' => function ($root, $args) { |
|
39 | + 'resolve' => function($root, $args) { |
|
40 | 40 | return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null); |
41 | 41 | }, |
42 | 42 | ]) |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | 'args' => [ |
47 | 47 | 'id' => new IdType() |
48 | 48 | ], |
49 | - 'resolve' => function ($value = null, $args = []) { |
|
49 | + 'resolve' => function($value = null, $args = []) { |
|
50 | 50 | $humans = StarWarsData::humans(); |
51 | 51 | |
52 | 52 | return isset($humans[$args['id']]) ? $humans[$args['id']] : null; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | 'args' => [ |
59 | 59 | 'id' => new IdType() |
60 | 60 | ], |
61 | - 'resolve' => function ($value = null, $args = []) { |
|
61 | + 'resolve' => function($value = null, $args = []) { |
|
62 | 62 | $droids = StarWarsData::droids(); |
63 | 63 | |
64 | 64 | return isset($droids[$args['id']]) ? $droids[$args['id']] : null; |
@@ -9,8 +9,6 @@ |
||
9 | 9 | |
10 | 10 | |
11 | 11 | use Youshido\GraphQL\Config\Field\InputFieldConfig; |
12 | -use Youshido\GraphQL\Config\Traits\ResolvableObjectTrait; |
|
13 | -use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType; |
|
14 | 12 | use Youshido\GraphQL\Type\InputTypeInterface; |
15 | 13 | use Youshido\GraphQL\Type\Traits\AutoNameTrait; |
16 | 14 | use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait; |
@@ -45,7 +45,7 @@ |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | foreach ($value->getTypes() as $type) { |
48 | - $this->collectTypes($type); |
|
48 | + $this->collectTypes($type); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return array_values($this->types); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $edgeFields = !empty($config['edgeFields']) ? $config['edgeFields'] : []; |
53 | 53 | |
54 | 54 | $edgeType = new ObjectType([ |
55 | - 'name' => $name . 'Edge', |
|
55 | + 'name' => $name.'Edge', |
|
56 | 56 | 'description' => 'An edge in a connection.', |
57 | 57 | 'fields' => array_merge([ |
58 | 58 | 'node' => [ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : []; |
85 | 85 | |
86 | 86 | $connectionType = new ObjectType([ |
87 | - 'name' => $name . 'Connection', |
|
87 | + 'name' => $name.'Connection', |
|
88 | 88 | 'description' => 'A connection to a list of items.', |
89 | 89 | 'fields' => array_merge([ |
90 | 90 | 'pageInfo' => [ |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | public function isValidValue($value) |
44 | 44 | { |
45 | - if($value instanceof InputObject) { |
|
45 | + if ($value instanceof InputObject) { |
|
46 | 46 | $value = $value->getValue(); |
47 | 47 | } |
48 | 48 | |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | $typeConfig = $this->getConfig(); |
54 | - $requiredFields = array_filter($typeConfig->getFields(), function (FieldInterface $field) { |
|
54 | + $requiredFields = array_filter($typeConfig->getFields(), function(FieldInterface $field) { |
|
55 | 55 | return $field->getType()->getKind() == TypeMap::KIND_NON_NULL; |
56 | 56 | }); |
57 | 57 | |
58 | 58 | foreach ($value as $valueKey => $valueItem) { |
59 | - if($valueItem instanceof Variable) { |
|
59 | + if ($valueItem instanceof Variable) { |
|
60 | 60 | $valueItem = $valueItem->getValue(); |
61 | 61 | } |
62 | 62 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | { |
87 | 87 | $typeConfig = $this->getConfig(); |
88 | 88 | foreach ($value as $valueKey => $item) { |
89 | - if($item instanceof Variable) { |
|
89 | + if ($item instanceof Variable) { |
|
90 | 90 | $item = $item->getValue(); |
91 | 91 | } |
92 | 92 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | if (!is_array($types)) { |
25 | 25 | throw new \Exception('addTypes accept only array of types'); |
26 | 26 | } |
27 | - foreach($types as $type) { |
|
27 | + foreach ($types as $type) { |
|
28 | 28 | $this->addType($type); |
29 | 29 | } |
30 | 30 | return $this; |
@@ -42,7 +42,9 @@ discard block |
||
42 | 42 | public function addType(TypeInterface $type) |
43 | 43 | { |
44 | 44 | $typeName = $this->getTypeName($type); |
45 | - if ($this->isTypeNameRegistered($typeName)) return $this; |
|
45 | + if ($this->isTypeNameRegistered($typeName)) { |
|
46 | + return $this; |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $this->typesList[$typeName] = $type; |
48 | 50 | return $this; |
@@ -54,7 +56,9 @@ discard block |
||
54 | 56 | } |
55 | 57 | |
56 | 58 | private function getTypeName($type) { |
57 | - if (is_string($type)) return $type; |
|
59 | + if (is_string($type)) { |
|
60 | + return $type; |
|
61 | + } |
|
58 | 62 | if (is_object($type) && $type instanceof AbstractType) { |
59 | 63 | return $type->getName(); |
60 | 64 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/../../../../../vendor/autoload.php'; |
|
4 | -require_once __DIR__ . '/Schema/FactionType.php'; |
|
5 | -require_once __DIR__ . '/Schema/ShipType.php'; |
|
6 | -require_once __DIR__ . '/Schema/TestDataProvider.php'; |
|
7 | -require_once __DIR__ . '/Schema/StarWarsRelaySchema.php'; |
|
3 | +require_once __DIR__.'/../../../../../vendor/autoload.php'; |
|
4 | +require_once __DIR__.'/Schema/FactionType.php'; |
|
5 | +require_once __DIR__.'/Schema/ShipType.php'; |
|
6 | +require_once __DIR__.'/Schema/TestDataProvider.php'; |
|
7 | +require_once __DIR__.'/Schema/StarWarsRelaySchema.php'; |