-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.py
33 lines (29 loc) · 813 Bytes
/
queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from ariadne import convert_kwargs_to_snake_case
from .models import Todo
def resolve_todos(obj, info):
try:
todos = [todo.to_dict() for todo in Todo.query.all()]
payload = {
'success': True,
'todos': todos
}
except Exception as error:
payload = {
'success': False,
'errors': [str(error)]
}
return payload
@convert_kwargs_to_snake_case
def resolve_todo(obj, info, todo_id):
try:
todo = Todo.query.get(todo_id)
payload = {
"success": True,
"todo": todo.to_dict()
}
except AttributeError: # todo not found
payload = {
"success": False,
"errors": [f"Todo item matching id {todo_id} not found"]
}
return payload