strawberry-django-plus icon indicating copy to clipboard operation
strawberry-django-plus copied to clipboard

Query optimization based on type hints for non-model fields?

Open blueyed opened this issue 1 year ago • 4 comments

A field that represents a model property will not be handled by the query optimizer: https://github.com/blb-ventures/strawberry-django-plus/blob/9a54dd0378b31302b99754704ccd9f1025f43fbd/strawberry_django_plus/optimizer.py#L163-L166

It could get derived from the type hint though, couldn't it?

Specifying field_name, which gets translated into django_name works. Is this supposed to work like/for this? Are there unwanted side effects given that it is of type Foo, but not necessarily the actual foreign key / linked object?

    special_foo: Foo = gql.django.field(
        field_name="foo",  # workaround? other side effects?
    )

As for now I am happy with adding only/select_related manually (related: https://github.com/blb-ventures/strawberry-django-plus/issues/152).

blueyed avatar Dec 16 '22 15:12 blueyed