Created
July 2, 2022 18:42
-
-
Save Bijitakc/8c3cbddca593e997aa3e19571d4ed878 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import graphene | |
from graphene_file_upload.scalars import Upload | |
from .models import Post | |
from .types import PostType | |
class CreatePostMutation(graphene.Mutation): | |
post = graphene.Field(PostType) | |
class Arguments: | |
title = graphene.String(required=True) | |
photo = Upload(required=True) | |
caption = graphene.String(required=True) | |
@classmethod | |
def mutate(cls, root, info, title, photo, caption): | |
post_ins = Post.objects.create(title=title, photo=photo, caption=caption) | |
return CreatePostMutation(post=post_ins) | |
class Mutation(graphene.ObjectType): | |
create_post = CreatePostMutation.Field() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment