@@ -46,6 +46,7 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
4646 experimentalFragmentVariables : boolean ;
4747 mergeFragmentTypes : boolean ;
4848 customDirectives : CustomDirectivesConfig ;
49+ generatesOperationTypes : boolean ;
4950}
5051
5152export interface RawDocumentsConfig extends RawTypesConfig {
@@ -180,6 +181,29 @@ export interface RawDocumentsConfig extends RawTypesConfig {
180181 * ```
181182 */
182183 customDirectives ?: CustomDirectivesConfig ;
184+
185+ /**
186+ * @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
187+ * @default true
188+ * @exampleMarkdown
189+ * ```ts filename="codegen.ts"
190+ * import type { CodegenConfig } from '@graphql-codegen/cli';
191+ *
192+ * const config: CodegenConfig = {
193+ * // ...
194+ * generates: {
195+ * 'path/to/file.ts': {
196+ * plugins: ['typescript-operations'],
197+ * config: {
198+ * generatesOperationTypes: false,
199+ * },
200+ * },
201+ * },
202+ * };
203+ * export default config;
204+ * ```
205+ */
206+ generatesOperationTypes ?: boolean ;
183207}
184208
185209export class BaseDocumentsVisitor <
@@ -214,6 +238,7 @@ export class BaseDocumentsVisitor<
214238 customDirectives : getConfigValue ( rawConfig . customDirectives , {
215239 apolloUnmask : false ,
216240 } ) ,
241+ generatesOperationTypes : getConfigValue ( rawConfig . generatesOperationTypes , true ) ,
217242 ...( ( additionalConfig || { } ) as any ) ,
218243 } ) ;
219244
@@ -268,6 +293,10 @@ export class BaseDocumentsVisitor<
268293 }
269294
270295 FragmentDefinition ( node : FragmentDefinitionNode ) : string {
296+ if ( ! this . config . generatesOperationTypes ) {
297+ return null ;
298+ }
299+
271300 const fragmentRootType = this . _schema . getType ( node . typeCondition . name . value ) ;
272301 const selectionSet = this . _selectionSetToObject . createNext ( fragmentRootType , node . selectionSet ) ;
273302 const fragmentSuffix = this . getFragmentSuffix ( node ) ;
@@ -300,7 +329,11 @@ export class BaseDocumentsVisitor<
300329 return variablesBlock ;
301330 }
302331
303- OperationDefinition ( node : OperationDefinitionNode ) : string {
332+ OperationDefinition ( node : OperationDefinitionNode ) : string | null {
333+ if ( ! this . config . generatesOperationTypes ) {
334+ return null ;
335+ }
336+
304337 const name = this . handleAnonymousOperation ( node ) ;
305338 const operationRootType = getRootType ( node . operation , this . _schema ) ;
306339
0 commit comments