-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolvers_specific.py
More file actions
29 lines (21 loc) · 827 Bytes
/
Copy pathresolvers_specific.py
File metadata and controls
29 lines (21 loc) · 827 Bytes
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
"""All the resolvers for the queries and mutations."""
from __future__ import annotations
import logging
from datetime import datetime
from typing import Any
from ariadne.types import GraphQLResolveInfo
from pytz import timezone, utc
from ..const import COSMOS_FIELD_TS
_LOGGER = logging.getLogger(__name__)
LOCAL_TZ = timezone("Europe/Amsterdam")
async def resolve_timestamp_timezone(
obj: dict[str, Any], info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> Any:
"""Sample resolver that turns the Unix Timestamp into a iso-formatted timestamp with the timezone defined above.
Meant as a drop-in replacement for the built-in `resolve_timestamp` resolver.
"""
return (
datetime.fromtimestamp(obj[COSMOS_FIELD_TS], tz=utc)
.astimezone(LOCAL_TZ)
.isoformat()
)