Skip to content

Commit 671f5d1

Browse files
authored
Merge pull request #67 from aszenz/6.0
fix: for symfony 6 and php8.1
2 parents 7b1ee6e + 121057e commit 671f5d1

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

src/ConstraintViolationException.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,14 @@ public function isClientSafe(): bool
2828
return true;
2929
}
3030

31-
/**
32-
* Returns string describing a category of the error.
33-
*
34-
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
35-
*/
36-
public function getCategory(): string
37-
{
38-
return 'Validate';
39-
}
40-
4131
/**
4232
* Returns the "extensions" object attached to the GraphQL error.
4333
*
4434
* @return array<string, mixed>
4535
*/
4636
public function getExtensions(): array
4737
{
48-
$extensions = [];
38+
$extensions = ['category' => 'Validate'];
4939
$code = $this->violation->getCode();
5040
if (! empty($code)) {
5141
$extensions['code'] = $code;

src/Mappers/Parameters/ParameterValidator.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Type\Definition\InputType;
88
use GraphQL\Type\Definition\ResolveInfo;
9+
use GraphQL\Type\Definition\Type;
910
use Symfony\Component\Validator\Constraint;
1011
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1112
use Symfony\Component\Validator\Context\ExecutionContext;
@@ -40,13 +41,8 @@ public function __construct(InputTypeParameterInterface $parameter, string $para
4041
$this->translator = $translator;
4142
}
4243

43-
/**
44-
* @param array<string, mixed> $args
45-
* @param mixed $context
46-
*
47-
* @return mixed
48-
*/
49-
public function resolve(object|null $source, array $args, $context, ResolveInfo $info)
44+
/** @param array<string, mixed> $args */
45+
public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed
5046
{
5147
$value = $this->parameter->resolve($source, $args, $context, $info);
5248

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

70-
public function getType(): InputType
66+
public function getType(): InputType&Type
7167
{
7268
return $this->parameter->getType();
7369
}
@@ -77,8 +73,7 @@ public function hasDefaultValue(): bool
7773
return $this->parameter->hasDefaultValue();
7874
}
7975

80-
/** @return mixed */
81-
public function getDefaultValue()
76+
public function getDefaultValue(): mixed
8277
{
8378
return $this->parameter->getDefaultValue();
8479
}

tests/ConstraintValidationExceptionTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ public function testException()
1313
$exception = new ConstraintViolationException(new ConstraintViolation('foo', 'foo {bar}', ['bar' => 'baz'], null, null, 'invalidValue', null, 'myCode'));
1414
$this->assertSame(400, $exception->getCode());
1515
$this->assertTrue($exception->isClientSafe());
16-
$this->assertSame('Validate', $exception->getCategory());
17-
$this->assertSame(['code' => 'myCode'], $exception->getExtensions());
16+
$this->assertSame(['category' => 'Validate', 'code' => 'myCode'], $exception->getExtensions());
1817

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

0 commit comments

Comments
 (0)