0

The default CUD operation in srawberry_django identifies the model to be mutated by the model's id (the database's id column, which is the Primary Key). How can I change this behavior to point to a column's/model's UUID without overriding strawberry_django.mutations.update method?

In simple terms, how to do a search on a field that is not id/PK in strawberry-graphql-djang without mending update method?

Progman
  • 16,827
  • 6
  • 33
  • 48
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124

1 Answers1

0

At the moment of strawberry-graphql-django v0.16.0 it's not possible to do so! The reason is the implementation of get_pk method.

def get_pk(data: dict[str, Any],) -> strawberry.ID | relay.GlobalID | Literal[UNSET] | None:
    pk = data.pop("id", UNSET)
    if pk is UNSET:
        pk = data.pop("pk", UNSET)
    return pk

As you can see, this method assumes that the model identifier is id or pk ONLY!

Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124