strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.96k stars 527 forks source link

Descriptions don't work with pydantic decorators #3484

Open pmowrer opened 5 months ago

pmowrer commented 5 months ago

Describe the Bug

Works as expected with regular @strawberry.input decorator

@strawberry.input
class User:
    id: str = strawberry.field(description="Id of the user")
    name: str | None = strawberry.field(description="Name of the user", deprecation_reason="No longer used")
input User {
  """Id of the user"""
  id: String!    

  """Name of the user"""
  name: String @deprecated(reason: "No longer used")
}

Doesn't work as expected with @strawberry.experimental.pydantic.input decorator

class UserPyd(BaseModel):
  id: str
  name: str | None

@strawberry.experimental.pydantic.input(model=UserPyd)
class User:
    id: str = strawberry.field(description="Id of the user")
    name: str | None = strawberry.field(description="Name of the user", deprecation_reason="No longer used")
input User {
  id: String!
  name: String @deprecated(reason: "No longer used")
}

System Information

Additional Context

Upvote & Fund

Fund with Polar

mecampbellsoup commented 5 months ago

As a sanity check, does removing the pass change anything? It definitely shouldn't but, just in case I suppose...

@strawberry.experimental.pydantic.input(model=UserPyd)
class User:
    id: str = strawberry.field(description="Id of the user")
    name: str | None = strawberry.field(description="Name of the user", deprecation_reason="No longer used")
    pass
pmowrer commented 4 months ago

Thanks for catching the typo! Unfortunately doesn't impact the bug