PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.
https://django-graphql-auth.readthedocs.io/en/latest/
MIT License
329 stars 106 forks source link

Nested Form field? #142

Closed saileshkush95 closed 2 years ago

saileshkush95 commented 2 years ago

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

Thank you for this amazing package, I'm following same apprach to perform other crud operatations. and It is working fine. But I've one questions, how can i implement nested field muation and also how can i upload images. I mean simple model form works or not?

for example, I've moodel called Media, and Here is mutations for model.


class CreateMedia(
    RelayMutationMixin,
    DynamicInputMixin,
    Output,
    graphene.ClientIDMutation):
    form = MediaForm
    _inputs = list(form.Meta.fields)
    media = graphene.Field(MediaNode)

    @classmethod
    @login_required
    def resolve_mutation(cls, root, info, **kwargs):
        f = cls.form(kwargs)
        if f.is_valid():
            try:
                media = f.save()
                return cls(success=True, media=media)
            except Exception as e:
                return cls(success=False, errors="Some things went wrongs")
        else:
            return cls(success=False, errors=f.errors.get_json_data())

and here is model

class MediaForm(forms.ModelForm):
    class Meta:
        model = Media
        fields = ("media", "content_type", "object_id")

But it is not working