Skip to content

Commit d283377

Browse files
committed
Initial GraphQL codegen
1 parent 4ed7be8 commit d283377

File tree

8 files changed

+14121
-145
lines changed

8 files changed

+14121
-145
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { CodegenConfig } from "@graphql-codegen/cli";
2+
3+
const config: CodegenConfig = {
4+
schema: "schema.graphql",
5+
documents: ["src/**/*"],
6+
generates: {
7+
"./src/generated/client.ts": {
8+
plugins: [
9+
"typescript",
10+
"typescript-operations",
11+
"typescript-graphql-request",
12+
],
13+
config: {
14+
gqlImport: "graphql-request#gql",
15+
},
16+
},
17+
},
18+
emitLegacyCommonJSImports: false,
19+
};
20+
21+
export default config;

workspaces/leetcode-api/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"type": "module",
1616
"exports": "./src/main.ts",
1717
"scripts": {
18+
"codegen": "graphql-codegen-esm --config graphql-codegen.ts",
1819
"format": "prettier --color --write .",
1920
"lint": "eslint --color --max-warnings=0 .",
2021
"scrape-graphql-schema": "tsx src/scripts/scrape-graphql-schema/main.ts",
@@ -31,6 +32,8 @@
3132
},
3233
"devDependencies": {
3334
"@code-chronicles/eslint-config": "workspace:*",
35+
"@graphql-codegen/cli": "5.0.2",
36+
"@graphql-codegen/typescript-graphql-request": "6.2.0",
3437
"@types/node": "22.7.4",
3538
"eslint": "9.11.1",
3639
"graphql": "16.9.0",

workspaces/leetcode-api/src/fetchActiveDailyCodingChallengeQuestion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType
1111
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
1212

1313
const QUERY = gql`
14-
query {
14+
query fetchActiveDailyCodingChallengeQuestion {
1515
activeDailyCodingChallengeQuestion {
1616
date
1717
question {

workspaces/leetcode-api/src/fetchCommunitySolutionTopic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getGraphQLClient } from "./getGraphQLClient.ts";
66
// TODO: see if there are any fun GraphQL ESLint plugins
77

88
const QUERY = gql`
9-
query ($topicId: Int!) {
9+
query fetchTopic($topicId: Int!) {
1010
topic(id: $topicId) {
1111
title
1212
solutionTags {

workspaces/leetcode-api/src/fetchQuestionList.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { z } from "zod";
44
import { numericIdAsNumberZodType } from "@code-chronicles/util/numericIdAsNumberZodType";
55

66
import { getGraphQLClient } from "./getGraphQLClient.ts";
7+
import { getSdk } from "./generated/client.ts";
78
import { questionDifficultyZodType } from "./zod-types/questionDifficultyZodType.ts";
89
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
910

10-
const QUERY = gql`
11-
query (
11+
gql`
12+
query fetchQuestionList(
1213
$categorySlug: String!
1314
$limit: Int
1415
$skip: Int
@@ -79,7 +80,7 @@ export async function fetchQuestionList({
7980
limit?: number;
8081
skip?: number;
8182
} = {}): Promise<QuestionList> {
82-
const data = await getGraphQLClient().request(QUERY, {
83+
const data = await getSdk(getGraphQLClient()).fetchQuestionList({
8384
categorySlug,
8485
filters,
8586
limit,

workspaces/leetcode-api/src/fetchRecentAcSubmissionList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getGraphQLClient } from "./getGraphQLClient.ts";
77
import { questionTitleSlugZodType } from "./zod-types/questionTitleSlugZodType.ts";
88

99
const QUERY = gql`
10-
query ($username: String!, $limit: Int!) {
10+
query fetchRecentAcSubmissionList($username: String!, $limit: Int!) {
1111
recentAcSubmissionList(username: $username, limit: $limit) {
1212
id
1313
title

0 commit comments

Comments
 (0)