@@ -22,7 +22,7 @@ type Options<T = TypeNode> = {
2222 types : TypeItem [ ] ;
2323 typeNamesConvention : NamingConvention ;
2424 enumValuesConvention : NamingConvention ;
25- terminateCircularRelationships : boolean ;
25+ terminateCircularRelationships : boolean | 'immediate' ;
2626 prefix : string | undefined ;
2727 typesPrefix : string ;
2828 enumsPrefix : string ;
@@ -40,6 +40,9 @@ type Options<T = TypeNode> = {
4040 nonNull : boolean ;
4141} ;
4242
43+ const getTerminateCircularRelationshipsConfig = ( { terminateCircularRelationships } : TypescriptMocksPluginConfig ) =>
44+ terminateCircularRelationships ? terminateCircularRelationships : false ;
45+
4346const convertName = ( value : string , fn : ( v : string ) => string , transformUnderscore : boolean ) : string => {
4447 if ( transformUnderscore ) {
4548 return fn ( value ) ;
@@ -430,7 +433,7 @@ const getMockString = (
430433 typeName : string ,
431434 fields : string ,
432435 typeNamesConvention : NamingConvention ,
433- terminateCircularRelationships : boolean ,
436+ terminateCircularRelationships : boolean | 'immediate' ,
434437 addTypename = false ,
435438 prefix ,
436439 typesPrefix = '' ,
@@ -443,13 +446,15 @@ const getMockString = (
443446 const typenameReturnType = addTypename ? `{ __typename: '${ typeName } ' } & ` : '' ;
444447
445448 if ( terminateCircularRelationships ) {
449+ const relationshipsToOmitInit =
450+ terminateCircularRelationships === 'immediate' ? '_relationshipsToOmit' : 'new Set(_relationshipsToOmit)' ;
446451 return `
447452export const ${ toMockName (
448453 typeName ,
449454 casedName ,
450455 prefix ,
451456 ) } = (overrides?: Partial<${ casedNameWithPrefix } >, _relationshipsToOmit: Set<string> = new Set()): ${ typenameReturnType } ${ casedNameWithPrefix } => {
452- const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit) ;
457+ const relationshipsToOmit: Set<string> = ${ relationshipsToOmitInit } ;
453458 relationshipsToOmit.add('${ casedName } ');
454459 return {${ typename }
455460${ fields }
@@ -541,7 +546,7 @@ export interface TypescriptMocksPluginConfig {
541546 addTypename ?: boolean ;
542547 prefix ?: string ;
543548 scalars ?: ScalarMap ;
544- terminateCircularRelationships ?: boolean ;
549+ terminateCircularRelationships ?: boolean | 'immediate' ;
545550 typesPrefix ?: string ;
546551 enumsPrefix ?: string ;
547552 transformUnderscore ?: boolean ;
@@ -669,7 +674,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
669674 types,
670675 typeNamesConvention,
671676 enumValuesConvention,
672- terminateCircularRelationships : ! ! config . terminateCircularRelationships ,
677+ terminateCircularRelationships : getTerminateCircularRelationshipsConfig ( config ) ,
673678 prefix : config . prefix ,
674679 typesPrefix : config . typesPrefix ,
675680 enumsPrefix : config . enumsPrefix ,
@@ -706,7 +711,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
706711 types,
707712 typeNamesConvention,
708713 enumValuesConvention,
709- terminateCircularRelationships : ! ! config . terminateCircularRelationships ,
714+ terminateCircularRelationships : getTerminateCircularRelationshipsConfig ( config ) ,
710715 prefix : config . prefix ,
711716 typesPrefix : config . typesPrefix ,
712717 enumsPrefix : config . enumsPrefix ,
@@ -733,7 +738,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
733738 fieldName ,
734739 mockFields ,
735740 typeNamesConvention ,
736- ! ! config . terminateCircularRelationships ,
741+ getTerminateCircularRelationshipsConfig ( config ) ,
737742 false ,
738743 config . prefix ,
739744 config . typesPrefix ,
@@ -756,7 +761,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
756761 typeName ,
757762 mockFields ,
758763 typeNamesConvention ,
759- ! ! config . terminateCircularRelationships ,
764+ getTerminateCircularRelationshipsConfig ( config ) ,
760765 ! ! config . addTypename ,
761766 config . prefix ,
762767 config . typesPrefix ,
@@ -777,7 +782,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
777782 typeName ,
778783 mockFields ,
779784 typeNamesConvention ,
780- ! ! config . terminateCircularRelationships ,
785+ getTerminateCircularRelationshipsConfig ( config ) ,
781786 ! ! config . addTypename ,
782787 config . prefix ,
783788 config . typesPrefix ,
0 commit comments