diff --git a/composer.json b/composer.json index 0ab2ded..7d9ba70 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": "^8.1", "thecodingmachine/safe": "^2", - "webonyx/graphql-php": "^15.0" + "webonyx/graphql-php": "^15.4" }, "require-dev": { "doctrine/coding-standard": "^12.0", diff --git a/src/Builder/FieldBuilder.php b/src/Builder/FieldBuilder.php index 1407387..9906855 100644 --- a/src/Builder/FieldBuilder.php +++ b/src/Builder/FieldBuilder.php @@ -63,8 +63,13 @@ public function setDescription(string $description): self * * @return $this */ - public function addArgument(string $name, $type, string|null $description = null, mixed $defaultValue = null): self - { + public function addArgument( + string $name, + $type, + string|null $description = null, + mixed $defaultValue = null, + string|null $deprecationReason = null, + ): self { if ($this->args === null) { $this->args = []; } @@ -80,6 +85,11 @@ public function addArgument(string $name, $type, string|null $description = null $value['defaultValue'] = $defaultValue; } + if ($deprecationReason !== null) { + /** @psalm-suppress MixedAssignment */ + $value['deprecationReason'] = $deprecationReason; + } + $this->args[$name] = $value; return $this; diff --git a/src/Builder/InputFieldBuilder.php b/src/Builder/InputFieldBuilder.php index bb08b64..f685db7 100644 --- a/src/Builder/InputFieldBuilder.php +++ b/src/Builder/InputFieldBuilder.php @@ -62,6 +62,14 @@ public function setDescription(string $description): self return $this; } + /** @return $this */ + public function setDeprecationReason(string|null $deprecationReason): self + { + $this->deprecationReason = $deprecationReason; + + return $this; + } + /** @psalm-return InputObjectFieldConfig */ public function build(): array { @@ -73,7 +81,6 @@ public function build(): array ]; $property = new ReflectionProperty($this, 'defaultValue'); - $property->setAccessible(true); if ($property->isInitialized($this)) { /** @psalm-suppress MixedAssignment */ $config['defaultValue'] = $this->defaultValue; diff --git a/tests/Builder/FieldBuilderTest.php b/tests/Builder/FieldBuilderTest.php index dbcff6c..81d2e20 100644 --- a/tests/Builder/FieldBuilderTest.php +++ b/tests/Builder/FieldBuilderTest.php @@ -18,7 +18,7 @@ public function testCreate(): void ->setDeprecationReason('Deprecated') ->setDescription('SomeDescription') ->setResolver(static fn (): string => 'Resolver result') - ->addArgument('arg1', Type::int(), 'Argument Description', 1) + ->addArgument('arg1', Type::int(), 'Argument Description', 1, 'Reason') ->build(); self::assertSame('SomeField', $field['name']); @@ -43,6 +43,7 @@ public function testCreate(): void self::assertIsArray($args['arg1']); self::assertSame(Type::int(), $args['arg1']['type']); self::assertSame('Argument Description', $args['arg1']['description']); + self::assertSame('Reason', $args['arg1']['deprecationReason']); self::assertSame(1, $args['arg1']['defaultValue']); } } diff --git a/tests/Builder/InputFieldBuilderTest.php b/tests/Builder/InputFieldBuilderTest.php index 3fb40f9..5030802 100644 --- a/tests/Builder/InputFieldBuilderTest.php +++ b/tests/Builder/InputFieldBuilderTest.php @@ -15,6 +15,7 @@ public function testCreate(): void $field = InputFieldBuilder::create('SomeField', Type::string()) ->setDefaultValue(null) ->setDescription('SomeDescription') + ->setDeprecationReason('Reason') ->build(); self::assertSame('SomeField', $field['name']); @@ -22,6 +23,8 @@ public function testCreate(): void self::assertNull($field['defaultValue']); self::assertArrayHasKey('description', $field); self::assertSame('SomeDescription', $field['description']); + self::assertArrayHasKey('deprecationReason', $field); + self::assertSame('Reason', $field['deprecationReason']); } public function testCreateWithoutDefaultValue(): void