def mutate(cls, root, context, **kwargs):
"""
Mutation logic is handled here
"""
# 'before_insert' hooks won't work with db.session.bulk_save_objects
# we need to find a way to get hooks to work with bulk_save_objects @todo
objs = []
for data in kwargs.get('records', []):
c = Contact.get_object_from_graphql_input(data)
db.session.add(c)
objs.append(c)
try:
db.session.commit()
return cls(ok=True, ids=[obj.id for obj in objs])
except Exception as e:
raise GraphQLError(e.args)
评论列表
文章目录