Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for symfony 6 and php8.1 #67

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/ConstraintViolationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,14 @@ public function isClientSafe(): bool
return true;
}

/**
* Returns string describing a category of the error.
*
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
*/
public function getCategory(): string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientAware no longer has this method now, see webonyx/graphql-php#830 for why they removed the category

{
return 'Validate';
}

/**
* Returns the "extensions" object attached to the GraphQL error.
*
* @return array<string, mixed>
*/
public function getExtensions(): array
{
$extensions = [];
$extensions = ['category' => 'Validate'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep tests running and for backwards compatibility i added category to extensions manually

$code = $this->violation->getCode();
if (! empty($code)) {
$extensions['code'] = $code;
Expand Down
15 changes: 5 additions & 10 deletions src/Mappers/Parameters/ParameterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use GraphQL\Type\Definition\InputType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\Context\ExecutionContext;
Expand Down Expand Up @@ -40,13 +41,8 @@ public function __construct(InputTypeParameterInterface $parameter, string $para
$this->translator = $translator;
}

/**
* @param array<string, mixed> $args
* @param mixed $context
*
* @return mixed
*/
public function resolve(object|null $source, array $args, $context, ResolveInfo $info)
/** @param array<string, mixed> $args */
public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed
{
$value = $this->parameter->resolve($source, $args, $context, $info);

Expand All @@ -67,7 +63,7 @@ public function resolve(object|null $source, array $args, $context, ResolveInfo
return $value;
}

public function getType(): InputType
public function getType(): InputType&Type
{
return $this->parameter->getType();
}
Expand All @@ -77,8 +73,7 @@ public function hasDefaultValue(): bool
return $this->parameter->hasDefaultValue();
}

/** @return mixed */
public function getDefaultValue()
public function getDefaultValue(): mixed
{
return $this->parameter->getDefaultValue();
}
Expand Down
5 changes: 2 additions & 3 deletions tests/ConstraintValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public function testException()
$exception = new ConstraintViolationException(new ConstraintViolation('foo', 'foo {bar}', ['bar' => 'baz'], null, null, 'invalidValue', null, 'myCode'));
$this->assertSame(400, $exception->getCode());
$this->assertTrue($exception->isClientSafe());
$this->assertSame('Validate', $exception->getCategory());
$this->assertSame(['code' => 'myCode'], $exception->getExtensions());
$this->assertSame(['category' => 'Validate', 'code' => 'myCode'], $exception->getExtensions());

$exception = new ConstraintViolationException(new ConstraintViolation('foo', 'foo {bar}', ['bar' => 'baz'], null, null, 'invalidValue'));
$this->assertSame([], $exception->getExtensions());
$this->assertSame(['category' => 'Validate'], $exception->getExtensions());
}
}