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

codegen doesn't properly handle postponed type annotations #3699

Open
jbkoh opened this issue Nov 14, 2024 · 0 comments
Open

codegen doesn't properly handle postponed type annotations #3699

jbkoh opened this issue Nov 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jbkoh
Copy link

jbkoh commented Nov 14, 2024

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
@jbkoh jbkoh added the bug Something isn't working label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant