Skip to content

Commit

Permalink
add mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
devjunhong committed Mar 24, 2020
1 parent aebe1a4 commit a5b0796
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions polls/mutations.py
@@ -0,0 +1,26 @@
from django.utils.timezone import now

import graphene

from .models import Question
from .types import QuestionType


class CreateQuestion(graphene.Mutation):
class Arguments:
question_text = graphene.String()

ok = graphene.Boolean()
question = graphene.Field(QuestionType)

def mutate(self, info, question_text):
question = Question(question_text=question_text,
pub_date=now()).save()
ok = True
return CreateQuestion(question=question,
ok=ok)


class MyMutations(graphene.ObjectType):
create_question = CreateQuestion.Field()

3 changes: 2 additions & 1 deletion polls/schema.py
Expand Up @@ -5,6 +5,7 @@
from .types import QuestionType
from .types import ChoiceType
from .types import CustomType
from .mutations import MyMutations


class Query(graphene.ObjectType):
Expand Down Expand Up @@ -35,4 +36,4 @@ def resolve_custom_question(self, info, **kwargs):
return None


schema = graphene.Schema(query=Query)
schema = graphene.Schema(query=Query, mutation=MyMutations)

0 comments on commit a5b0796

Please sign in to comment.