Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 28 additions & 57 deletions workspaces/leetcode-api/graphql-codegen.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CodegenConfig } from "@graphql-codegen/cli";
import type { Types as GraphQLCodegen } from "@graphql-codegen/plugin-helpers";
import immutableUpdate from "immutability-helper";

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

Expand Down Expand Up @@ -47,28 +46,6 @@ const headerPlugin: GraphQLCodegen.OutputConfig = {
},
};

const nearOperationFilePreset: GraphQLCodegen.ConfiguredOutput = {
preset: "near-operation-file",
presetConfig: {
// We enable `globalNamespace` below so that we don't import the base
// types through the preset, but let the specified plugins add the imports
// if necessary. This allows us to make sure the base types import is
// below the header, and it uses the ".ts" extension.
baseTypesPath: "<not-used-but-cannot-be-empty>",

extension: ".generated.ts",
fileName: null as string | null,
},
plugins: [headerPlugin],
config: {
...commonTypeScriptPluginConfig,

// Specified plugins will handle the imports and exports!
globalNamespace: true,
noExport: true,
},
};

const config: CodegenConfig = {
schema: SCHEMA_PATCHED_FILE,
documents: ["src/api/**/query.graphql"],
Expand All @@ -81,45 +58,39 @@ const config: CodegenConfig = {
config: commonTypeScriptPluginConfig,
},

// Generate a file for the query variables and result types, near each
// operation.
"src/api/**/queryTypes.generated.ts": immutableUpdate(
nearOperationFilePreset,
{
presetConfig: { fileName: { $set: "queryTypes" } },
plugins: {
$push: [
// Explicitly add the base types import, since the preset was
// tricked into not adding it.
{
add: {
content:
'\n\nimport type * as Types from "../../graphqlTypes.generated.ts";\n\n',
placement: "content",
},
},

// Generate TypeScript operations types, overriding the
// `globalNamespace` which was set in the preset.
{ "typescript-operations": { globalNamespace: false } },
],
},
// Generate a small SDK for each operation using our custom plugin.
"src/api/**/fetchGraphQL.generated.ts": {
preset: "near-operation-file",
presetConfig: {
// We enable `globalNamespace` below so that we don't import the base
// types through the preset, but let the specified plugins add the
// imports if necessary. This allows us to make sure the base types
// import is below the header, and it uses the ".ts" extension.
baseTypesPath: "<not-used-but-cannot-be-empty>",

// Do export the types.
config: { noExport: { $set: false } },
fileName: "fetchGraphQL",
extension: ".generated.ts",
},
),
plugins: [
headerPlugin,

// Generate a small SDK for each operation using our custom plugin.
"src/api/**/fetchGraphQL.generated.ts": immutableUpdate(
nearOperationFilePreset,
{
presetConfig: { fileName: { $set: "fetchGraphQL" } },
plugins: {
$push: ["./src/scripts/codegen/graphqlCodegenPlugin.ts"],
{
"typescript-operations": {
// Override the `globalNamespace` which was set in the preset.
globalNamespace: false,
},
},

"./src/scripts/codegen/graphqlCodegenPlugin.ts",
],
config: {
...commonTypeScriptPluginConfig,

// Specified plugins will handle the imports and exports!
globalNamespace: true,
noExport: true,
},
),
},
},

hooks: {
Expand Down
1 change: 0 additions & 1 deletion workspaces/leetcode-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"jest": "29.7.0",
"prettier": "3.3.3",
"ts-jest": "29.2.5",
"ts-to-zod": "3.13.0",
"tsx": "4.19.1",
"typescript": "5.6.2"
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading
Loading