Skip to content

codegen doesn't properly handle postponed type annotations #3699

Open

Description

strawberry codegen --schema schema.graphql generates models referencing postponed types as its class variable instead of using a string to be deferred.

Describe the Bug

From schema, the following code has been generated. In this example, AccessCredentialFilter is referencing itself inside the model

@strawberry.input
class AccessCredentialFilter:
    and_: list[AccessCredentialFilter | None] | None = strawberry.field(name="and")

However, it should rather be

@strawberry.input
class AccessCredentialFilter:
    and_: list[Union["AccessCredentialFilter", None]] | None = strawberry.field(name="and")

or

@strawberry.input
class AccessCredentialFilter:
    and_: list[Optional["AccessCredentialFilter"]] | None = strawberry.field(name="and")

System Information

  • Operating system: Ubuntu 22.04
  • Strawberry version (if applicable): 0.248.1

Additional Context

It seems there was a related discussion: #769
but not sure if it was discussed in the context of codegen.

I'd be happy to contribute if I can be directed to the right part of the code.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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