def mutate(root, info, answer_id, reaction_data): errors = {} current_user = get_jwt_identity() user = UserModel.find_by_id(current_user["id"]) if not user: errors["user"] = "******" answer = AnswerModel.find_by_id(answer_id) if not answer: errors["answer"] = "not found" if errors: raise GraphQLError(json.dumps(errors)) reaction = ReactionModel(user=user, **reaction_data) if not answer.reactions: answer.reactions = [reaction] else: old_reaction = list( filter(lambda r: r.user == reaction.user, answer.reactions)) if old_reaction: if old_reaction[0].reaction != reaction.reaction: answer.reactions.remove(old_reaction[0]) answer.reactions.append(reaction) else: answer.reactions.append(reaction) answer.save() return ReactToAnswer(answer=answer, reactions=answer.reactions, ok=True)
def mutate(root, info, answer_id, reply_data): errors = {} current_user = get_jwt_identity() user = UserModel.find_by_id(current_user["id"]) if not user: errors["user"] = "******" answer = AnswerModel.find_by_id(answer_id) if not answer: errors["answer"] = "not found" if errors: raise GraphQLError(json.dumps(errors)) reply = ReplyModel(created_by=user, **reply_data) reply.save() if answer.replies: answer.replies.append(reply) else: answer.replies = [reply] answer.save() return ReplyToAnswer(reply=reply, ok=True)
def resolve_answer(root, info, _id): answer = AnswerModel.find_by_id(_id) return answer