Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postponed annotation evaluation causes Annotated to break #1819

Closed
yrd opened this issue Apr 18, 2022 · 1 comment · Fixed by #1994
Closed

Postponed annotation evaluation causes Annotated to break #1819

yrd opened this issue Apr 18, 2022 · 1 comment · Fixed by #1994

Comments

@yrd
Copy link

yrd commented Apr 18, 2022

When using postponed annotation evaluation, annotating resolver arguments no longer works:

from __future__ import annotations

import random
from typing import Annotated

import strawberry


@strawberry.type
class Query:
    @strawberry.field
    def dice_roll(
        self,
        sides: Annotated[
            int,
            strawberry.argument(description="Number of sides the die should have."),
        ] = 6,
    ) -> int:
        return random.randint(1, sides)


strawberry.Schema(query=Query)

The example above raises this TypeError:

TypeError: Query fields cannot be resolved. Unexpected type 'typing.Annotated[int, <strawberry.arguments.StrawberryArgumentAnnotation object at 0x7fd12e130d00>]'

When the first line (from __future__ import annotations) is left out, everything works as intended. This will probably also break once Python 3.11 lands, since the behavior will become mandatory then. #1586 refers to a somewhat related issue.

@patrick91
Copy link
Member

@yrd I think this has been fixed, I'll close for now, but let me know if is not fixed.

I tested it here: https://play.strawberry.rocks/?gist=1f311d6ce6b63ef50bdb55115551fbb5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants