From 956dc3915ca2d61fe62d4a6fed74fa8f9545c756 Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Sat, 11 Jun 2022 17:35:10 +0300 Subject: [PATCH] add userChats query --- inbox_resolvers/inbox.py | 13 +++++++++++++ inbox_schema.graphql | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/inbox_resolvers/inbox.py b/inbox_resolvers/inbox.py index f545a6b6..9a55ec94 100644 --- a/inbox_resolvers/inbox.py +++ b/inbox_resolvers/inbox.py @@ -102,6 +102,19 @@ async def load_messages(chatId, size, page): messages = [json.loads(msg) for msg in messages] return messages +@query.field("userChats") +@login_required +async def user_chats(_, info): + user = info.context["request"].user + + chats = await redis.execute("GET", f"chats_by_user/{user.slug}") + if not chats: + chats = list() + else: + chats = list(json.loads(chats)) + + return {"chats" : chats} + @query.field("enterChat") @login_required async def enter_chat(_, info, chatId, size): diff --git a/inbox_schema.graphql b/inbox_schema.graphql index e3ea4c6a..6f2544f3 100644 --- a/inbox_schema.graphql +++ b/inbox_schema.graphql @@ -34,6 +34,11 @@ type EnterChatResult { error: String } +type UserChatsResult { + error: String + chats: [String] +} + ################################### Mutation type Mutation { @@ -49,7 +54,7 @@ type Mutation { ################################### Query type Query { - # messages + userChats: UserChatsResult! enterChat(chatId: String!, size: Int = 50): EnterChatResult! getMessages(chatId: String!, size: Int!, page: Int!): [Message]! }