Skip to content

Commit 0149aea

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

File tree

12 files changed

+53
-28
lines changed

12 files changed

+53
-28
lines changed

workspaces/adventure-pack/webpack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const config: Configuration = {
3434
],
3535
},
3636

37+
resolve: {
38+
conditionNames: ["import"],
39+
},
40+
3741
plugins: [
3842
new webpack.DefinePlugin({
3943
ADVENTURE_PACK_COMMIT_HASH: JSON.stringify(commitHash),

workspaces/chrome-extension-hello-world/webpack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const config: Configuration = {
3030
],
3131
},
3232

33+
resolve: {
34+
conditionNames: ["import"],
35+
},
36+
3337
optimization: {
3438
splitChunks: {
3539
cacheGroups: {

workspaces/download-leetcode-submissions/webpack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const config: Configuration = {
3838
],
3939
},
4040

41+
resolve: {
42+
conditionNames: ["import"],
43+
},
44+
4145
externalsType: "commonjs",
4246
externals: ({ request }: ExternalItemFunctionData) =>
4347
Promise.resolve(

workspaces/fetch-leetcode-problem-list/webpack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const config: Configuration = {
3838
],
3939
},
4040

41+
resolve: {
42+
conditionNames: ["import"],
43+
},
44+
4145
externalsType: "commonjs",
4246
externals: ({ request }: ExternalItemFunctionData) =>
4347
Promise.resolve(

workspaces/fetch-recent-accepted-leetcode-submissions/webpack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const config: Configuration = {
3838
],
3939
},
4040

41+
resolve: {
42+
conditionNames: ["import"],
43+
},
44+
4145
externalsType: "commonjs",
4246
externals: ({ request }: ExternalItemFunctionData) =>
4347
Promise.resolve(

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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { GraphQLClient } from "graphql-request";
2+
3+
let client: GraphQLClient | null = null;
4+
5+
export function getGraphQLClient(): GraphQLClient {
6+
return (client ??= new GraphQLClient("https://leetcode.com/graphql/"));
7+
}

0 commit comments

Comments
 (0)