
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, 11, 8, 25), 'ariadne.MutationType', 'MutationType', ({}, {}), '()', False, 'from ariadne import MutationType\n'), ((14, 8, 14, 28), 'api.db.session.add', 'db.session.add', ({(14, 23, 14, 27): 'post'}, {}), '(post)', False, 'from api import db\n'), ((15, 8, 15, 27), 'api.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from api import db\n'), ((13, 27, 13, 34), 'uuid.uuid4', 'uuid4', ({}, {}), '()', False, 'from uuid import uuid4\n')]