Skip to content

DjangoObjectType.fields ignores select_related #1375

Closed
@lufte

Description

@lufte
  • What is the current behavior?

The behavior for resolving a ForeignKey field of a DjangoObjectType is not the same when adding the field to fields versus declaring the field explicitly as an attribute of the class. In the second case, an extra query won't be made if the field has been cached by a previous select_related, but the first case always executes an additional query ignoring the select_related.

Create two Models with a foreign key between them, and a schema in which you can list all the parent models with their respective children, using a select_related call in the resolver. In the parent DjangoObjectType, try declaring the child model using both fields and an explicit attribute like child = graphene.NonNull('schema.ChildType'), and count the queries using both strategies.

  • What is the expected behavior?

The select_related field should be honored in both cases.

  • Please tell us about your environment:

    • Version: 3.0.0
    • Platform: Python 3.10.8, graphene==3.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions