Closed sabina-talipova closed 9 months ago
The reason changing the order of the fields in the schema affected the results is because the underlying GraphQL library we're using ignores the order that fields are entered in the query arguments. It uses the order that the fields were defined in the schema.
I've added a new commit on top of yours to resolve this. It also changes the test to use a query provider so it will run all of the FilterAndSort scenarios even if one fails. I removed the scenarios that had commented out tests because they weren't actually contributing anything to the test coverage.
Normally I would have asked you to make those changes, but I didn't know what changes were necessary or even possible - and to find that out I had to essentially do the full implementation. At that point it was just easier to commit that implementation rather than ask you to redo what I had just done.
myField
and then by AuthorID
to protect us against regressionsread
(not read one - but read many) querysrc/Schema/Plugin/SortPlugin.php
Please also check if this bug affects graphql 4 - if so, we need to retarget to 4.3
Open new PR for 4.3:
Description
Even if a method receives several parameters, then sorting occurs by the field of the arguments that is last specified in the schema, and not in the passed parameters. That is, if
SilverStripe\GraphQL\Tests\Fake\DataObjectFake
has the following schemaand sorting is required
AuthorID => DESC, myField => ASC
, then sorting was done only byAuthorID
, since in the schema this field is indicated after myField. Therefore, the call$list->sort()
must be completed after all the necessary processing has been carried out.Parent issue