File tree Expand file tree Collapse file tree 5 files changed +25
-28
lines changed
workspaces/leetcode-api/src Expand file tree Collapse file tree 5 files changed +25
-28
lines changed Original file line number Diff line number Diff line change 1- import { gql , request } from "graphql-request" ;
1+ import { gql } from "graphql-request" ;
22import { z } from "zod" ;
33
44import { numericIdAsNumberZodType } from "@code-chronicles/util/numericIdAsNumberZodType" ;
55import { sleep } from "@code-chronicles/util/sleep" ;
66import { MS_IN_SEC } from "@code-chronicles/util/timeConstants" ;
77import { timestampInSecondsToYearMonthDay } from "@code-chronicles/util/timestampInSecondsToYearMonthDay" ;
88
9+ import { getGraphQLClient } from "./getGraphQLClient.ts" ;
910import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType.ts" ;
1011import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts" ;
1112
@@ -47,10 +48,7 @@ export type ActiveDailyCodingChallengeQuestion = z.infer<
4748> ;
4849
4950export 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}
Original file line number Diff line number Diff line change 1- import { gql , request } from "graphql-request" ;
1+ import { gql } from "graphql-request" ;
22import { z } from "zod" ;
33
4+ import { getGraphQLClient } from "./getGraphQLClient.ts" ;
5+
46// TODO: see if there are any fun GraphQL ESLint plugins
57
68const QUERY = gql `
@@ -37,12 +39,8 @@ export type CommunitySolutionTopic = z.infer<
3739
3840export 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}
Original file line number Diff line number Diff line change 1- import { gql , request } from "graphql-request" ;
1+ import { gql } from "graphql-request" ;
22import { z } from "zod" ;
33
44import { numericIdAsNumberZodType } from "@code-chronicles/util/numericIdAsNumberZodType" ;
55
6+ import { getGraphQLClient } from "./getGraphQLClient.ts" ;
67import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType.ts" ;
78import { 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 ) ;
Original file line number Diff line number Diff line change 1- import { gql , request } from "graphql-request" ;
1+ import { gql } from "graphql-request" ;
22import { z } from "zod" ;
33
44import { numericIdAsStringZodType } from "@code-chronicles/util/numericIdAsStringZodType" ;
55
6+ import { getGraphQLClient } from "./getGraphQLClient.ts" ;
67import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts" ;
78
89const 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments