File tree Expand file tree Collapse file tree 3 files changed +292
-92
lines changed
other/visitor-plugin-common/src
typescript/operations/tests Expand file tree Collapse file tree 3 files changed +292
-92
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @graphql-codegen/visitor-plugin-common ' : patch
3+ ---
4+
5+ fix fragment type generation names
Original file line number Diff line number Diff line change @@ -962,16 +962,19 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
962962 return parentName ;
963963 }
964964
965- // When the parent schema type is an interface, use the interface name instead of the concrete type
966- // BUT only if we're not inside a fragment (fragments explicitly target specific types)
967965 const schemaType = this . _schema . getType ( typeName ) ;
968- const isInFragment = parentName . includes ( 'Fragment' ) ;
969- if (
970- isObjectType ( schemaType ) &&
971- this . _parentSchemaType &&
972- isInterfaceType ( this . _parentSchemaType ) &&
973- ! isInFragment
974- ) {
966+
967+ // Check if current selection set has fragments (e.g., "... AppNotificationFragment" or "... on AppNotification")
968+ const hasFragment =
969+ this . _selectionSet ?. selections ?. some (
970+ selection => selection . kind === Kind . INLINE_FRAGMENT || selection . kind === Kind . FRAGMENT_SPREAD
971+ ) ?? false ;
972+
973+ // When the parent schema type is an interface:
974+ // - If we're processing inline fragments, use the concrete type name
975+ // - If we're processing the interface directly, use the interface name
976+ // - If we're in a named fragment, always use the concrete type name
977+ if ( isObjectType ( schemaType ) && this . _parentSchemaType && isInterfaceType ( this . _parentSchemaType ) && ! hasFragment ) {
975978 return `${ parentName } _${ this . _parentSchemaType . name } ` ;
976979 }
977980
You can’t perform that action at this time.
0 commit comments