graphql-python / graphql-python/graphene-pydantic

Annotated optional string incorrectly generated as [String]

Open
#113 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.