graphene-django-cud icon indicating copy to clipboard operation
graphene-django-cud copied to clipboard

Some proposals for improvement

Open zaunerp opened this issue 8 months ago • 1 comments

Hello,

first of all the graphene-django-cud is a wonderfull tool and simplifys a lot of things, but I found some issues for some cases.

One rather minor things that I spotted was, if I add foreign_key_extras they are always required. In my used case I have foreinkeys that are optional, but if I put them in optional fields they don't get ignored and I get an error message that one of my fields don't have items. Makes sense because it's expecting the foreignkey to be in the query. You can workaround this by just adding an empty dict with the foreign key.

Next Point is, Foreingkeys that get objects not ids but are get_or_create objects. E.g. Numberplates of cars. I have some plates pre saved, but I cannot save all numberplates that are out there and I have some number plates presaved that I use for driveaways. So if someone adds a car, with the number plate i have already saved use this one, if the number plate not in the database make a new one and use it.

My suggestion to solve a problem like this, would be that if you add foreign_key_extras with the type e.g. CreateNumberPlateInput the hooks (before_mutate, before_save, after_mutate) in the class CreateNumberPlateMutation still gets called even if it's only in a foreign_key_extras of another class. Also enable the possiblity to overwrite the whole mutate function that is called from the CreateMutation class.

I think this would lift this tool to a new level of utilization. E.g my case with get_or_create can be covered because I can add a before_save method and overwrite the object if the object exists.

best regards,

Patrick

zaunerp avatar Nov 01 '23 11:11 zaunerp