Skip to content

Commit 046c0fe

Browse files
committed
Generate own Zod types
1 parent 130a4d0 commit 046c0fe

17 files changed

+244
-503
lines changed

workspaces/leetcode-api/graphql-codegen.config.ts

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CodegenConfig } from "@graphql-codegen/cli";
22
import type { Types as GraphQLCodegen } from "@graphql-codegen/plugin-helpers";
3-
import immutableUpdate from "immutability-helper";
43

54
import { SCHEMA_PATCHED_FILE } from "./src/scripts/scrape-graphql-schema/constants.ts";
65

@@ -47,28 +46,6 @@ const headerPlugin: GraphQLCodegen.OutputConfig = {
4746
},
4847
};
4948

50-
const nearOperationFilePreset: GraphQLCodegen.ConfiguredOutput = {
51-
preset: "near-operation-file",
52-
presetConfig: {
53-
// We enable `globalNamespace` below so that we don't import the base
54-
// types through the preset, but let the specified plugins add the imports
55-
// if necessary. This allows us to make sure the base types import is
56-
// below the header, and it uses the ".ts" extension.
57-
baseTypesPath: "<not-used-but-cannot-be-empty>",
58-
59-
extension: ".generated.ts",
60-
fileName: null as string | null,
61-
},
62-
plugins: [headerPlugin],
63-
config: {
64-
...commonTypeScriptPluginConfig,
65-
66-
// Specified plugins will handle the imports and exports!
67-
globalNamespace: true,
68-
noExport: true,
69-
},
70-
};
71-
7249
const config: CodegenConfig = {
7350
schema: SCHEMA_PATCHED_FILE,
7451
documents: ["src/api/**/query.graphql"],
@@ -81,45 +58,39 @@ const config: CodegenConfig = {
8158
config: commonTypeScriptPluginConfig,
8259
},
8360

84-
// Generate a file for the query variables and result types, near each
85-
// operation.
86-
"src/api/**/queryTypes.generated.ts": immutableUpdate(
87-
nearOperationFilePreset,
88-
{
89-
presetConfig: { fileName: { $set: "queryTypes" } },
90-
plugins: {
91-
$push: [
92-
// Explicitly add the base types import, since the preset was
93-
// tricked into not adding it.
94-
{
95-
add: {
96-
content:
97-
'\n\nimport type * as Types from "../../graphqlTypes.generated.ts";\n\n',
98-
placement: "content",
99-
},
100-
},
101-
102-
// Generate TypeScript operations types, overriding the
103-
// `globalNamespace` which was set in the preset.
104-
{ "typescript-operations": { globalNamespace: false } },
105-
],
106-
},
61+
// Generate a small SDK for each operation using our custom plugin.
62+
"src/api/**/fetchGraphQL.generated.ts": {
63+
preset: "near-operation-file",
64+
presetConfig: {
65+
// We enable `globalNamespace` below so that we don't import the base
66+
// types through the preset, but let the specified plugins add the
67+
// imports if necessary. This allows us to make sure the base types
68+
// import is below the header, and it uses the ".ts" extension.
69+
baseTypesPath: "<not-used-but-cannot-be-empty>",
10770

108-
// Do export the types.
109-
config: { noExport: { $set: false } },
71+
fileName: "fetchGraphQL",
72+
extension: ".generated.ts",
11073
},
111-
),
74+
plugins: [
75+
headerPlugin,
11276

113-
// Generate a small SDK for each operation using our custom plugin.
114-
"src/api/**/fetchGraphQL.generated.ts": immutableUpdate(
115-
nearOperationFilePreset,
116-
{
117-
presetConfig: { fileName: { $set: "fetchGraphQL" } },
118-
plugins: {
119-
$push: ["./src/scripts/codegen/graphqlCodegenPlugin.ts"],
77+
{
78+
"typescript-operations": {
79+
// Override the `globalNamespace` which was set in the preset.
80+
globalNamespace: false,
81+
},
12082
},
83+
84+
"./src/scripts/codegen/graphqlCodegenPlugin.ts",
85+
],
86+
config: {
87+
...commonTypeScriptPluginConfig,
88+
89+
// Specified plugins will handle the imports and exports!
90+
globalNamespace: true,
91+
noExport: true,
12192
},
122-
),
93+
},
12394
},
12495

12596
hooks: {

workspaces/leetcode-api/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"jest": "29.7.0",
4747
"prettier": "3.3.3",
4848
"ts-jest": "29.2.5",
49-
"ts-to-zod": "3.13.0",
5049
"tsx": "4.19.1",
5150
"typescript": "5.6.2"
5251
}

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

Lines changed: 19 additions & 6 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/queryTypes.generated.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

workspaces/leetcode-api/src/api/question-list/fetchGraphQL.generated.ts

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

workspaces/leetcode-api/src/api/question-list/queryTypes.generated.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

workspaces/leetcode-api/src/api/recent-ac-submission-list/fetchGraphQL.generated.ts

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

workspaces/leetcode-api/src/api/recent-ac-submission-list/queryTypes.generated.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)