question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about mutation in the documentation

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
zbyte64commented, Nov 27, 2020

If you do not define an output type then you must define the return fields on your mutation itself. The example documentation does not define output but opts to return an instance of itself instead. Returning the user model instance works for you because it duck types to UserType.

From the code docs:

output (graphene.ObjectType): Or ``Output`` inner class with attributes on Mutation class.
            Or attributes from Mutation class. Fields which can be returned from this mutation
            field.
0reactions
laurent-brisboiscommented, Jan 26, 2021

I see. Thanks for your advices !

Read more comments on GitHub >

github_iconTop Results From Across the Web

835 questions with answers in MUTATION | Science topic
1- Can i calculate probable no of mutation in each branch? · 2- Is there any tools available for that? · 3-I also...
Read more >
Question about graphene-django mutation documentation
In the documentation, here, in the QuestionMutation class, there is a question attribute. What does that actually mean ?
Read more >
Genetic Mutation | Learn Science at Scitable - Nature
The answer to this question is closely linked to the molecular details of how both DNA and the entire genome are organized. The...
Read more >
Standard Mutation Nomenclature in Molecular Diagnostics
Standard mutation nomenclature based on coding DNA reference sequences and protein-level amino acid sequences requires prefixes “c.” and “p.,” respectively, as ...
Read more >
DNA and Mutations - Understanding Evolution
by the Understanding Evolution team A mutation is a change in DNA, the hereditary material of life ... In this article, we will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found