From 36667403ea4c5ca2916443fa6e635be883600387 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 3 Oct 2026 16:50:04 -0600 Subject: [PATCH] Make the sortFields config a bool sortFields was bool|null with a null default, which meant the same as false. It is now a bool, false by default, and Config::getSortFields() returns a bool. Passing null throws Exception\Configuration. Co-Authored-By: Claude Opus 5.5 --- docs/driver.rst | 1 + docs/upgrade.rst | 6 ++++++ docs/versions.rst | 3 ++- src/Config.php | 16 ++++++++-------- src/ConfigBuilder.php | 2 +- test/Feature/ConfigBuilderTest.php | 2 +- test/Feature/ConfigTest.php | 4 ++++ 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/driver.rst b/docs/driver.rst index 5f5b2ea6..b0fc0f67 100644 --- a/docs/driver.rst +++ b/docs/driver.rst @@ -164,6 +164,7 @@ sortFields When entity types are created, and after the definition event, the fields will be sorted alphabetically when set to true. This can aid reading of the documentation created by GraphQL. +The default is false. useHydratorCache diff --git a/docs/upgrade.rst b/docs/upgrade.rst index dc38ff30..ab091afd 100644 --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -173,6 +173,12 @@ parameter is named ``$enable``, as the other boolean methods' are. // 14.0 ConfigBuilder::create()->enableSortFields(); +The ``sortFields`` config value is a ``bool``, ``false`` by default. It was +``bool|null``, where ``null``, the default, meant ``false``. Passing +``'sortFields' => null`` to ``Config`` now throws +``ApiSkeletons\Doctrine\ORM\GraphQL\Exception\Configuration``; remove it or +pass ``false``. + A computed field of a method such as ``getaway()``, whose name only begins with ``get``, is named for the whole method, ``getaway``, rather than ``away``. diff --git a/docs/versions.rst b/docs/versions.rst index f230d13b..15d2bf72 100644 --- a/docs/versions.rst +++ b/docs/versions.rst @@ -72,7 +72,8 @@ ORM versions do not support ``doctrine/persistence`` 4. collection by its ``#[ORM\OrderBy]`` first - Configuration: ``globalEnable`` and ``ignoreFields`` are removed; ``globalByValue`` and ``byValue`` are renamed ``extractByValue``; ``ConfigBuilder::sortFields()`` is renamed - ``enableSortFields()``; config values are validated + ``enableSortFields()``; ``sortFields`` is a ``bool`` and may not be ``null``; config + values are validated - Types: ``decimal`` is a ``String``; date-times are converted to the default timezone; the date and time scalars reject impossible and invalid values and serialize only date objects; filter, connection and input type names change; the ``sort`` filter takes the diff --git a/src/Config.php b/src/Config.php index 33e9e612..31a91b0f 100644 --- a/src/Config.php +++ b/src/Config.php @@ -88,10 +88,10 @@ final class Config protected readonly string|null $entityPrefix; /** - * @var bool|null When set to true entity fields will be - * sorted alphabetically + * @var bool When set to true entity fields will be + * sorted alphabetically */ - protected readonly bool|null $sortFields; + protected readonly bool $sortFields; /** * @var Filters[] An array of filters to exclude from @@ -127,7 +127,7 @@ final class Config 'limit' => ['int'], 'extractByValue' => ['bool', 'null'], 'entityPrefix' => ['string', 'null'], - 'sortFields' => ['bool', 'null'], + 'sortFields' => ['bool'], 'excludeFilters' => ['array'], 'formatJsonAs' => [JsonFormat::class, 'string'], 'useNonNullTypes' => ['bool'], @@ -146,7 +146,7 @@ public function __construct(array $config = []) 'limit' => 1000, 'extractByValue' => null, 'entityPrefix' => null, - 'sortFields' => null, + 'sortFields' => false, 'excludeFilters' => [], 'formatJsonAs' => JsonFormat::String, 'useNonNullTypes' => false, @@ -187,7 +187,7 @@ public function __construct(array $config = []) * * @param array $config * - * @return array{group: string, groupSuffix: string|null, useHydratorCache: bool, useQueryResultCache: bool, batchAssociations: bool, batchLimit: int, limit: int, extractByValue: bool|null, entityPrefix: string|null, sortFields: bool|null, excludeFilters: Filters[], formatJsonAs: JsonFormat, useNonNullTypes: bool} + * @return array{group: string, groupSuffix: string|null, useHydratorCache: bool, useQueryResultCache: bool, batchAssociations: bool, batchLimit: int, limit: int, extractByValue: bool|null, entityPrefix: string|null, sortFields: bool, excludeFilters: Filters[], formatJsonAs: JsonFormat, useNonNullTypes: bool} * * @throws ConfigurationException */ @@ -247,7 +247,7 @@ private function validate(array $config): array ); } - /** @var array{group: string, groupSuffix: string|null, useHydratorCache: bool, useQueryResultCache: bool, batchAssociations: bool, batchLimit: int, limit: int, extractByValue: bool|null, entityPrefix: string|null, sortFields: bool|null, excludeFilters: Filters[], formatJsonAs: JsonFormat, useNonNullTypes: bool} $validated */ + /** @var array{group: string, groupSuffix: string|null, useHydratorCache: bool, useQueryResultCache: bool, batchAssociations: bool, batchLimit: int, limit: int, extractByValue: bool|null, entityPrefix: string|null, sortFields: bool, excludeFilters: Filters[], formatJsonAs: JsonFormat, useNonNullTypes: bool} $validated */ $validated = $config; return $validated; @@ -298,7 +298,7 @@ public function getEntityPrefix(): string|null return $this->entityPrefix; } - public function getSortFields(): bool|null + public function getSortFields(): bool { return $this->sortFields; } diff --git a/src/ConfigBuilder.php b/src/ConfigBuilder.php index 26ed7320..ea232f37 100644 --- a/src/ConfigBuilder.php +++ b/src/ConfigBuilder.php @@ -31,7 +31,7 @@ final class ConfigBuilder private int $limit = 1000; private bool|null $extractByValue = null; private string|null $entityPrefix = null; - private bool|null $sortFields = null; + private bool $sortFields = false; /** @var Filters[] */ private array $excludeFilters = []; diff --git a/test/Feature/ConfigBuilderTest.php b/test/Feature/ConfigBuilderTest.php index 332bd077..5d0c7eef 100644 --- a/test/Feature/ConfigBuilderTest.php +++ b/test/Feature/ConfigBuilderTest.php @@ -217,7 +217,7 @@ public function testDefaultValues(): void $this->assertEquals(1000, $config->getLimit()); $this->assertNull($config->getExtractByValue()); $this->assertNull($config->getEntityPrefix()); - $this->assertNull($config->getSortFields()); + $this->assertFalse($config->getSortFields()); $this->assertEquals([], $config->getExcludeFilters()); } diff --git a/test/Feature/ConfigTest.php b/test/Feature/ConfigTest.php index dfcd64c4..67b43eb9 100644 --- a/test/Feature/ConfigTest.php +++ b/test/Feature/ConfigTest.php @@ -40,6 +40,10 @@ public static function invalidValueProvider(): array ['extractByValue' => 1], 'Invalid configuration value for extractByValue: expected bool or null, got int.', ], + 'null sortFields' => [ + ['sortFields' => null], + 'Invalid configuration value for sortFields: expected bool, got null.', + ], 'excludeFilters not an array' => [ ['excludeFilters' => 'eq'], 'Invalid configuration value for excludeFilters: expected array, got string.',