Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement