-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
Allow using a static method as a resolver #1430
Allow using a static method as a resolver #1430
Conversation
Thanks for adding the Here's a preview of the changelog: This release fixes an issue that prevented using import strawberry
@strawberry.type
class Query:
@strawberry.field
@staticmethod
def static_text() -> str:
return "Strawberry"
@strawberry.field
@classmethod
def class_name(cls) -> str:
return cls.__name__ Here's the preview release card for twitter: Here's the tweet text:
|
35e28da
to
4840efa
Compare
4840efa
to
c3c681c
Compare
Codecov Report
@@ Coverage Diff @@
## main #1430 +/- ##
==========================================
- Coverage 98.08% 98.08% -0.01%
==========================================
Files 119 121 +2
Lines 4129 4228 +99
Branches 599 710 +111
==========================================
+ Hits 4050 4147 +97
Misses 42 42
- Partials 37 39 +2 |
I have a more robust fix for this that also supports |
After much deep-diving into (and frustration with!) the underlying mechanics of This should be ready for review @patrick91. Let me know if I should add any more comments/documentation anywhere. |
Co-authored-by: Patrick Arminio <[email protected]>
Thanks for contributing to Strawberry! 🎉 You've been invited to join You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67 And don't forget to join our discord server: https://strawberry.rocks/discord 🔥 |
Description
In a project I had to define a resolver that gets some data from the root argument.
It was not possible to use
self
because of some mypy warnings. Therefore, I wanted to remove theself
argument.It was possible to remove it without using
@staticmethod
, but mypy complained thatSelf argument missing for a non-static method (or an invalid type for self)
.So, I had to add
@staticmethod
.I tried adding it before
@strawberry.field
, but Python did not add the field to__dataclass_fields__
and a type was not created correctly.Then, I tried adding it after
@strawberry.field
, but Strawberry did not like that becauseAttributeError: 'staticmethod' object has no attribute '__annotations__'
. The changes fix this problem.Types of Changes
Checklist