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

root Query type doesn't initialize fields correctly, fields with default_factory are unininitialized #3332

Open
devkral opened this issue Jan 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@devkral
Copy link
Contributor

devkral commented Jan 10, 2024

Describe the Bug

Here a code example

@strawberry.type
class Sub:
    @strawberry.field
    def foo(self) -> str:
        return "bar"

@strawberry.type
class Query:
    sub: Sub = strawberry.field(default_factory=Sub)

schema = strawberry.Schema(query=Query)

# this fails
result = schema.execute_sync(
    """
    query TestQuery{
        sub {
            foo
        }
    }
    """
)

Solution: initialize also the root schema or provide a fallback for None in get_result

System Information

  • Operating system:
  • Strawberry version (if applicable):

Additional Context

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
@devkral devkral added the bug Something isn't working label Jan 10, 2024
@devkral
Copy link
Contributor Author

devkral commented Jan 10, 2024

as the source is somewhere defined outside of strawberry, None must be handled

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