-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support for using attribute as a target to parameter. Deprecate usi…
…ng as a target to the method. Add warning about next major release changes Refs: thecodingmachine/graphqlite#708 (comment)
- Loading branch information
1 parent
2f677f6
commit 750ec00
Showing
5 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,17 @@ public function createUser(string $email, string $password): User | |
|
||
#[Query] | ||
#[Assertion(for: '$email', constraint: new Assert\Email())] | ||
public function findByMail(string $email = '[email protected]'): User | ||
public function findByMailTargetMethod(string $email = '[email protected]'): User | ||
{ | ||
// deprecated way of using the Assertion annotation - as a target of the method | ||
return new User($email, 'foo'); | ||
} | ||
|
||
#[Query] | ||
public function findByMail( | ||
#[Assertion(constraint: new Assert\Email())] | ||
string $email = '[email protected]', | ||
): User { | ||
return new User($email, 'foo'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,6 @@ public function testEndToEndAssert(): void | |
|
||
$errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors']; | ||
|
||
// TODO: find why message is not in French... | ||
$this->assertSame('This value is not a valid email address.', $errors[0]['message']); | ||
$this->assertSame('email', $errors[0]['extensions']['field']); | ||
$this->assertSame('Validate', $errors[0]['extensions']['category']); | ||
|
@@ -151,6 +150,70 @@ public function testEndToEndAssert(): void | |
$this->assertSame('[email protected]', $data['findByMail']['email']); | ||
} | ||
|
||
public function testEndToEndAssertForDeprecatedWay(): void | ||
{ | ||
$schema = $this->getSchema(); | ||
$schema->assertValid(); | ||
|
||
$queryString = ' | ||
{ | ||
findByMailTargetMethod(email: "notvalid") { | ||
} | ||
} | ||
'; | ||
|
||
$result = GraphQL::executeQuery( | ||
$schema, | ||
$queryString, | ||
); | ||
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); | ||
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); | ||
|
||
$errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors']; | ||
|
||
$this->assertSame('This value is not a valid email address.', $errors[0]['message']); | ||
$this->assertSame('email', $errors[0]['extensions']['field']); | ||
$this->assertSame('Validate', $errors[0]['extensions']['category']); | ||
|
||
$queryString = ' | ||
{ | ||
findByMailTargetMethod(email: "[email protected]") { | ||
} | ||
} | ||
'; | ||
|
||
$result = GraphQL::executeQuery( | ||
$schema, | ||
$queryString, | ||
); | ||
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); | ||
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); | ||
|
||
$data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']; | ||
$this->assertSame('[email protected]', $data['findByMailTargetMethod']['email']); | ||
|
||
// Test default parameter | ||
$queryString = ' | ||
{ | ||
findByMailTargetMethod { | ||
} | ||
} | ||
'; | ||
|
||
$result = GraphQL::executeQuery( | ||
$schema, | ||
$queryString, | ||
); | ||
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); | ||
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); | ||
|
||
$data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']; | ||
$this->assertSame('[email protected]', $data['findByMailTargetMethod']['email']); | ||
} | ||
|
||
public function testException(): void | ||
{ | ||
$schemaFactory = $this->getSchemaFactory(); | ||
|