graphene-django-cud icon indicating copy to clipboard operation
graphene-django-cud copied to clipboard

Excluding nested fields in create mutation

Open geekashu opened this issue 3 years ago • 1 comments

Hi,

I want to exclude a few fields on my related OneToOne model. I have the following code for my create mutation. The nested field created and modifed are still available for the creation. Any clues to point me in the right direction is highly appreciated.

class CreateStackMutation(MutationMixin, DjangoCreateMutation):
    """Create dynamic settings"""
    class Meta:
        model = Stack
        exclude_fields = ('modified', 'created', 'email__modified', 'email__created')
        one_to_one_extras = {"email": {"type": "auto"}}

geekashu avatar Jan 23 '22 13:01 geekashu

Hi @geekashu!

You have to exclude inside the extra as such:

class CreateStackMutation(MutationMixin, DjangoCreateMutation):
    """Create dynamic settings"""
    class Meta:
        model = Stack
        exclude_fields = ('modified', 'created',)
        one_to_one_extras = {"email": {"type": "auto", "exclude_fields": ("modified", "created")}}

Please let me know if this works out for you.

tOgg1 avatar Mar 13 '22 13:03 tOgg1