@@ -41,6 +41,7 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
4141 experimentalFragmentVariables : boolean ;
4242 mergeFragmentTypes : boolean ;
4343 customDirectives : CustomDirectivesConfig ;
44+ generatesOperationTypes : boolean ;
4445}
4546
4647export interface RawDocumentsConfig extends RawTypesConfig {
@@ -175,6 +176,29 @@ export interface RawDocumentsConfig extends RawTypesConfig {
175176 * ```
176177 */
177178 customDirectives ?: CustomDirectivesConfig ;
179+
180+ /**
181+ * @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
182+ * @default true
183+ * @exampleMarkdown
184+ * ```ts filename="codegen.ts"
185+ * import type { CodegenConfig } from '@graphql-codegen/cli';
186+ *
187+ * const config: CodegenConfig = {
188+ * // ...
189+ * generates: {
190+ * 'path/to/file.ts': {
191+ * plugins: ['typescript-operations'],
192+ * config: {
193+ * generatesOperationTypes: false,
194+ * },
195+ * },
196+ * },
197+ * };
198+ * export default config;
199+ * ```
200+ */
201+ generatesOperationTypes ?: boolean ;
178202}
179203
180204export class BaseDocumentsVisitor <
@@ -207,6 +231,7 @@ export class BaseDocumentsVisitor<
207231 operationResultSuffix : getConfigValue ( rawConfig . operationResultSuffix , '' ) ,
208232 scalars : buildScalarsFromConfig ( _schema , rawConfig , defaultScalars ) ,
209233 customDirectives : getConfigValue ( rawConfig . customDirectives , { apolloUnmask : false } ) ,
234+ generatesOperationTypes : getConfigValue ( rawConfig . generatesOperationTypes , true ) ,
210235 ...( ( additionalConfig || { } ) as any ) ,
211236 } ) ;
212237
@@ -261,6 +286,10 @@ export class BaseDocumentsVisitor<
261286 }
262287
263288 FragmentDefinition ( node : FragmentDefinitionNode ) : string {
289+ if ( ! this . config . generatesOperationTypes ) {
290+ return null ;
291+ }
292+
264293 const fragmentRootType = this . _schema . getType ( node . typeCondition . name . value ) ;
265294 const selectionSet = this . _selectionSetToObject . createNext ( fragmentRootType , node . selectionSet ) ;
266295 const fragmentSuffix = this . getFragmentSuffix ( node ) ;
@@ -289,7 +318,11 @@ export class BaseDocumentsVisitor<
289318 return variablesBlock ;
290319 }
291320
292- OperationDefinition ( node : OperationDefinitionNode ) : string {
321+ OperationDefinition ( node : OperationDefinitionNode ) : string | null {
322+ if ( ! this . config . generatesOperationTypes ) {
323+ return null ;
324+ }
325+
293326 const name = this . handleAnonymousOperation ( node ) ;
294327 const operationRootType = getRootType ( node . operation , this . _schema ) ;
295328
0 commit comments