From 4e44e2f39eabc7e1b07d945eb1e53458fec0ac30 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 14 Oct 2023 18:11:17 +0300 Subject: [PATCH] no-datetime-scalar --- CHANGELOG.txt | 1 + inbox.graphql | 4 +--- services/core.py | 12 ++++++++++-- services/schema.py | 10 ++-------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d9c99bb..70f849f 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ - validators added - fixed graphql requests for core api - uses official redis[hiredis] async +- datetime scalar removed [0.2.12] - sigil is back for test diff --git a/inbox.graphql b/inbox.graphql index 6d49ebe..ea6c60e 100644 --- a/inbox.graphql +++ b/inbox.graphql @@ -1,5 +1,3 @@ -scalar DateTime - type _Service { sdl: String } @@ -15,7 +13,7 @@ type ChatMember { slug: String! name: String! userpic: String - lastSeen: DateTime + lastSeen: Int! online: Boolean # invitedAt: DateTime # invitedBy: String # user slug diff --git a/services/core.py b/services/core.py index f81dabc..3138a05 100644 --- a/services/core.py +++ b/services/core.py @@ -1,3 +1,5 @@ +from datetime import datetime + from httpx import AsyncClient from settings import API_BASE @@ -22,8 +24,14 @@ async def get_author(author_id): if response.status_code != 200: return None r = response.json() - author: ChatMember | None = r.get("data", {}).get("getAuthorById") - return author + a = r.get("data", {}).get("getAuthorById") + if a: + last_seen = a.get("lastSeen") + dt = datetime.strptime(last_seen, "%Y-%m-%dT%H:%M:%S.%f") + timestamp = int(dt.timestamp()) + a["lastSeen"] = timestamp + author: ChatMember = a + return author async def get_network(author_id: int, limit: int = 50, offset: int = 0) -> list: diff --git a/services/schema.py b/services/schema.py index 837936f..55f7653 100644 --- a/services/schema.py +++ b/services/schema.py @@ -1,15 +1,9 @@ -from ariadne import ScalarType, QueryType, MutationType +from ariadne import QueryType, MutationType -datetime_scalar = ScalarType("DateTime") query = QueryType() mutation = MutationType() -@datetime_scalar.serializer -def serialize_datetime(value): - return value.isoformat() - - @query.field("_service") def resolve_service(*_): # Load the full SDL from your SDL file @@ -19,4 +13,4 @@ def resolve_service(*_): return {"sdl": full_sdl} -resolvers = [query, mutation, datetime_scalar] +resolvers = [query, mutation]