11import type { CodegenConfig } from "@graphql-codegen/cli" ;
22import type { Types as GraphQLCodegen } from "@graphql-codegen/plugin-helpers" ;
3- import immutableUpdate from "immutability-helper" ;
43
54import { 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-
7249const 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 : {
0 commit comments