Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import graphene
  2.  
  3. from .queries import AuthorType
  4. from ..models import Author
  5.  
  6.  
  7. class AuthorInput(graphene.InputObjectType):
  8. id = graphene.ID()
  9. name = graphene.String()
  10.  
  11.  
  12. class CreateAuthor(graphene.Mutation):
  13. class Arguments:
  14. input = AuthorInput(required=True)
  15.  
  16. author = graphene.Field(AuthorType)
  17.  
  18. @staticmethod
  19. def mutate(root, info, input=None):
  20. author_instance = Author(name=input.name)
  21. author_instance.save()
  22. return CreateAuthor(author=author_instance)
  23.  
  24.  
  25. class Mutation(graphene.ObjectType):
  26. create_author = CreateAuthor.Field()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement