getGraphQLPayloadDiscussionList function
Implementation
String getGraphQLPayloadDiscussionList({
required List<String> categories,
required List<String> tags,
String? orderBy = 'hot',
String? searchQuery,
required int offset,
}) {
final categoryListString = categories.joinCsv();
final tagListString = tags.joinCsv();
if (orderBy != null) {
if (searchQuery != null) {
orderBy = 'most_relevant';
} else {
orderBy = 'hot';
}
}
return r'''{
"operationName": "categoryTopicList",
"variables": {
"orderBy": "#orderBy",
"query": "#searchQuery",
"skip": #offset,
"first": 15,
"tags": #tagListString,
"categories": #categoryListString
},
"query": "query categoryTopicList($categories: [String!]!, $first: Int!, $orderBy: TopicSortingOption, $skip: Int, $query: String, $tags: [String!]) {\n categoryTopicList(categories: $categories, orderBy: $orderBy, skip: $skip, query: $query, first: $first, tags: $tags) {\n ...TopicsList\n __typename\n }\n}\n\nfragment TopicsList on TopicConnection {\n totalNum\n edges {\n node {\n id\n title\n commentCount\n viewCount\n pinned\n tags {\n name\n slug\n __typename\n }\n post {\n id\n voteCount\n creationDate\n isHidden\n author {\n username\n isActive\n nameColor\n activeBadge {\n displayName\n icon\n __typename\n }\n profile {\n userAvatar\n __typename\n }\n __typename\n }\n status\n coinRewards {\n ...CoinReward\n __typename\n }\n __typename\n }\n lastComment {\n id\n post {\n id\n author {\n isActive\n username\n __typename\n }\n peek\n creationDate\n __typename\n }\n __typename\n }\n __typename\n }\n cursor\n __typename\n }\n __typename\n}\n\nfragment CoinReward on ScoreNode {\n id\n score\n description\n date\n __typename\n}\n"
}'''
.replaceAll('#orderBy', orderBy ?? 'hot')
.replaceAll('#query', searchQuery ?? '')
.replaceAll('#offset', offset.toString())
.replaceAll('#tagListString', tagListString)
.replaceAll('#categoryListString', categoryListString);
}