From 1b2aeb01ceb4924354f61a67fbaf10a9643c9ca3 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 2 Jul 2019 18:23:29 +0200 Subject: [PATCH] Move GraphQL constants into the module --- fbchat/_client.py | 8 +- fbchat/_graphql.py | 277 +++++++++++++++++++++++---------------------- 2 files changed, 143 insertions(+), 142 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index fde5ccc..c0582c6 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -436,7 +436,7 @@ class Client(object): :raises: FBchatException if request failed """ params = {"search": name, "limit": limit} - j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_USER, params=params)) + j = self.graphql_request(GraphQL(query=_graphql.SEARCH_USER, params=params)) return [User._from_graphql(node) for node in j[name]["users"]["nodes"]] @@ -450,7 +450,7 @@ class Client(object): :raises: FBchatException if request failed """ params = {"search": name, "limit": limit} - j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_PAGE, params=params)) + j = self.graphql_request(GraphQL(query=_graphql.SEARCH_PAGE, params=params)) return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]] @@ -465,7 +465,7 @@ class Client(object): :raises: FBchatException if request failed """ params = {"search": name, "limit": limit} - j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_GROUP, params=params)) + j = self.graphql_request(GraphQL(query=_graphql.SEARCH_GROUP, params=params)) return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]] @@ -480,7 +480,7 @@ class Client(object): :raises: FBchatException if request failed """ params = {"search": name, "limit": limit} - j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_THREAD, params=params)) + j = self.graphql_request(GraphQL(query=_graphql.SEARCH_THREAD, params=params)) rtn = [] for node in j[name]["threads"]["nodes"]: diff --git a/fbchat/_graphql.py b/fbchat/_graphql.py index 7506e29..79206f3 100644 --- a/fbchat/_graphql.py +++ b/fbchat/_graphql.py @@ -73,160 +73,161 @@ class GraphQL(object): else: raise FBchatUserError("A query or doc_id must be specified") - FRAGMENT_USER = """ - QueryFragment User: User { - id, - name, - first_name, - last_name, - profile_picture.width().height() { - uri - }, - is_viewer_friend, - url, - gender, - viewer_affinity - } - """ - FRAGMENT_GROUP = """ - QueryFragment Group: MessageThread { - name, - thread_key { - thread_fbid - }, - image { - uri - }, - is_group_thread, - all_participants { - nodes { - messaging_actor { - id - } +FRAGMENT_USER = """ +QueryFragment User: User { + id, + name, + first_name, + last_name, + profile_picture.width().height() { + uri + }, + is_viewer_friend, + url, + gender, + viewer_affinity +} +""" + +FRAGMENT_GROUP = """ +QueryFragment Group: MessageThread { + name, + thread_key { + thread_fbid + }, + image { + uri + }, + is_group_thread, + all_participants { + nodes { + messaging_actor { + id } + } + }, + customization_info { + participant_customizations { + participant_id, + nickname }, - customization_info { - participant_customizations { - participant_id, - nickname + outgoing_bubble_color, + emoji + }, + thread_admins { + id + }, + group_approval_queue { + nodes { + requester { + id + } + } + }, + approval_mode, + joinable_mode { + mode, + link + }, + event_reminders { + nodes { + id, + lightweight_event_creator { + id }, - outgoing_bubble_color, - emoji - }, - thread_admins { - id - }, - group_approval_queue { + time, + location_name, + event_title, + event_reminder_members { + edges { + node { + id + }, + guest_list_state + } + } + } + } +} +""" + +FRAGMENT_PAGE = """ +QueryFragment Page: Page { + id, + name, + profile_picture.width(32).height(32) { + uri + }, + url, + category_type, + city { + name + } +} +""" + +SEARCH_USER = ( + """ +Query SearchUser( = '', = 10) { + entities_named() { + search_results.of_type(user).first() as users { nodes { - requester { - id - } + @User } - }, - approval_mode, - joinable_mode { - mode, - link - }, - event_reminders { + } + } +} +""" + + FRAGMENT_USER +) + +SEARCH_GROUP = ( + """ +Query SearchGroup( = '', = 10, = 32) { + viewer() { + message_threads.with_thread_name().last() as groups { nodes { - id, - lightweight_event_creator { - id - }, - time, - location_name, - event_title, - event_reminder_members { - edges { - node { - id - }, - guest_list_state - } - } + @Group } } } - """ +} +""" + + FRAGMENT_GROUP +) - FRAGMENT_PAGE = """ - QueryFragment Page: Page { - id, - name, - profile_picture.width(32).height(32) { - uri - }, - url, - category_type, - city { - name - } - } +SEARCH_PAGE = ( """ - - SEARCH_USER = ( - """ - Query SearchUser( = '', = 10) { - entities_named() { - search_results.of_type(user).first() as users { - nodes { - @User - } +Query SearchPage( = '', = 10) { + entities_named() { + search_results.of_type(page).first() as pages { + nodes { + @Page } } } - """ - + FRAGMENT_USER - ) +} +""" + + FRAGMENT_PAGE +) - SEARCH_GROUP = ( - """ - Query SearchGroup( = '', = 10, = 32) { - viewer() { - message_threads.with_thread_name().last() as groups { - nodes { - @Group - } +SEARCH_THREAD = ( + """ +Query SearchThread( = '', = 10) { + entities_named() { + search_results.first() as threads { + nodes { + __typename, + @User, + @Group, + @Page } } } - """ - + FRAGMENT_GROUP - ) - - SEARCH_PAGE = ( - """ - Query SearchPage( = '', = 10) { - entities_named() { - search_results.of_type(page).first() as pages { - nodes { - @Page - } - } - } - } - """ - + FRAGMENT_PAGE - ) - - SEARCH_THREAD = ( - """ - Query SearchThread( = '', = 10) { - entities_named() { - search_results.first() as threads { - nodes { - __typename, - @User, - @Group, - @Page - } - } - } - } - """ - + FRAGMENT_USER - + FRAGMENT_GROUP - + FRAGMENT_PAGE - ) +} +""" + + FRAGMENT_USER + + FRAGMENT_GROUP + + FRAGMENT_PAGE +)