Skip to content

Commit 2c925b6

Browse files
committed
Split long query strings
1 parent a98b2bc commit 2c925b6

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

src/handlers/leetcode/api/question.rs

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,34 @@ impl LeetCode<Authorized> {
77
let url = "https://leetcode.com/graphql";
88
let client = &self.client;
99
let query = GraphqlRequest {
10-
query: "\n query questionOfToday {\n activeDailyCodingChallengeQuestion {\n date\n userStatus\n link\n question {\n acRate\n difficulty\n freqBar\n frontendQuestionId: questionFrontendId\n isFavor\n paidOnly: isPaidOnly\n status\n title\n titleSlug\n hasVideoSolution\n hasSolution\n topicTags {\n name\n id\n slug\n }\n }\n }\n}\n ".to_string(),
10+
query: r#"
11+
query questionOfToday {
12+
activeDailyCodingChallengeQuestion {
13+
date
14+
userStatus
15+
link
16+
question {
17+
acRate
18+
difficulty
19+
freqBar
20+
frontendQuestionId: questionFrontendId
21+
isFavor
22+
paidOnly: isPaidOnly
23+
status
24+
title
25+
titleSlug
26+
hasVideoSolution
27+
hasSolution
28+
topicTags {
29+
name
30+
id
31+
slug
32+
}
33+
}
34+
}
35+
}
36+
"#
37+
.to_string(),
1138
variables: "{}".to_string(),
1239
};
1340

@@ -52,8 +79,17 @@ impl LeetCode<Authorized> {
5279
let client = &self.client;
5380
let url = "https://leetcode.com/graphql";
5481
let query = GraphqlRequest {
55-
query: "query questionContent($titleSlug: String!) { question(titleSlug: $titleSlug) { content mysqlSchemas }}".to_string(),
56-
variables: serde_json::to_string(&Variables { titleSlug: title_slug.to_string() }).unwrap(),
82+
query: r#"
83+
query questionContent($titleSlug: String!) {
84+
question(titleSlug: $titleSlug) {
85+
content mysqlSchemas
86+
}
87+
}
88+
"#
89+
.to_string(),
90+
variables: serde_json::to_string(&Variables {
91+
titleSlug: title_slug.to_string(),
92+
})?,
5793
};
5894

5995
let data = client.post(url).json(&query).send()?;
@@ -67,7 +103,21 @@ impl LeetCode<Authorized> {
67103
data: QuestionWrapper,
68104
}
69105

70-
let query = "\n query questionEditorData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n codeSnippets {\n lang\n langSlug\n code\n }\n envInfo\n enableRunCode\n }\n}\n ";
106+
let query = r#"
107+
query questionEditorData($titleSlug: String!) {
108+
question(titleSlug: $titleSlug) {
109+
questionId
110+
questionFrontendId
111+
codeSnippets {
112+
lang
113+
langSlug
114+
code
115+
}
116+
envInfo
117+
enableRunCode
118+
}
119+
}
120+
"#;
71121
let varibales = serde_json::to_string(&Variables {
72122
titleSlug: title_slug.to_string(),
73123
})?;
@@ -139,8 +189,25 @@ impl LeetCode<Authorized> {
139189
let url = "https://leetcode.com/graphql";
140190

141191
let query = GraphqlRequest {
142-
query: "\n query consolePanelConfig($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n questionTitle\n enableDebugger\n enableRunCode\n enableSubmit\n enableTestMode\n exampleTestcaseList\n metaData\n }\n}\n".to_string(),
143-
variables: serde_json::to_string(&Variables { titleSlug: title_slug.to_string() }).unwrap(),
192+
query: r#"
193+
query consolePanelConfig($titleSlug: String!) {
194+
question(titleSlug: $titleSlug) {
195+
questionId
196+
questionFrontendId
197+
questionTitle
198+
enableDebugger
199+
enableRunCode
200+
enableSubmit
201+
enableTestMode
202+
exampleTestcaseList
203+
metaData
204+
}
205+
}
206+
"#
207+
.to_string(),
208+
variables: serde_json::to_string(&Variables {
209+
titleSlug: title_slug.to_string(),
210+
})?,
144211
};
145212
let data = client
146213
.post(url)

src/handlers/leetcode/api/submit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ impl LeetCode<Authorized> {
3434
question_id,
3535
typed_code,
3636
};
37-
let data = client.post(&url).json(&submission).send()?.json::<SubmissionID>().wrap_err("Failed to fetch submission id from LeetCode, Check your submissions manually on leetcode")?;
37+
let data = client.post(&url).json(&submission).send()?.json::<SubmissionID>().wrap_err(
38+
"Failed to fetch submission id from LeetCode, Check your submissions manually on leetcode"
39+
)?;
3840

3941
println!("Evaluating solution...");
4042
let submission_id = data.submission_id;

0 commit comments

Comments
 (0)