-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deleting items by id #50
Comments
I built something like this internally, but never really built up the test coverage, etc. to make me comfortable with adding it to this package. Here's the resolver that can be subclassed:
Here's an example of it in use:
There's still some boring repetitive code, but it's a smidge less and much more favorable to quick copypasta. |
@maxmorlocke I have not written test for mine either. I think this is useful to but it is easy to do the delete mutation and queries. When you get to the update and create it gets kind of difficult especially if you have nested foreign keys and trying to process them in bulk. |
We did create and update pretty well while also handling nesting. This required a pretty customized set of helpers to our DRF serializer though, as it doesn't handle child objects very well (e.g. If I have a child object and a child serializer, I want parent.validate to call child.validate and produce the 'correct' error messages). That being said, bulk updates and creates would definitely be a pain point. |
I find this to be a good way of setting up a delete by id:
For the function just replace the model
Document
with whatever model. The results are the same for any model where a string is returned of the items you deleted and the errors. Is there a way some way to write the code so we can just plug in the django models to a function / class in this setup so less code is written? (I am not good at meta programming but find myself repeating this pattern)The text was updated successfully, but these errors were encountered: