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

strawberry.field does not type check properly for async resolvers, but strawberry.field() does #3071

Closed
ben-xo opened this issue Sep 1, 2023 · 3 comments · Fixed by #3241
Labels
bug Something isn't working

Comments

@ben-xo
Copy link

ben-xo commented Sep 1, 2023

Describe the Bug

An example speaks a thousand words. Given the following minimal test case:

import strawberry
from django.test import SimpleTestCase


@strawberry.type
class Example:
    @strawberry.field
    async def async_field_1(self) -> str:
        return "str 1"

    @strawberry.field()
    async def async_field_2(self) -> str:
        return "str 2"


class ExampleTest(SimpleTestCase):
    async def test_types(self):
        example = Example()

        self.assertEqual(await example.async_field_1(), "str 1")
        self.assertEqual(await example.async_field_2(), "str 2")
  • the only difference between async_field_1 and async_field_2 is the parentheses after the strawberry.field annotation
  • the test passes (demonstrated by green checkmark)
  • the first assertion does not pass type check (demonstrated by red squiggly). The second one does.

Screenshot:
Screenshot 2023-09-01 at 12 38 27

The problem shows up as "async_field_1 is not awaitable" (if the field has args), or "missing argument for parameter resolver" (if the field has no args)

System Information

  • Strawberry version: 0.204.0

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
@ben-xo ben-xo added the bug Something isn't working label Sep 1, 2023
@patrick91
Copy link
Member

hi @ben-xo! it this mypy or pyright?

@ben-xo
Copy link
Author

ben-xo commented Sep 1, 2023

hi @ben-xo! it this mypy or pyright?

It's coming up as Pylance within VSCode so I guess it must be pyright. Our mypy config seems ok with it.

@ben-xo
Copy link
Author

ben-xo commented Sep 1, 2023

Here are the two variations
Screenshot 2023-09-01 at 12 52 37
Screenshot 2023-09-01 at 12 40 35

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

Successfully merging a pull request may close this issue.

2 participants