Skip to content

Commit 746145f

Browse files
committed
Add generated file header
1 parent 850c0f7 commit 746145f

File tree

9 files changed

+72
-42
lines changed

9 files changed

+72
-42
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,52 @@ const commonTypeScriptPluginConfig = {
1010
// TODO: add strictScalars: true
1111
};
1212

13+
const headerPlugin = {
14+
add: {
15+
content: `
16+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
17+
// Instead, update the generation process or inputs and run \`yarn codegen\`.
18+
`,
19+
},
20+
};
21+
1322
const config: CodegenConfig = {
1423
schema: "schema.graphql",
1524
documents: ["src/**/*.graphql"],
1625
overwrite: true,
1726
emitLegacyCommonJSImports: false,
1827
generates: {
1928
"src/graphqlTypes.generated.ts": {
20-
plugins: ["typescript"],
29+
plugins: [headerPlugin, "typescript"],
2130
config: commonTypeScriptPluginConfig,
2231
},
2332
"src/": {
2433
preset: "near-operation-file",
2534
presetConfig: {
26-
// TODO: get this to use a ".ts" extension in the output
27-
baseTypesPath: "~../../graphqlTypes.generated",
35+
// The base types are not imported because of the use of
36+
// `globalNamespace` below, instead our custom plugin will add the
37+
// import, so that it can end up _below_ the header.
38+
baseTypesPath: "<not-used-but-cannot-be-empty>",
39+
2840
extension: ".generated.ts",
2941
fileName: "fetchGraphQL",
3042
},
3143
plugins: [
32-
"typescript-operations",
44+
headerPlugin,
45+
{ "typescript-operations": { globalNamespace: false } },
3346
"./src/scripts/codegen/graphqlCodegenPlugin.ts",
3447
],
3548
config: {
3649
...commonTypeScriptPluginConfig,
3750

38-
// Our custom plugin will handle the exports!
51+
// Our custom plugin will handle the imports and exports!
52+
globalNamespace: true,
3953
noExport: true,
4054
},
4155
},
4256
},
4357
hooks: {
44-
afterAllFileWrite: [
45-
// The per-operation files can end up with imports in the middle.
46-
"eslint --fix --rule import-x/first:warn",
47-
48-
"prettier --write",
49-
],
58+
afterAllFileWrite: ["prettier --write"],
5059
},
5160
};
5261

workspaces/leetcode-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@code-chronicles/eslint-config": "workspace:*",
35+
"@graphql-codegen/add": "5.0.3",
3536
"@graphql-codegen/cli": "5.0.2",
3637
"@graphql-codegen/near-operation-file-preset": "3.0.0",
3738
"@types/node": "22.7.4",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import type * as Types from "../../graphqlTypes.generated.js";
1+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
2+
// Instead, update the generation process or inputs and run `yarn codegen`.
23

34
import type { Simplify } from "type-fest";
45

56
import { getGraphQLClient } from "../../getGraphQLClient.ts";
7+
import type * as Types from "../../graphqlTypes.generated.ts";
68

79
type ActiveDailyCodingChallengeQuestionQueryVariables = Types.Exact<{
810
[key: string]: never;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import type * as Types from "../../graphqlTypes.generated.js";
1+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
2+
// Instead, update the generation process or inputs and run `yarn codegen`.
23

34
import type { Simplify } from "type-fest";
45

56
import { getGraphQLClient } from "../../getGraphQLClient.ts";
7+
import type * as Types from "../../graphqlTypes.generated.ts";
68

79
type QuestionListQueryVariables = Types.Exact<{
810
categorySlug: Types.Scalars["String"]["input"];

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import type * as Types from "../../graphqlTypes.generated.js";
1+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
2+
// Instead, update the generation process or inputs and run `yarn codegen`.
23

34
import type { Simplify } from "type-fest";
45

56
import { getGraphQLClient } from "../../getGraphQLClient.ts";
7+
import type * as Types from "../../graphqlTypes.generated.ts";
68

79
type RecentAcSubmissionListQueryVariables = Types.Exact<{
810
username: Types.Scalars["String"]["input"];

workspaces/leetcode-api/src/api/topic/fetchGraphQL.generated.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import type * as Types from "../../graphqlTypes.generated.js";
1+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
2+
// Instead, update the generation process or inputs and run `yarn codegen`.
23

34
import type { Simplify } from "type-fest";
45

56
import { getGraphQLClient } from "../../getGraphQLClient.ts";
7+
import type * as Types from "../../graphqlTypes.generated.ts";
68

79
type TopicQueryVariables = Types.Exact<{
810
topicId: Types.Scalars["Int"]["input"];

workspaces/leetcode-api/src/graphqlTypes.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// THIS FILE IS GENERATED! DO NOT MODIFY IT MANUALLY!!
2+
// Instead, update the generation process or inputs and run `yarn codegen`.
3+
14
export type Maybe<T> = T | null;
25
export type InputMaybe<T> = Maybe<T>;
36
export type Exact<T extends { [key: string]: unknown }> = {

workspaces/leetcode-api/src/scripts/codegen/graphqlCodegenPlugin.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,27 @@ export const plugin: PluginFunction<{}> = function plugin(_schema, documents) {
2828

2929
// TODO: strip out the operation name from the minified GraphQL
3030

31-
// Note: The import will be moved to the top by ESLint post-processing.
32-
return `
33-
export type QueryVariables = Simplify<${operationName}QueryVariables>;
34-
export type Query = Simplify<${operationName}Query>;
35-
36-
export const QUERY = ${JSON.stringify(minifiedGraphql)};
37-
38-
export function fetchGraphQL(variables: QueryVariables): Promise<Query> {
39-
return getGraphQLClient().request(QUERY, variables);
40-
}
41-
42-
import type { Simplify } from 'type-fest';
43-
44-
import { getGraphQLClient } from "../../getGraphQLClient.ts";
45-
`;
31+
return {
32+
prepend: [
33+
`
34+
import type { Simplify } from "type-fest";
35+
36+
import { getGraphQLClient } from "../../getGraphQLClient.ts";
37+
import type * as Types from "../../graphqlTypes.generated.ts";
38+
`,
39+
],
40+
append: [
41+
`
42+
export type QueryVariables = Simplify<${operationName}QueryVariables>;
43+
export type Query = Simplify<${operationName}Query>;
44+
45+
export const QUERY = ${JSON.stringify(minifiedGraphql)};
46+
47+
export function fetchGraphQL(variables: QueryVariables): Promise<Query> {
48+
return getGraphQLClient().request(QUERY, variables);
49+
}
50+
`,
51+
],
52+
content: "",
53+
};
4654
};

yarn.lock

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

0 commit comments

Comments
 (0)