-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolvers_generic.py
64 lines (47 loc) · 1.94 KB
/
resolvers_generic.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Generic resolvers specific to Cosmos."""
from __future__ import annotations
from datetime import datetime
from typing import Any
from ariadne.types import GraphQLResolveInfo
from pytz import utc
from ..const import COSMOS_FIELD_TS, ENV_COSMOS_PARTITION_KEY
from ..cosmos import cosmos
async def resolve_cosmos_query(
obj: Any, # pylint: disable=unused-argument
info: GraphQLResolveInfo, # pylint: disable=unused-argument
**kwargs: Any,
) -> list[dict[str, Any]]:
"""Resolve the container query."""
return await cosmos.query(**kwargs)
async def resolve_cosmos_mutation(
obj: Any, # pylint: disable=unused-argument
info: GraphQLResolveInfo, # pylint: disable=unused-argument
**kwargs: Any,
) -> list[dict[str, Any]]:
"""Resolve the container query."""
return await cosmos.upsert(**kwargs)
async def resolve_timestamp(
obj: dict[str, Any], info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> Any:
"""Sample resolver that turns the Unix Timestamp into a iso-formatted timestamp."""
return datetime.fromtimestamp(obj[COSMOS_FIELD_TS], tz=utc).isoformat()
async def resolve_partition_key(
obj: dict[str, Any], info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> Any:
"""Sample resolver that returns the value of the partition_key field."""
return obj[cosmos.partition_key_field]
async def resolve_partition_key_field(
obj: dict[str, Any], info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> Any:
"""Sample resolver that returns the value of the partition_key field."""
return ENV_COSMOS_PARTITION_KEY
async def resolve_costs(
obj: Any, info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> int:
"""Resolve the costs field."""
return cosmos.costs
async def resolve_continuation(
obj: Any, info: GraphQLResolveInfo # pylint: disable=unused-argument
) -> int:
"""Resolve the continuation field."""
return cosmos.continuation