Skip to content

Optional Union fails to set correct name/description #3993

@fogrye

Description

@fogrye

Optional union type definition ignores annotation metadata added with typing.Annotated

Describe the Bug

Following the documentation create sample definition:

import strawberry
from typing import Annotated
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter

@strawberry.type
class A:
    a: str

@strawberry.type
class B:
    b: str

@strawberry.type
class Query:
    u: Annotated[A | B | None, strawberry.union("C")]

schema = strawberry.Schema(query=Query)
app = FastAPI()
graphql_app = GraphQLRouter(schema)
app.include_router(graphql_app, prefix="/graphql")

Checking schema introspection in gql client will show u as "AB" type instead of "C".

Now remove None from annotation and check again - you'll see correct definition.

System Information

  • Operating system: bookworm
  • Python version: 3.13
  • Strawberry version (if applicable): 0.282.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions