Skip to content

DRF Serializer update #326

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

Merged
merged 1 commit into from
Mar 30, 2018
Merged

DRF Serializer update #326

merged 1 commit into from
Mar 30, 2018

Conversation

pizzapanther
Copy link
Contributor

@pizzapanther pizzapanther commented Nov 15, 2017

Currently you can't use serializers for updates only add operations unless you customize mutate_and_get_payload. This PR adds functionality to support most updates without any customization needed by the user. I also added support for Partial updates.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.001%) to 93.141% when pulling f489c97 on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

1 similar comment
@coveralls
Copy link

coveralls commented Nov 15, 2017

Coverage Status

Coverage decreased (-0.001%) to 93.141% when pulling f489c97 on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 15, 2017

Coverage Status

Coverage decreased (-0.001%) to 93.141% when pulling 693ee6e on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 15, 2017

Coverage Status

Coverage decreased (-0.001%) to 93.141% when pulling a099ecb on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 15, 2017

Coverage Status

Coverage increased (+0.2%) to 93.34% when pulling 0773c8b on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 15, 2017

Coverage Status

Coverage increased (+0.2%) to 93.34% when pulling e2ac311 on pizzapanther:drf-serializer-update into 5661db8 on graphql-python:master.

@urbandove
Copy link
Contributor

Looks great!

I see you decided to go with making the add/update decision based on if there was some sort of id specified. Much more django like. ;)

I'm wondering about raising the 404 on update if the instance isn't found - is GraphQL meant to be raising HTTP status codes? From graphql-python/graphene#142 it seems not.
Wondering if there is any consensus in the GraphQL community on how such issues are meant to be dealt with.

@pizzapanther
Copy link
Contributor Author

I decided to go with the add/update and leave it up to user if they want to split out. The other way, the implementation would be very much the same but with more enforcement. So I went the flexible route.

As for the 404, that is something I am wishing for :-)

Graphene eats a lot of errors and returns 200 codes. I see the reasoning for not with the link you posted but I still think that's probably bad behavior to continue executing after a failure. I'll update if needed but one can always dream.

Copy link
Contributor

@spockNinja spockNinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few discussion points.

Also, see #228 where the idea of generalizing out to the get_serializer level is proposed. I think get_serializer_kwargs would cover the context case it is after, but I see value in both levels of abstraction.

@@ -67,9 +90,35 @@ def __init_subclass_with_meta__(cls, serializer_class=None,
)
super(SerializerMutation, cls).__init_subclass_with_meta__(_meta=_meta, input_fields=input_fields, **options)

@classmethod
def resolve_serializer_inputs(cls, root, info, **input):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of get_serializer_kwargs for this method? "resolve" and "inputs" both have special meanings in the graphene world.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍

return {
'instance': instance,
'data': input,
'partial': cls._meta.partial
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance and data definitely make sense here, as those are very dynamic and dependent on the query.

However, I think kwargs like partial (many, context, etc.) should use a different mechanism instead of living on SerializerMutationOptions. If we go with renaming this get_serializer_kwargs, those would be easy enough to add with a call to super on an overridden version.

There is also the compromise of adding a serializer_kwargs option to the SerializerMutationOptions that would be combined with this dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I wasn't too happy with partial there

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage increased (+0.4%) to 93.508% when pulling 5b78517 on pizzapanther:drf-serializer-update into c63dbea on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling 415d7d7 on pizzapanther:drf-serializer-update into c63dbea on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling eaa045e on pizzapanther:drf-serializer-update into c63dbea on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling caebbf0 on pizzapanther:drf-serializer-update into c63dbea on graphql-python:master.

@pizzapanther
Copy link
Contributor Author

@spockNinja updated with feedback, also changed the operations to 'create', 'update' instead of 'add', 'update' so it mirrors DRF serializer language.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 92.729% when pulling 54183bc on pizzapanther:drf-serializer-update into 24706f5 on graphql-python:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 92.729% when pulling 54183bc on pizzapanther:drf-serializer-update into 24706f5 on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 92.729% when pulling 54183bc on pizzapanther:drf-serializer-update into 24706f5 on graphql-python:master.

@coveralls
Copy link

coveralls commented Dec 9, 2017

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling fc0db26 on pizzapanther:drf-serializer-update into 24706f5 on graphql-python:master.

@spockNinja
Copy link
Contributor

It looks like the build is breaking due to an issue with py.test. I'll put in a separate PR to get that fixed up, and rebuild this one once it's merged.

@urbandove urbandove mentioned this pull request Jan 14, 2018
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling 17c75b4 on pizzapanther:drf-serializer-update into b54e02c on graphql-python:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling 17c75b4 on pizzapanther:drf-serializer-update into b54e02c on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling 17c75b4 on pizzapanther:drf-serializer-update into b54e02c on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.327% when pulling 17c75b4 on pizzapanther:drf-serializer-update into b54e02c on graphql-python:master.

@coveralls
Copy link

coveralls commented Jan 15, 2018

Coverage Status

Coverage increased (+0.2%) to 94.361% when pulling 91a99ee on pizzapanther:drf-serializer-update into c585982 on graphql-python:master.

@pizzapanther
Copy link
Contributor Author

@colanconnon added your lines but getting a weird test failure. I'll see if i can debug, it seems unrelated

@patrick91
Copy link
Member

@pizzapanther if you rebase from master the CI check will pass :)

@pizzapanther
Copy link
Contributor Author

@patrick91 rebased

@syrusakbary
Copy link
Member

@patrick91 @spockNinja is this PR ready to be merged?

@syrusakbary
Copy link
Member

I re-reviewed and everything looks perfect. Sorry for taking so long to merge.

@syrusakbary syrusakbary merged commit a480a39 into graphql-python:master Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants