Skip to content

Instantly share code, notes, and snippets.

@Bijitakc
Created July 2, 2022 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bijitakc/8c3cbddca593e997aa3e19571d4ed878 to your computer and use it in GitHub Desktop.
Save Bijitakc/8c3cbddca593e997aa3e19571d4ed878 to your computer and use it in GitHub Desktop.
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