Skip to content

Commit eb0b38e

Browse files
committed
avoid repeating the url
1 parent 86df3d4 commit eb0b38e

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

workspaces/leetcode-api/src/fetchActiveDailyCodingChallengeQuestion.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { gql, request } from "graphql-request";
1+
import { gql } from "graphql-request";
22
import { z } from "zod";
33

44
import { numericIdAsNumberZodType } from "@code-chronicles/util/numericIdAsNumberZodType";
55
import { sleep } from "@code-chronicles/util/sleep";
66
import { MS_IN_SEC } from "@code-chronicles/util/timeConstants";
77
import { timestampInSecondsToYearMonthDay } from "@code-chronicles/util/timestampInSecondsToYearMonthDay";
88

9+
import { getGraphQLClient } from "./getGraphQLClient.ts";
910
import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType.ts";
1011
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
1112

@@ -47,10 +48,7 @@ export type ActiveDailyCodingChallengeQuestion = z.infer<
4748
>;
4849

4950
export async function fetchActiveDailyCodingChallengeQuestionWithoutDateValidation(): Promise<ActiveDailyCodingChallengeQuestion> {
50-
const data = await request({
51-
url: "https://leetcode.com/graphql/",
52-
document: QUERY,
53-
});
51+
const data = await getGraphQLClient().request(QUERY);
5452

5553
return activeDailyCodingChallengeQuestionZodType.parse(data);
5654
}

workspaces/leetcode-api/src/fetchCommunitySolutionTopic.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { gql, request } from "graphql-request";
1+
import { gql } from "graphql-request";
22
import { z } from "zod";
33

4+
import { getGraphQLClient } from "./getGraphQLClient.ts";
5+
46
// TODO: see if there are any fun GraphQL ESLint plugins
57

68
const QUERY = gql`
@@ -37,12 +39,8 @@ export type CommunitySolutionTopic = z.infer<
3739

3840
export async function fetchCommunitySolutionTopic(
3941
topicId: string,
40-
): Promise<null | CommunitySolutionTopic> {
41-
const data = await request({
42-
url: "https://leetcode.com/graphql/",
43-
document: QUERY,
44-
variables: { topicId },
45-
});
42+
): Promise<CommunitySolutionTopic> {
43+
const data = await getGraphQLClient().request(QUERY, { topicId });
4644

4745
return communitySolutionTopicZodType.parse(data);
4846
}

workspaces/leetcode-api/src/fetchQuestionList.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { gql, request } from "graphql-request";
1+
import { gql } from "graphql-request";
22
import { z } from "zod";
33

44
import { numericIdAsNumberZodType } from "@code-chronicles/util/numericIdAsNumberZodType";
55

6+
import { getGraphQLClient } from "./getGraphQLClient.ts";
67
import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType.ts";
78
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
89

@@ -78,15 +79,11 @@ export async function fetchQuestionList({
7879
limit?: number;
7980
skip?: number;
8081
} = {}): Promise<QuestionList> {
81-
const data = await request({
82-
url: "https://leetcode.com/graphql/",
83-
document: QUERY,
84-
variables: {
85-
categorySlug,
86-
filters,
87-
limit,
88-
skip,
89-
},
82+
const data = await getGraphQLClient().request(QUERY, {
83+
categorySlug,
84+
filters,
85+
limit,
86+
skip,
9087
});
9188

9289
return questionListZodType.parse(data);

workspaces/leetcode-api/src/fetchRecentAcSubmissionList.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { gql, request } from "graphql-request";
1+
import { gql } from "graphql-request";
22
import { z } from "zod";
33

44
import { numericIdAsStringZodType } from "@code-chronicles/util/numericIdAsStringZodType";
55

6+
import { getGraphQLClient } from "./getGraphQLClient.ts";
67
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
78

89
const QUERY = gql`
@@ -44,11 +45,7 @@ export async function fetchRecentAcSubmissionList({
4445
limit?: number;
4546
username: string;
4647
}): Promise<RecentAcSubmission[]> {
47-
const data = await request({
48-
url: "https://leetcode.com/graphql/",
49-
document: QUERY,
50-
variables: { username, limit },
51-
});
48+
const data = await getGraphQLClient().request(QUERY, { username, limit });
5249

5350
return recentAcSubmissionListZodType.parse(data);
5451
}

0 commit comments

Comments
 (0)