graphene-pydantic icon indicating copy to clipboard operation
graphene-pydantic copied to clipboard

Annotated optional string incorrectly generated as [String]

Open hongyuan1306 opened this issue 5 months ago • 0 comments

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

hongyuan1306 avatar Jun 25 '25 00:06 hongyuan1306