loopback-component-jsonapi
loopback-component-jsonapi copied to clipboard
Unable to sort using JSONAPI "?sort=somefield"
I'm using EmberJS/Ember Data 2.8.0 to talk to a loopback 2.22.0 server using loopback-component-jsonapi 1.1.0 backed by a MariaDB database.
When I send the GET request http://localhost:3000/api/shipments?sort=-timestamp the results should be sorted descending by timestamp, however they are not. If I send the GET request http://localhost:3000/api/shipments?filter%5Border%5D=timestamp%20DESC I do get the result sorted descending by timestamp. (That is ...shipments?filter[order]=timestamp DESC urldecoded.)The first format is specified in the JSONAPI spec. The later is the "loopback" way of passing an order filter.
I turned on debugging and I can see that, when the "?sort=" method is used, the "ORDER BY" clause never makes it to the SQL server, so it must not be making it through loopback-component-jsonapi. I'm working around it by manipulating the query string in Ember, but I thought I'd report the bug in case anyone else ran into it or knew how to fix it. :)
Thanks for reporting. Yup, this is a yet to be implemented. This and other features such as correct includes syntax are essentially syntax mappings to loopback syntax. Theres still a tonne of small polish type items like this that it would be great to get done. Ah to have more time :)