
from api import db
from uuid import uuid4
from ariadne import MutationType

from api.models import Post
from api.store import queues
mutation = MutationType()

@mutation.field("createPost")
async def create_post_resolver(obj, info, input):
    try:
        post = Post(postId=uuid4(), caption=input["caption"])
        db.session.add(post)
        db.session.commit()
        for queue in queues:
            queue.put(post)  
            
        return{
            "error": None,
            "post": post
        }
    except Exception as e:
        return{
            "error": {"message":str(e), "field": "unknown"},
            "post": None
        }
[(8, 'ariadne.MutationType', 'MutationType', False, 'from ariadne import MutationType\n'), (14, 'api.db.session.add', 'db.session.add', False, 'from api import db\n'), (15, 'api.db.session.commit', 'db.session.commit', False, 'from api import db\n'), (13, 'uuid.uuid4', 'uuid4', False, 'from uuid import uuid4\n')]