Skip to content

Annotated optional string incorrectly generated as [String] #113

@hongyuan1306

Description

@hongyuan1306

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions