Skip to content

Commit e70f86a

Browse files
authored
Support more custom directives in GraphQL patching (#462)
We now support: * saying that a string field is actually an enum of a few specific values (e.g. question difficulty) * saying that a field is a "slug" (i.e. a string of alphanumeric elements separated by hyphens)
1 parent 79e320c commit e70f86a

39 files changed

+391
-157
lines changed

workspaces/adventure-pack/src/app/zod-types/goodyBaseZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
22

3-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
3+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
44

55
export const goodyBaseZodType = z.object({
66
importedBy: z.array(nonBlankStringZodType),

workspaces/adventure-pack/src/app/zod-types/javaGoodyZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadonlyDeep } from "type-fest";
22
import { z } from "zod";
33

4-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
4+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
55

66
import { goodyBaseZodType } from "./goodyBaseZodType.ts";
77

workspaces/adventure-pack/src/app/zod-types/javaScriptGoodyZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadonlyDeep } from "type-fest";
22
import { z } from "zod";
33

4-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
4+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
55

66
import { goodyBaseZodType } from "./goodyBaseZodType.ts";
77

workspaces/adventure-pack/src/app/zod-types/kotlinGoodyZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadonlyDeep } from "type-fest";
22
import { z } from "zod";
33

4-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
4+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
55

66
import { goodyBaseZodType } from "./goodyBaseZodType.ts";
77

workspaces/adventure-pack/src/app/zod-types/python3GoodyZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadonlyDeep } from "type-fest";
22
import { z } from "zod";
33

4-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
4+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
55

66
import { goodyBaseZodType } from "./goodyBaseZodType.ts";
77

workspaces/adventure-pack/src/app/zod-types/typeScriptGoodyZodType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadonlyDeep } from "type-fest";
22
import { z } from "zod";
33

4-
import { nonBlankStringZodType } from "@code-chronicles/util/nonBlankStringZodType";
4+
import { nonBlankStringZodType } from "@code-chronicles/util/zod-types/nonBlankStringZodType";
55

66
import { goodyBaseZodType } from "./goodyBaseZodType.ts";
77

workspaces/generate-health-report/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const COMMANDS = [
1414
"yarn workspace @code-chronicles/adventure-pack build-chrome-extension",
1515
"yarn workspace @code-chronicles/fetch-leetcode-problem-list build",
1616
"yarn workspace @code-chronicles/fetch-recent-accepted-leetcode-submissions build",
17+
// TODO: assert that no code changes
18+
"yarn workspace @code-chronicles/leetcode-api patch-graphql-schema",
19+
// TODO: assert that no code changes
1720
"yarn workspace @code-chronicles/leetcode-api codegen",
1821
"yarn workspace @code-chronicles/leetcode-zen-mode build",
1922
"yarn workspace @code-chronicles/post-leetcode-potd-to-discord build",

workspaces/leetcode-api/schema-patched.graphql

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspaces/leetcode-api/src/api/active-daily-coding-challenge-question/fetchGraphQL.generated.ts

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspaces/leetcode-api/src/api/active-daily-coding-challenge-question/main.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
import { z } from "zod";
22

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

88
import { questionDifficultyZodType } from "../../zod-types/questionDifficultyZodType.ts";
9-
import { questionTitleSlugZodType } from "../../zod-types/questionTitleSlugZodType.ts";
9+
import { slugZodType } from "../../zod-types/slugZodType.ts";
1010
import { fetchGraphQL } from "./fetchGraphQL.generated.ts";
1111

1212
const questionZodType = z.object({
1313
difficulty: questionDifficultyZodType,
1414
questionFrontendId: numericIdAsNumberZodType,
1515
title: z.string().trim().min(1),
16-
titleSlug: questionTitleSlugZodType,
16+
titleSlug: slugZodType,
1717
});
1818

19-
const activeDailyCodingChallengeQuestionZodType = z.object({
20-
date: z
21-
.string()
22-
.trim()
23-
.regex(/^\d{4}-\d{2}-\d{2}$/),
24-
question: questionZodType,
25-
});
26-
27-
export type ActiveDailyCodingChallengeQuestion = z.infer<
28-
typeof activeDailyCodingChallengeQuestionZodType
29-
>;
19+
export type ActiveDailyCodingChallengeQuestion = {
20+
date: string;
21+
question: z.infer<typeof questionZodType>;
22+
};
3023

3124
export async function fetchActiveDailyCodingChallengeQuestionWithoutDateValidation(): Promise<ActiveDailyCodingChallengeQuestion> {
32-
const { activeDailyCodingChallengeQuestion } = await fetchGraphQL();
33-
34-
return activeDailyCodingChallengeQuestionZodType.parse(
35-
activeDailyCodingChallengeQuestion,
36-
);
25+
const {
26+
activeDailyCodingChallengeQuestion: { date, question },
27+
} = await fetchGraphQL();
28+
29+
return {
30+
date,
31+
question: questionZodType.parse(question),
32+
};
3733
}
3834

3935
export async function fetchActiveDailyCodingChallengeQuestionWithDateValidation({

0 commit comments

Comments
 (0)