strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

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

Open devkral opened this issue 1 year ago • 1 comments
trafficstars

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 avatar Jan 10 '24 02:01 devkral

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

devkral avatar Jan 10 '24 07:01 devkral