From f6ef50f87860f0dab9648cbb955ba9723599d72f Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 12 Oct 2023 15:15:06 +0300 Subject: [PATCH] core-service-connector-fix --- inbox.graphql | 2 +- resolvers/load.py | 3 ++- services/core.py | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/inbox.graphql b/inbox.graphql index c766eb5..6d49ebe 100644 --- a/inbox.graphql +++ b/inbox.graphql @@ -62,7 +62,7 @@ input MessagesBy { type Query { # inbox - loadChats( limit: Int, offset: Int): ChatResult! # your chats + loadChats(limit: Int, offset: Int): ChatResult! # your chats loadMessagesBy(by: MessagesBy!, limit: Int, offset: Int): ChatResult! loadRecipients(limit: Int, offset: Int): ChatResult! searchRecipients(query: String!, limit: Int, offset: Int): ChatResult! diff --git a/resolvers/load.py b/resolvers/load.py index b4ccb00..944d789 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -51,7 +51,8 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0): members_online = (await redis.execute("SMEMBERS", "authors-online")) or [] chats = [] if len(cids) == 0: - r = await create_chat(None, info, members=[1]) # member with id = 1 is discours + print("[resolvers.load] no chats for user {}, create one with Discours (id=2)") + r = await create_chat(None, info, members=[2]) # member with id = 1 is discours cids.append(r["chat"]["id"]) for cid in cids: c = await redis.execute("GET", f"chats/{cid}") diff --git a/services/core.py b/services/core.py index 32bc187..fddf587 100644 --- a/services/core.py +++ b/services/core.py @@ -9,10 +9,9 @@ headers = {"Content-Type": "application/json"} async def get_author(author_id): gql = { - "query": "query GetAuthor { getAuthor(author_id: %s) { id slug userpic name lastSeen } }" - % author_id, + "query": "query GetAuthor { getAuthor(author_id: Int!) { id slug userpic name lastSeen } }", "operation": "GetAuthor", - "variables": None + "variables": { "author_id" : author_id } } try: async with AsyncClient() as client: @@ -28,10 +27,13 @@ async def get_author(author_id): async def get_network(author_id, limit=50, offset=0) -> list: gql = { - "query": "query LoadAuthors { authorFollowings(author_id: %s, limit: %s, offset: %s) { id slug userpic name } }" - % (author_id, limit, offset), + "query": "query LoadAuthors { authorFollowings(author_id: Int!, limit: Int, offset: Int) { id slug userpic name } }", "operation": "LoadAuthors", - "variables": None + "variables": { + "author_id": author_id, + "limit": limit, + "offset": offset + } } followings = [] @@ -56,10 +58,12 @@ async def get_network(author_id, limit=50, offset=0) -> list: async def get_followers(author_id, amount): gql = { - "query": "query LoadAuthors { authorFollowers(author_id: %s, limit: %s) { id slug userpic name } }" - % (author_id, amount), + "query": "query LoadAuthors { authorFollowers(author_id: Int!, limit: Int) { id slug userpic name } }", "operation": "LoadAuthors", - "variables": None + "variables": { + "author_id": author_id, + "limit": amount + } } followers = [] try: