Skip to content

Commit c20063e

Browse files
committed
Add a test to assert that only the passed fields from an input object are validated
1 parent e6d2f8c commit c20063e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

tests/Functional/App/config/validator/mapping/Mutation.types.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,11 @@ Mutation:
138138
validation:
139139
cascade:
140140
groups: ['group2']
141+
142+
onlyPassedFieldsValidation:
143+
type: Boolean
144+
resolve: '@=m("mutation_mock", args)'
145+
args:
146+
person:
147+
validation: cascade
148+
type: Person!
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Person:
2+
type: input-object
3+
config:
4+
fields:
5+
firstName:
6+
type: String
7+
validation:
8+
- NotBlank: ~
9+
- NotNull: ~
10+
surname:
11+
type: String
12+
validation:
13+
- NotBlank: ~
14+
- NotNull: ~

tests/Functional/Validator/InputValidatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ public function testLinkedConstraintsValidationPasses(): void
8787
$this->assertTrue($result['data']['linkedConstraintsValidation']);
8888
}
8989

90+
public function testOnlyPassedFieldsValidated(): void
91+
{
92+
$query = '
93+
mutation {
94+
onlyPassedFieldsValidation(
95+
person: { firstName: "Joe" }
96+
)
97+
}
98+
';
99+
100+
$result = $this->executeGraphQLRequest($query);
101+
102+
$this->assertTrue(empty($result['errors']));
103+
$this->assertTrue($result['data']['onlyPassedFieldsValidation']);
104+
}
105+
90106
public function testLinkedConstraintsValidationFails(): void
91107
{
92108
$query = '

0 commit comments

Comments
 (0)