Skip to content

Commit f588d91

Browse files
authored
fix invalid check for inline fragments (#10530)
* fix invalid check for inline fragments * handle fragment spreads * added changeset * comment fixup
1 parent 90b62ea commit f588d91

File tree

3 files changed

+292
-92
lines changed

3 files changed

+292
-92
lines changed

.changeset/eager-deer-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/visitor-plugin-common': patch
3+
---
4+
5+
fix fragment type generation names

packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)