graphql-python / graphql-python/graphene-pydantic
Annotated optional string incorrectly generated as [String]
- Dominant language
- Python
- Stars
- 249
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
With the code below
```
from pydantic import StringConstraints
UnionId = Annotated[str, StringConstraints(min_length=28, max_length=28)]
class UserModel(BaseModel):
id: str
avatar: str | None = None
unionid: UnionId | None = None
unionid1: UnionId
class UserType(PydanticObjectType):
class Meta:
model = UserModel
```
The field `unionid` is incorrectly generated as a list of string in the schema:
```
type UserType {
id: String!
avatar: String
unionid: [String]
unionid1: String!
}
```
Note that the required version of the same `UnionId` type is generated correctly as in `unionid1`. Also, an unannotated optional string is also correct, as in field `avatar`.
My environment:
graphene 3.4.3
graphene-pydantic 0.6.1
python 3.13.5
Contributor guide
Assessment
This issue has not been assessed yet.