strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
406 stars 118 forks source link

Custom filter/order method unexpected value #509

Closed Kitefiko closed 5 months ago

Kitefiko commented 6 months ago

Value of custom filter method is being, by default, resolved via filters._resolve_value

@strawberry_django.filter_field
def multi_filter(self, value: relay.GlobalID):
    # value here is not GlobalID instance, but already resolved node_id (str)
    # so following cannot be currently done

    if value.type_name == "FruitNode":
        ...
    else value.type_name == "VegetableNode":
        ... 
    else:
        raise ValidationError("Incorrect GlobalID type")

Solution: add flag to resolve_value param to filter_field that could be used to change behavior of value.

I believe default behavior for custom filter or order methods should be to not resolve. Current behavior is confusing to users, not just for lack of documentation.

What should be default behavior and can be possibly do breaking change @bellini666 ?

I will create pull with changes shortly.

Upvote & Fund

Fund with Polar