Skip to content

Commit ba23cad

Browse files
author
Christian Nielsen
committed
fix non null list of non null of input object
1 parent 62d47d2 commit ba23cad

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/Support/Field.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function inferRulesFromType(GraphqlType $type, string $prefix, array $res
118118

119119
// make sure we are dealing with the actual type
120120
if ($type instanceof WrappingType) {
121-
$type = $type->getWrappedType();
121+
$type = $type->getWrappedType(true);
122122
}
123123

124124
// if it is an input object type - the only type we care about here...
@@ -144,12 +144,17 @@ public function getInputTypeRules(InputObjectType $input, string $prefix, array
144144
$rules[$key] = $this->resolveRules($field->rules, $resolutionArguments);
145145
}
146146

147+
$type = $field->type;
148+
if ($field->type instanceof WrappingType) {
149+
$type = $field->type->getWrappedType(true);
150+
}
151+
147152
// then recursively call the parent method to see if this is an
148153
// input object, passing in the new prefix
149-
if ($field->type instanceof InputObjectType) {
154+
if ($type instanceof InputObjectType) {
150155
// in case the field is a self reference we must not do
151156
// a recursive call as it will never stop
152-
if ($field->type->toString() == $input->toString()) {
157+
if ($type->toString() == $input->toString()) {
153158
continue;
154159
}
155160
}

tests/Support/Objects/UpdateExampleMutationWithInputType.php

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public function args(): array
5959
'type' => Type::nonNull(GraphQL::type('ExampleValidationInputObject')),
6060
'rules' => ['required'],
6161
],
62+
63+
'test_with_rules_non_nullable_list_of_non_nullable_input_object' => [
64+
'name' => 'test',
65+
'type' => Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type('ExampleValidationInputObject')))),
66+
],
67+
6268
];
6369
}
6470

tests/Unit/MutationTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function testGetRules(): void
5858
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_input_object.nest.email'), ['email']);
5959
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_input_object.list'), ['required']);
6060
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_input_object.list.*.email'), ['email']);
61+
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_list_of_non_nullable_input_object.*.val'), ['required']);
62+
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_list_of_non_nullable_input_object.*.nest'), ['required']);
63+
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_list_of_non_nullable_input_object.*.nest.email'), ['email']);
64+
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_list_of_non_nullable_input_object.*.list'), ['required']);
65+
$this->assertEquals(Arr::get($rules, 'test_with_rules_non_nullable_list_of_non_nullable_input_object.*.list.*.email'), ['email']);
6166
}
6267

6368
/**

0 commit comments

Comments
 (0)