Skip to content
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

[WIP] Improve form and serializer mutations #546

Closed
wants to merge 8 commits into from

Conversation

patrick91
Copy link
Member

@patrick91 patrick91 commented Oct 28, 2018

This PR improves both FormMutation and SerializerMutation to add support for better error types and wrapping the return type for the SerializerMutation.

I've also removed the ModelFormMutation since I think it is easier to use one class, and I'm not sure why it was possible to customize the model class there too.

TODO:

  • Use registry for return fields
  • Add support for return field to SerializerMutation
  • Add support for adding more inputs or overriding them
  • Add support for adding additional arguments
  • Non opinionated errors[1]
  • Update doc
  • Allow to create Form Mutation for models that don't have graphql types
  • more stuff (potentially)

Feel free to add comments and notes even if this is still a WIP.

[1] My idea is to add support for customizable errors via a setting property

NOTE: this is going to have some breaking changes (errors and return types have changed)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 94.849% when pulling fd516a3 on feature/improved-mutations into f76f38e on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 94.849% when pulling fd516a3 on feature/improved-mutations into f76f38e on master.

@coveralls
Copy link

coveralls commented Oct 28, 2018

Coverage Status

Coverage increased (+0.3%) to 94.686% when pulling 675a989 on feature/improved-mutations into ea2cd98 on master.

@firaskafri
Copy link
Collaborator

@patrick91 any plans to update this pull request?

@patrick91
Copy link
Member Author

@firaskafri I'd love to, but I don't have much time right now, I might try to work on it during DjangoCon Europe sprints :)

@firaskafri
Copy link
Collaborator

@CharlesBradshaw can you update @patrick91 todo list?

@zbyte64 zbyte64 closed this Mar 28, 2019
@zbyte64 zbyte64 force-pushed the feature/improved-mutations branch from 66c3875 to ea2cd98 Compare March 28, 2019 16:36
@zbyte64 zbyte64 reopened this Mar 28, 2019
@zbyte64 zbyte64 force-pushed the feature/improved-mutations branch from 0e6fa16 to fd516a3 Compare March 28, 2019 17:00
@zbyte64
Copy link
Collaborator

zbyte64 commented May 29, 2019

My current attempt at supporting Global IDs as part of form mutation lookup does a hard type check:

@classmethod
    def get_form_kwargs(cls, root, info, **input):
        kwargs = {"data": input}

        pk = input.pop("id", None)
        if pk:
            pk_type = cls.Input._meta.fields['id'].type
            if isinstance(pk, str) and pk_type == ID:
                _, pk = from_global_id(pk)
            instance = cls._meta.model._default_manager.get(pk=pk)
            kwargs["instance"] = instance

        return kwargs

For an InputField I could not find a duck typed method that would parse global IDs. Alternatively we could try using the form field to parse the supplied value, I think that will be my next attempt. Edit: that won't work either...

@zbyte64
Copy link
Collaborator

zbyte64 commented May 29, 2019

I think adding a "resolve_instance" class method to BaseDjangoFormMutation might be a good idea. Users may have their own custom lookup logic, ie UUID, and that would make it easier for them.

@stale
Copy link

stale bot commented Jul 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 28, 2019
@stale stale bot closed this Aug 4, 2019
@firaskafri firaskafri deleted the feature/improved-mutations branch September 23, 2022 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants