graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.28k stars 766 forks source link

Not able to use camelCase in `orderBy` field #1491

Open innateessence opened 8 months ago

innateessence commented 8 months ago

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

I execute a query with these arguments:

{
  "first": 50,
  "kind": "QXNzZXRLaW5kOjMzZGYxZmNhLWI0NTAtNDcyZS05ZmYzLWI5NzcxZmYxMzlkMZ==",
  "after": null,
  "search": null,
  "orderBy": "fuelType"
}

and fuelType (which is fuelType as a JSON column in a Django DB) gets converted to fuel_type before it reaches django's ORM.

The culprit is here: /usr/local/lib/python3.11/site-packages/graphene_django/filter/fields.py (line: 99) resolve_queryset() On the version of graphene_django that I'm currently using (3.2.0).

telegram-cloud-photo-size-1-4974392837344963747-y

execute a query where orderBy has a value that is in camelCase

graphene-django = "==3.2.0"

innateessence commented 8 months ago

Looks like this is indeed expected behavior, based on previously merged PRs addressing this in the past https://github.com/graphql-python/graphene-django/pull/1054

kiendang commented 7 months ago

From a quick look there doesn't seem to be a quick fix for this. One workaround is if you have access to and can change model class you can do

fuel_type = JSONField(..., db_column="fuelType")
innateessence commented 7 months ago

From a quick look there doesn't seem to be a quick fix for this. One workaround is if you have access to and can change model class you can do

fuel_type = JSONField(..., db_column="fuelType")

In my case, I believe this won't work as the key fuelType is dynamically provided from a key from a JSONB field, which is pushed from an external codebase in charge of the data.

Any ideas in regards to bypassing the resolve_queryset function from executing? I don't mind explicitly writing my own order_by functionality in Django's ORM outside of graphene-land.

Alternatively, it'd be nice if we could provide an optional override somehow to prevent this kind of behavior for codebases that have data that expect to perfor an order_by using a value in camelCase, possibly as a kwarg somewhere?