GraphQL (Graphene) Mutations - Verständnisfrage

Django, Flask, Bottle, WSGI, CGI…
Antworten
naheliegend
User
Beiträge: 439
Registriert: Mittwoch 8. August 2018, 16:42

Hi,

der Beispielcode auf in den docs zu graphene-django:

Code: Alles auswählen

import graphene

from graphene_django import DjangoObjectType

from .models import Question


class QuestionType(DjangoObjectType):
    class Meta:
        model = Question


class QuestionMutation(graphene.Mutation):
    class Arguments:
        # The input arguments for this mutation
        text = graphene.String(required=True)
        id = graphene.ID()

    # The class attributes define the response of the mutation
    question = graphene.Field(QuestionType)

    @classmethod
    def mutate(cls, root, info, text, id):
        question = Question.objects.get(pk=id)
        question.text = text
        question.save()
        # Notice we return an instance of this mutation
        return QuestionMutation(question=question)


class Mutation(graphene.ObjectType):
    update_question = QuestionMutation.Field()

Was macht hier diese Zeile?

Code: Alles auswählen

    # The class attributes define the response of the mutation
    question = graphene.Field(QuestionType)
Das verstehe ich nicht so genau.
__backjack__: "Jemand der VB oder PHP kann, der also was Programmieren angeht irgendwo im negativen Bereich liegt (...)"
Benutzeravatar
sparrow
User
Beiträge: 4164
Registriert: Freitag 17. April 2009, 10:28

Das steht ja eigentlich schon im Kommetar: Es wird ein Klassenattribut definiert.
Wenn du wissen willst, wofür das benötigt wird, solltest du einen Blick in die Klasse werfen, von der QuestionMutation erbt.
Antworten