Skip to content

Commit 46415ff

Browse files
supresysex-sh
andauthored
fix: allow adding properties starting with 'set' (#779)
* fix: allow adding properties starting with 'set' Now legitimate properties with prefix 'set' are cut. Such as 'settled', 'settings', 'setup'... Also, all setters are cut out despite the presence of an explicit 'Field' indication. This shouldn't break backwards compatibility because it requires explicitly specifying 'Field' attribute. * test: check presence of field with 'set' prefix Checks whether fields that begin with 'set' have been lost as a result of constructing the schema. --------- Co-authored-by: ex-sh <[email protected]>
1 parent 7c6974c commit 46415ff

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/FieldsBuilder.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,6 @@ private function getFieldsByMethodAnnotations(
444444
$methodName = $refMethod->getName();
445445

446446
if ($queryAnnotation instanceof Field) {
447-
if (str_starts_with($methodName, 'set')) {
448-
continue;
449-
}
450447
$for = $queryAnnotation->getFor();
451448
if ($typeName && $for && ! in_array($typeName, $for)) {
452449
continue;

tests/FieldsBuilderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithMagicProperty;
6161
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithMagicPropertyType;
6262
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithPrefetchMethods;
63+
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithSetPrefix;
6364
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithSourceFieldInterface;
6465
use TheCodingMachine\GraphQLite\Fixtures\TestTypeWithSourceFieldInvalidParameterAnnotation;
6566
use TheCodingMachine\GraphQLite\Mappers\CannotMapTypeException;
@@ -440,6 +441,16 @@ public function testSourceFieldIsId(): void
440441
$this->assertInstanceOf(IDType::class, $fields['test']->getType()->getWrappedType());
441442
}
442443

444+
public function testFieldWithSetPrefixPresence(): void
445+
{
446+
$queryProvider = $this->buildFieldsBuilder();
447+
$fields = $queryProvider->getFields(new TestTypeWithSetPrefix());
448+
$this->assertCount(2, $fields);
449+
450+
$this->assertSame('settings', $fields['settings']->name);
451+
$this->assertSame('numberOfParameters', $fields['numberOfParameters']->name);
452+
}
453+
443454
public function testFromSourceFieldsInterface(): void
444455
{
445456
$queryProvider = new FieldsBuilder(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TheCodingMachine\GraphQLite\Fixtures;
6+
7+
use TheCodingMachine\GraphQLite\Annotations\Field;
8+
use TheCodingMachine\GraphQLite\Annotations\Type;
9+
10+
#[Type(class: TestObject::class)]
11+
class TestTypeWithSetPrefix
12+
{
13+
#[Field]
14+
public function settings(): string
15+
{
16+
return 'settings';
17+
}
18+
19+
#[Field(name: 'numberOfParameters')]
20+
public function setOfParameters(): int
21+
{
22+
return 4;
23+
}
24+
}

0 commit comments

Comments
 (0)