Skip to content

Instantly share code, notes, and snippets.

@nidhinp
Created September 5, 2019 07:35
Show Gist options
  • Save nidhinp/90ec3db8bffe68d855883bea229b6549 to your computer and use it in GitHub Desktop.
Save nidhinp/90ec3db8bffe68d855883bea229b6549 to your computer and use it in GitHub Desktop.
import graphene
from .queries import AuthorType
from ..models import Author
class AuthorInput(graphene.InputObjectType):
id = graphene.ID()
name = graphene.String()
class CreateAuthor(graphene.Mutation):
class Arguments:
input = AuthorInput(required=True)
author = graphene.Field(AuthorType)
@staticmethod
def mutate(root, info, input=None):
author_instance = Author(name=input.name)
author_instance.save()
return CreateAuthor(author=author_instance)
class Mutation(graphene.ObjectType):
create_author = CreateAuthor.Field()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment