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

Querying for '__in' #160

Closed TheUKDave closed 4 years ago

TheUKDave commented 4 years ago

I need to be able to filter an API on a list of IDs. I have amended my filter to allow for this, but I cannot find a syntax that will get through to my filter. Is it possible?

It seems anything with a comma in, breaks the parsing and results in a QuerySyntaxError being returned, e.g:

GET /?query=(id__in:1,2){*}

[
    "QuerySyntaxError: expecting '{' on (id__in:1,2){*}"
]
GET /?query=(id__in:[1,2]){*}

[
    "QuerySyntaxError: expecting '{' on (id__in:[1,2]){*}"
]
yezyilomo commented 4 years ago

We just solved this issue yesterday(Duplicate of #157), so make sure you are using v0.9.2. In your case you have to use either single quotes or double quotes to escape special characters(which is comma in this case) i.e

GET /?query=(id__in: "[1,2]"){*}

Refer to the updated documentation for more details about escaping special characters https://django-restql.yezyilomo.com/querying_data/#query-arguments