Skip to content

Commit 95b46b7

Browse files
committed
Add missing AddField arguments
1 parent 0fc1759 commit 95b46b7

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/Type/Builder/Config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
abstract class Config
66
{
7+
78
/**
8-
* @var \ArrayObject
9+
* @var array
910
*/
1011
private $config;
1112

src/Type/Builder/ObjectTypeConfig.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,18 @@ public function description($description)
1616
return $this;
1717
}
1818

19-
public function addField($name, $type, callable $resolve = null, $description = null, ArgsConfig $args = null)
19+
public function addField($name, $type, callable $resolve = null, $description = null, ArgsConfig $args = null, callable $complexity = null, $deprecationReason = null)
2020
{
2121
$field = [
2222
'name' => $name,
2323
'type' => $type,
24+
'description' => $description,
25+
'resolve' => $resolve,
26+
'complexity' => $complexity,
27+
'deprecationReason' => $deprecationReason,
28+
'args' => null === $args ? [] : $args->build(),
2429
];
2530

26-
if (null !== $description) {
27-
$field['description'] = $description;
28-
}
29-
30-
if (null !== $resolve) {
31-
$field['resolve'] = $resolve;
32-
}
33-
34-
if (null !== $args) {
35-
$field['args'] = $args->build();
36-
}
37-
3831
$this->addConfig('fields', $field);
3932

4033
return $this;

tests/Type/Builder/ObjectTypeConfigTest.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,34 @@ public function testBuild()
1414
->addArg('arg1', Type::boolean(), true, 'description arg1')
1515
->addArg('arg2', Type::string(), 'defaultVal', 'description arg2');
1616

17+
$field1Resolver = function () {
18+
return 'resolve it!';
19+
};
20+
$isTypeOf = function () {
21+
return true;
22+
};
23+
$isTypeOf = function () {
24+
return [];
25+
};
26+
1727
$config = ObjectTypeConfig::create()
1828
->name('TypeName')
19-
->addField('field1', Type::string(), null, 'description field1', $args)
29+
->addField('field1', Type::string(), $field1Resolver, 'description field1', $args)
2030
->addField('field2', Type::nonNull(Type::string()))
21-
;
31+
->description('My new Object')
32+
->isTypeOf($isTypeOf)
33+
->resolveField();
2234

2335
$this->assertEquals(
2436
[
2537
'name' => 'TypeName',
26-
'fields' => [
38+
'description' => 'My new Object',
39+
'fields' => [
2740
[
2841
'name' => 'field1',
2942
'type' => Type::string(),
3043
'description' => 'description field1',
44+
'resolve' => $field1Resolver,
3145
'args' => [
3246
[
3347
'name' => 'arg1',
@@ -42,12 +56,21 @@ public function testBuild()
4256
'defaultValue' => 'defaultVal',
4357
],
4458
],
59+
'complexity' => null,
60+
'deprecationReason' => null,
4561
],
4662
[
4763
'name' => 'field2',
4864
'type' => Type::nonNull(Type::string()),
65+
'description' => null,
66+
'resolve' => null,
67+
'complexity' => null,
68+
'deprecationReason' => null,
69+
'args' => [],
4970
],
5071
],
72+
'isTypeOf' => $isTypeOf,
73+
'resolveField' => null,
5174
],
5275
$config->build()
5376
);

0 commit comments

Comments
 (0)