strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
MIT License
394 stars 115 forks source link

How to locate model on uuid instead of id ? #348

Closed ldynia closed 9 months ago

ldynia commented 11 months ago

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?

Upvote & Fund

Fund with Polar

bellini666 commented 10 months ago

This is indeed not possible currently.

What can be done is to add a flag to the mutation like key_attr (or a better name) to be used to retrieve the object instead of pk.

Do you want to try to open a PR for that? I'll gladly review it and you can also ping me on discord if you need any help while writing it

ldynia commented 10 months ago

Hi @bellini666 I'd love to do PR, but I have no time for it :(. If someone is interested in implementing this, then I drop this answer on stackoverflow.com. It's a good place to pick it up.

thepapermen commented 9 months ago

@bellini666, @ldynia, so just for fun I have made the PR which adds this feature.

ldynia commented 9 months ago

:heart: it! I'll test it once it's merged. But at the moment PR is stopped by this error: https://github.com/strawberry-graphql/strawberry-graphql-django/pull/387

bellini666 commented 9 months ago

@thepapermen just reviewed your PR :)

There are a couple of minor comments there that after fixed should be good to be merged

thepapermen commented 9 months ago

❤️ it! I'll test it once it's merged. But at the moment PR is stopped by this error: #387

@ldynia, now it's merged. :smile:

bellini666 commented 9 months ago

I'll assume this issue has been fixed by https://github.com/strawberry-graphql/strawberry-graphql-django/pull/387 , so I'm closing the issue.

If not, please let me know :)