Move GraphQL constants into the module

This commit is contained in:
Mads Marquart
2019-07-02 18:23:29 +02:00
parent cab8abd1a0
commit 1b2aeb01ce
2 changed files with 143 additions and 142 deletions

View File

@@ -436,7 +436,7 @@ class Client(object):
:raises: FBchatException if request failed :raises: FBchatException if request failed
""" """
params = {"search": name, "limit": limit} 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"]] return [User._from_graphql(node) for node in j[name]["users"]["nodes"]]
@@ -450,7 +450,7 @@ class Client(object):
:raises: FBchatException if request failed :raises: FBchatException if request failed
""" """
params = {"search": name, "limit": limit} 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"]] return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]]
@@ -465,7 +465,7 @@ class Client(object):
:raises: FBchatException if request failed :raises: FBchatException if request failed
""" """
params = {"search": name, "limit": limit} 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"]] return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]]
@@ -480,7 +480,7 @@ class Client(object):
:raises: FBchatException if request failed :raises: FBchatException if request failed
""" """
params = {"search": name, "limit": limit} 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 = [] rtn = []
for node in j[name]["threads"]["nodes"]: for node in j[name]["threads"]["nodes"]:

View File

@@ -73,160 +73,161 @@ class GraphQL(object):
else: else:
raise FBchatUserError("A query or doc_id must be specified") raise FBchatUserError("A query or doc_id must be specified")
FRAGMENT_USER = """
QueryFragment User: User {
id,
name,
first_name,
last_name,
profile_picture.width(<pic_size>).height(<pic_size>) {
uri
},
is_viewer_friend,
url,
gender,
viewer_affinity
}
"""
FRAGMENT_GROUP = """ FRAGMENT_USER = """
QueryFragment Group: MessageThread { QueryFragment User: User {
name, id,
thread_key { name,
thread_fbid first_name,
}, last_name,
image { profile_picture.width(<pic_size>).height(<pic_size>) {
uri uri
}, },
is_group_thread, is_viewer_friend,
all_participants { url,
nodes { gender,
messaging_actor { viewer_affinity
id }
} """
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 { outgoing_bubble_color,
participant_customizations { emoji
participant_id, },
nickname 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, time,
emoji location_name,
}, event_title,
thread_admins { event_reminder_members {
id edges {
}, node {
group_approval_queue { 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(<search> = '', <limit> = 10) {
entities_named(<search>) {
search_results.of_type(user).first(<limit>) as users {
nodes { nodes {
requester { @User
id
}
} }
}, }
approval_mode, }
joinable_mode { }
mode, """
link + FRAGMENT_USER
}, )
event_reminders {
SEARCH_GROUP = (
"""
Query SearchGroup(<search> = '', <limit> = 10, <pic_size> = 32) {
viewer() {
message_threads.with_thread_name(<search>).last(<limit>) as groups {
nodes { nodes {
id, @Group
lightweight_event_creator {
id
},
time,
location_name,
event_title,
event_reminder_members {
edges {
node {
id
},
guest_list_state
}
}
} }
} }
} }
""" }
"""
+ FRAGMENT_GROUP
)
FRAGMENT_PAGE = """ SEARCH_PAGE = (
QueryFragment Page: Page {
id,
name,
profile_picture.width(32).height(32) {
uri
},
url,
category_type,
city {
name
}
}
""" """
Query SearchPage(<search> = '', <limit> = 10) {
SEARCH_USER = ( entities_named(<search>) {
""" search_results.of_type(page).first(<limit>) as pages {
Query SearchUser(<search> = '', <limit> = 10) { nodes {
entities_named(<search>) { @Page
search_results.of_type(user).first(<limit>) as users {
nodes {
@User
}
} }
} }
} }
""" }
+ FRAGMENT_USER """
) + FRAGMENT_PAGE
)
SEARCH_GROUP = ( SEARCH_THREAD = (
""" """
Query SearchGroup(<search> = '', <limit> = 10, <pic_size> = 32) { Query SearchThread(<search> = '', <limit> = 10) {
viewer() { entities_named(<search>) {
message_threads.with_thread_name(<search>).last(<limit>) as groups { search_results.first(<limit>) as threads {
nodes { nodes {
@Group __typename,
} @User,
@Group,
@Page
} }
} }
} }
""" }
+ FRAGMENT_GROUP """
) + FRAGMENT_USER
+ FRAGMENT_GROUP
SEARCH_PAGE = ( + FRAGMENT_PAGE
""" )
Query SearchPage(<search> = '', <limit> = 10) {
entities_named(<search>) {
search_results.of_type(page).first(<limit>) as pages {
nodes {
@Page
}
}
}
}
"""
+ FRAGMENT_PAGE
)
SEARCH_THREAD = (
"""
Query SearchThread(<search> = '', <limit> = 10) {
entities_named(<search>) {
search_results.first(<limit>) as threads {
nodes {
__typename,
@User,
@Group,
@Page
}
}
}
}
"""
+ FRAGMENT_USER
+ FRAGMENT_GROUP
+ FRAGMENT_PAGE
)