yezyilomo / django-restql

Turn your API made with Django REST Framework(DRF) into a GraphQL like API.
https://yezyilomo.github.io/django-restql
MIT License
616 stars 43 forks source link

Bug with parsing CSV-type filters #167

Closed resurrexi closed 4 years ago

resurrexi commented 4 years ago

I'm having issue with restql parsing filter queries when some filters allow comma separated values, specifically ordering filters where multiple fields can be ordered by, e.g. /api/employees/?query=(ordering:last_name,first_name){*}

The error response I get is:

[
    "QuerySyntaxError: expecting '{' on (ordering:last_name,"
]

I don't get the error if I only order by one field. Also, if I attempt to chain the ordering, e.g. /api/employees/?query=(ordering:last_name,ordering:first_name){*}, I get the result that it only orders by the last ordering element (by first_name). It doesn't do the hierarchical ordering that I desire.

The filter backend I'm using is django-filter (link to its OrderingFilter doc), though I doubt it's relevant because django's built-in ordering filter also supports CSV values.

I know the bug happens here but I'm no pypeg2 expert. I'm guessing one potential fix is to maybe change the delimiter to |, e.g. query=(ordering:field1,field2|filter2:field3|filter3:fieldX|...){*}?

resurrexi commented 4 years ago

Ok, I figured it out. I can use quotes within my filter arguments:

/api/employees/?query=(ordering:"last_name,first_name"){*}