Skip to content

Question about mutation in the documentation #1066

@laurent-brisbois

Description

@laurent-brisbois

Is your feature request related to a problem? Please describe.
No. It is about a clarification that might be helpful about mutations in the documentation.

Describe the solution you'd like
In the documentation, here, in the QuestionMutation class, there is a question attribute. What does that actually mean ? It says that it defines the response and I don't understand this.

In my code I've been able to do this :

My type :

class UserType(DjangoObjectType):

    class Meta:
        model = User
        fields = (
            'id',
            'username',
            'password',
            'email',
            'first_name',
            'last_name',
            'is_active',
            'group_ids',
        )

    full_name = graphene.String()           # Python property
    full_identification = graphene.String() # Python property

My mutation :

class UpdateUser(graphene.Mutation):
    # --------> I could comment these and no problem. Why ? <--------
    # id = graphene.ID()
    # username = graphene.String()
    # email = graphene.String()
    # first_name = graphene.String()
    # last_name = graphene.String()
    # is_active = graphene.Boolean()

    class Arguments:
        id = graphene.ID()
        username = graphene.String()
        email = graphene.String()
        first_name = graphene.String()
        last_name = graphene.String()
        is_active = graphene.Boolean()

    class Meta:
        output = UserType

    @login_required
    def mutate(self, info, **kwargs):
        user = get_object_or_404(User, id=kwargs['id'])
        for attr, value in kwargs.items():
            setattr(user, attr, value)
        user.save()
        return user
        # I'm not returning explicit UserType, is it a problem ?
        # I actually do it with the Meta class. I guess it is the same for this

and it works whereas I didn't specify anything for the response attributes. And I don't even return the same kind of thing.
Can someone explain if I'm doing it wrong ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions