-
-
Notifications
You must be signed in to change notification settings - Fork 537
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
Fix _RESOLVER_TYPE for async functions #3241
Fix _RESOLVER_TYPE for async functions #3241
Conversation
Thanks for adding the Here's a preview of the changelog: This release improves type checking for async resolver functions when used as Now doing this will raise a type error: import strawberry
def some_resolver() -> int:
return 0
@strawberry.type
class User:
# Note the field being typed as str instead of int
name: str = strawberry.field(resolver=some_resolver) Here's the tweet text:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3241 +/- ##
=======================================
Coverage 96.52% 96.53%
=======================================
Files 520 520
Lines 33243 33243
Branches 5527 5527
=======================================
+ Hits 32089 32090 +1
+ Misses 921 920 -1
Partials 233 233 |
CodSpeed Performance ReportMerging #3241 will not alter performanceComparing Summary
|
I am converting this to Draft while I investigate the test failures. I need help from the maintainers to understand these failures. For the record: This change does fix the errors from Pyright (via Pylance in VSCode), but the test failures are from mypy. |
Unfortunately, according to Github, "the logs for this run have expired and are no longer available". This also hides the "re-run jobs" button for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to review pull request #3241 due to the following error:
<class 'KeyError'>: 0
Try re-running the review or contact [email protected] for help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review and merge! Looks great 😊
I've added a test for pyright, just to check the behaviour there 😊 (The error is weird, but at least it errors correctly :D)
Dynamic field creation failed (or may be i doing something wrong). Suppose you have code
And this produce following error
Why I tried to change |
Description
Fixes generic type arguments for Coroutine in RESOLVER_TYPE. The given types are incorrect: It is
Coroutine[YieldType, SendType, ReturnType]
.This allows catching when the return type of an async resolver is incompatible with the field type. For example:
With the change made in this PR, the above code will be caught by typecheckers.
Types of Changes
Issues Fixed or Closed by This PR
strawberry.field
does not type check properly for async resolvers, butstrawberry.field()
does #3071Checklist