Describe the bug
When using the --class-name-prefix option with GraphQL, type unions are broken.
To Reproduce
type Apple {
ripe: Boolean!
}
type Orange {
size: Float!
}
union Fruit = Apple | Orange
type FruitBasket {
fruits: [Fruit!]!
}
Used commandline:
$ datamodel-codegen --input ./apples.graphql --input-file-type graphql --class-name-prefix ABC
Current behavior
class ABCApple(BaseModel):
ripe: ABCBoolean
typename__: Literal['Apple'] | None = Field('Apple', alias='__typename')
class ABCOrange(BaseModel):
size: ABCFloat
typename__: Literal['Orange'] | None = Field('Orange', alias='__typename')
ABCFruit: TypeAlias = Union[
'Apple',
'Orange',
]
class ABCFruitBasket(BaseModel):
fruits: list[ABCFruit]
typename__: Literal['FruitBasket'] | None = Field('FruitBasket', alias='__typename')
Expected behavior
The union type should reference the prefixed class names:
Version:
- OS: MacOS 26.2
- Python version: 3.13.9
- datamodel-code-generator version: 507c33f
Describe the bug
When using the
--class-name-prefixoption with GraphQL, type unions are broken.To Reproduce
Used commandline:
Current behavior
Expected behavior
The union type should reference the prefixed class names:
Version: