Skip to content

Commit

Permalink
Add a test to assert that only the passed fields from an input object…
Browse files Browse the repository at this point in the history
… are validated
  • Loading branch information
joesaunderson committed May 10, 2024
1 parent e6d2f8c commit c20063e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@ Mutation:
validation:
cascade:
groups: ['group2']

onlyPassedFieldsValidation:
type: Boolean
resolve: '@=m("mutation_mock", args)'
args:
person:
validation: cascade
type: Person!
14 changes: 14 additions & 0 deletions tests/Functional/App/config/validator/mapping/Person.types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Person:
type: input-object
config:
fields:
firstName:
type: String
validation:
- NotBlank: ~
- NotNull: ~
surname:
type: String
validation:
- NotBlank: ~
- NotNull: ~
16 changes: 16 additions & 0 deletions tests/Functional/Validator/InputValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public function testLinkedConstraintsValidationPasses(): void
$this->assertTrue($result['data']['linkedConstraintsValidation']);
}

public function testOnlyPassedFieldsValidated(): void
{
$query = '
mutation {
onlyPassedFieldsValidation(
person: { firstName: "Joe" }
)
}
';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertTrue($result['data']['onlyPassedFieldsValidation']);
}

public function testLinkedConstraintsValidationFails(): void
{
$query = '
Expand Down

0 comments on commit c20063e

Please sign in to comment.