-
Notifications
You must be signed in to change notification settings - Fork 767
Allow for custom instantiation of input serializer #228
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
Conversation
docs/rest-framework.rst
Outdated
class MySecondAwesomeMutation(SerializerMutation): | ||
|
||
@classmethod | ||
def instantiate_serializer(cls, instance, args, request, info): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this get_serializer, @syrusakbary what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had a quick look at drf source, it's indeed get_serializer
everywhere. I'll make the change.
Looks good @abdulhaq-e, I've add just a comment :) |
also, can you add a test? :) |
9240fbe
to
b5a32be
Compare
b5a32be
to
bc7d96b
Compare
I added the tests. @patrick91 While writing the tests, I may have discovered a bug; serializers with no fields cannot be defined. If you see the test file and look at
I know it's an edge case but it maybe something to think about. |
@@ -68,3 +69,47 @@ class Meta: | |||
model_input_type = model_input._type.of_type | |||
assert issubclass(model_input_type, InputObjectType) | |||
assert 'cool_name' in model_input_type._meta.fields | |||
|
|||
|
|||
def test_custom_serializer(capfd): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's capfd
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, got it: https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function (TIL) :)
I think you can remove it, since it not used :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@abdulhaq-e well spotted, not sure if serialiser without fields are a thing, do you know any use case for it? |
Their |
bdc7189
to
f93251b
Compare
I appreciate the flexibility this change will provide. It will cover use-cases like #285. It looks like the new test is not passing in the travis build. Please see https://travis-ci.org/graphql-python/graphene-django/jobs/271085453#L709 for details. Also, as to your comments about the edge-case. I think that problem should be resolved in a separate PR. Feel free to file an issue with the use-case or open up another PR for that problem. Thanks for your work! It is very much appreciated. 😄 |
@abdulhaq-e still interested to work on this? |
@firaskafri I have a lot in my hand right now so unfortunately I can't :( |
I'd like to tidy up some of the PRs, so if we still want to work on this let me know or I will close this in 1 week. |
@patrick91