Describe the bug
When using the --class-name-prefix option with GraphQL, the default scalar type mappings (and custom mappings) break, resulting in incorrect types in the generated models.
To Reproduce
type Apple {
color: String!
ripe: Boolean!
}
type Orange {
size: Float!
count: Int!
}
Used commandline:
$ datamodel-codegen --input ./apples.graphql --input-file-type graphql --class-name-prefix ABC
Current behavior
from __future__ import annotations
from typing import Literal, TypeAlias
from pydantic import BaseModel, Field
ABCBoolean: TypeAlias = str
"""
The `Boolean` scalar type represents `true` or `false`.
"""
ABCFloat: TypeAlias = str
"""
The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
"""
ABCInt: TypeAlias = str
"""
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
"""
ABCString: TypeAlias = str
"""
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
"""
class ABCApple(BaseModel):
color: ABCString
ripe: ABCBoolean
typename__: Literal['Apple'] | None = Field('Apple', alias='__typename')
class ABCOrange(BaseModel):
count: ABCInt
size: ABCFloat
typename__: Literal['Orange'] | None = Field('Orange', alias='__typename')
Expected behavior
The generated types for ABCBoolean, ABCFloat, and ABCInt should map to the correct Python types (bool, float, and int respectively) instead of all mapping to str.
Version:
- OS: MacOS 26.2
- Python version: 3.13.9
- datamodel-code-generator version: 58e73ed
Describe the bug
When using the
--class-name-prefixoption with GraphQL, the default scalar type mappings (and custom mappings) break, resulting in incorrect types in the generated models.To Reproduce
Used commandline:
Current behavior
Expected behavior
The generated types for
ABCBoolean,ABCFloat, andABCIntshould map to the correct Python types (bool,float, andintrespectively) instead of all mapping tostr.Version: