diff --git a/src/Schema/DataObject/Plugin/QuerySort.php b/src/Schema/DataObject/Plugin/QuerySort.php index 1647bc34..7261a6e6 100644 --- a/src/Schema/DataObject/Plugin/QuerySort.php +++ b/src/Schema/DataObject/Plugin/QuerySort.php @@ -102,6 +102,9 @@ public static function sort(array $context): closure } $filterArgs = $args[$fieldName] ?? []; $paths = NestedInputBuilder::buildPathsFromArgs($filterArgs); + if (empty($paths)) { + return $list; + } $schemaContext = SchemaConfigProvider::get($context); if (!$schemaContext) { throw new Exception(sprintf( @@ -111,6 +114,7 @@ public static function sort(array $context): closure )); } + $normalisedPaths = []; foreach ($paths as $path => $value) { $normalised = $schemaContext->mapPath($rootType, $path); Schema::invariant( @@ -120,10 +124,11 @@ public static function sort(array $context): closure $path, $rootType ); - $list = $list->sort($normalised, $value); + + $normalisedPaths[$normalised] = $value; } - return $list; + return $list->sort($normalisedPaths); }; } diff --git a/tests/Schema/_testFilterAndSort/models.yml b/tests/Schema/_testFilterAndSort/models.yml index 17343286..ccebcf47 100644 --- a/tests/Schema/_testFilterAndSort/models.yml +++ b/tests/Schema/_testFilterAndSort/models.yml @@ -5,8 +5,8 @@ SilverStripe\GraphQL\Tests\Fake\DataObjectFake: filter: true sort: true fields: - myField: true AuthorID: true + myField: true author: fields: firstName: true