Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d0a5e68

Browse files
Clean: Move queries to new file
1 parent 6d84d4f commit d0a5e68

File tree

2 files changed

+150
-77
lines changed

2 files changed

+150
-77
lines changed

‎index.js‎

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,23 @@
11
import axios from "axios";
22
import config from "./config/config";
3+
import queries from "./queries/queries";
34

4-
const body2 = `{"operationName":"getContestRankingData","variables":{"username":"aditi"},"query":"query getContestRankingData($username: String!) {\
5-
userContestRanking(username: aditi) {\
6-
attendedContestsCount\
7-
rating\
8-
globalRanking\
9-
}\
10-
}\
11-
"}`;
12-
const test = () => {
13-
fetch(url, {
14-
method: "POST",
15-
headers: {
16-
accept: "*/*",
17-
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8,hi;q=0.7,ru;q=0.6",
18-
"cache-control": "no-cache",
19-
"content-type": "application/json",
20-
pragma: "no-cache",
21-
"sec-ch-ua-mobile": "?0",
22-
"sec-ch-ua":
23-
'" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
24-
"sec-fetch-dest": "empty",
25-
"sec-fetch-mode": "cors",
26-
"sec-fetch-site": "same-origin",
27-
"sec-gpc": "1",
28-
},
29-
referrerPolicy: "strict-origin-when-cross-origin",
30-
mode: "cors",
31-
body: body2,
32-
})
33-
.then((res) => res.json())
34-
.then((data) => {
35-
console.table(data);
36-
});
37-
};
38-
39-
// Just some constants
40-
const LEETCODE_API_ENDPOINT = "https://leetcode.com/graphql";
41-
const DAILY_CODING_CHALLENGE_QUERY = `query questionOfToday {
42-
activeDailyCodingChallengeQuestion {
43-
date
44-
userStatus
45-
link
46-
question {
47-
acRate
48-
difficulty
49-
freqBar
50-
frontendQuestionId: questionFrontendId
51-
isFavor
52-
paidOnly: isPaidOnly
53-
status
54-
title
55-
titleSlug
56-
hasVideoSolution
57-
hasSolution
58-
topicTags {
59-
name
60-
id
61-
slug
62-
}
63-
}
64-
}
65-
}`;
665

676
const testPostReq = async () => {
68-
const globalQuery = {
69-
operationName: "questionData",
70-
variables: { titleSlug: "path-sum" },
71-
query: "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n categoryTitle\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n challengeQuestion {\n id\n date\n incompleteChallengeCount\n streakCount\n type\n __typename\n }\n __typename\n }\n}\n",
72-
};
73-
const dailyChallengeQuery = {
74-
operationName: "questionOfToday",
75-
query: "query questionOfToday{\n\tactiveDailyCodingChallengeQuestion {\n\t\tdate\n\t\tuserStatus\n\t\tlink\n\t\tquestion {\n\t\t\tacRate\n\t\t\tdifficulty\n\t\t\tfreqBar\n\t\t\tfrontendQuestionId: questionFrontendId\n\t\t\tisFavor\n\t\t\tpaidOnly: isPaidOnly\n\t\t\tstatus\n\t\t\ttitle\n\t\t\ttitleSlug\n\t\t\thasVideoSolution\n\t\t\thasSolution\n\t\t\ttopicTags {\n\t\t\t\tname\n\t\t\t\tid\n\t\t\t\tslug\n\t\t\t}\n\t\t}\n\t}\n}\n",
76-
};
77-
const testQuery = {
78-
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 ",
79-
variables: {},
80-
};
817
const data = await axios({
828
url: "http://localhost:8000/api/get",
839
method: "POST",
8410
data: {
8511
LEETCODE_SESSION: config.LEETCODE_SESSION,
8612
CSRFTOKEN: config.CSRFTOKEN,
87-
queryData: testQuery,
13+
queryData: queries.getDailyChallengeQuery,
8814
},
8915
});
9016
return data.data.data;
9117
};
92-
console.log(testPostReq().then((res) => console.log(res.data)));
18+
19+
console.log(
20+
testPostReq().then((res) =>
21+
console.log(res.data.data.activeDailyCodingChallengeQuestion.question)
22+
)
23+
);

‎queries/queries.js‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
export const getExampleQuestionQuery = {
2+
operationName: "questionData",
3+
variables: { titleSlug: "path-sum" },
4+
query: `
5+
query questionData(: String\!) {
6+
question(titleSlug: ) {
7+
questionId
8+
questionFrontendId
9+
boundTopicId
10+
title
11+
titleSlug
12+
content
13+
translatedTitle
14+
translatedContent
15+
isPaidOnly
16+
difficulty
17+
likes
18+
dislikes
19+
isLiked
20+
similarQuestions
21+
exampleTestcases
22+
categoryTitle
23+
contributors {
24+
username
25+
profileUrl
26+
avatarUrl
27+
__typename
28+
}
29+
topicTags {
30+
name
31+
slug
32+
translatedName
33+
__typename
34+
}
35+
companyTagStats
36+
codeSnippets {
37+
lang
38+
langSlug
39+
code
40+
__typename
41+
}
42+
stats
43+
hints
44+
solution {
45+
id
46+
canSeeDetail
47+
paidOnly
48+
hasVideoSolution
49+
paidOnlyVideo
50+
__typename
51+
}
52+
status
53+
sampleTestCase
54+
metaData
55+
judgerAvailable
56+
judgeType
57+
mysqlSchemas
58+
enableRunCode
59+
enableTestMode
60+
enableDebugger
61+
envInfo
62+
libraryUrl
63+
adminUrl
64+
challengeQuestion {
65+
id
66+
date
67+
incompleteChallengeCount
68+
streakCount
69+
type
70+
__typename
71+
}
72+
__typename
73+
}
74+
}
75+
`,
76+
};
77+
78+
export const getDailyChallengeQuery = {
79+
operationName: "questionOfToday",
80+
query: `query questionOfToday {
81+
activeDailyCodingChallengeQuestion {
82+
date
83+
userStatus
84+
link
85+
question {
86+
acRate
87+
difficulty
88+
freqBar
89+
frontendQuestionId: questionFrontendId
90+
isFavor
91+
paidOnly: isPaidOnly
92+
status
93+
title
94+
content
95+
titleSlug
96+
hasVideoSolution
97+
hasSolution
98+
topicTags {
99+
name
100+
id
101+
slug
102+
}
103+
}
104+
}
105+
}`,
106+
};
107+
export const getQuestionOfTodayQuery = {
108+
query: `
109+
query questionOfToday {
110+
activeDailyCodingChallengeQuestion {
111+
date
112+
userStatus
113+
link
114+
question {
115+
acRate
116+
difficulty
117+
freqBar
118+
frontendQuestionId: questionFrontendId
119+
isFavor
120+
paidOnly: isPaidOnly
121+
status
122+
title
123+
content
124+
titleSlug
125+
hasVideoSolution
126+
hasSolution
127+
topicTags {
128+
name
129+
id
130+
slug
131+
}
132+
}
133+
}
134+
}`,
135+
variables: {},
136+
};
137+
138+
export default {
139+
getExampleQuestionQuery,
140+
getDailyChallengeQuery,
141+
getQuestionOfTodayQuery,
142+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /