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
Add Resolver type, use it as a return type for field and fix tests #3383
base: main
Are you sure you want to change the base?
Add Resolver type, use it as a return type for field and fix tests #3383
Conversation
Hi, thanks for contributing to Strawberry 🍓! We noticed that this PR is missing a So as soon as this PR is merged, a release will be made 🚀. Here's an example of Release type: patch
Description of the changes, ideally with some examples, if adding a new feature. Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :) Here's the tweet text:
|
bc31bc6
to
1560cd3
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3383 +/- ##
==========================================
- Coverage 96.41% 95.36% -1.06%
==========================================
Files 498 498
Lines 31133 31148 +15
Branches 3814 3809 -5
==========================================
- Hits 30016 29703 -313
- Misses 911 1236 +325
- Partials 206 209 +3 |
couldn't we use Callable instead of Resolver? 😊 |
I will fill up the documentation and release notes as soon as someone tells me there is a chance for merging this PR in :) Also my approach to writing the |
CodSpeed Performance ReportMerging #3383 will not alter performanceComparing Summary
|
Hmm, yes now that you say that we probably could do it, although it would be a bit of pain. Note that
So you would have to write the whole thing every time:
which is IMO a mouthfull and not necessary correct - people could try and call this function, but without proper typing they wouldn't get the arguments right. |
Oh, I see that you are using libcst for codemoding backward incompatible changes. I was about to write one for myself, but I can add it here in this PR. Stay tuned! :) |
Codemod added as promised |
5cd56fd
to
42c21a7
Compare
42c21a7
to
4bd3bca
Compare
One thing that I've noticed when using this new type on my codebase was that if you have an interface it might get difficult to get the types right. Consider this code:
With the new
because the child class
So for future reference if you stumble on this problem while changing your codebase my suggestion would be to write something like this:
|
@patrick91 any chance this is going to be merged or closed without merging? |
@lukaspiatkowski not sure, sorry I didn't have time to take a proper look at this, I have set some time to look at PRs today, hopefully I get to this one |
Just friendly pinging @patrick91 here :) |
@lukaspiatkowski sorry, still haven't had the time to properly think about this, I'll add it to my things for next week 😊 |
Description
Change one of the overrides of
strawberry.field
to return-> Resolver[T]
ifresolver = ...
is provided. This forces you to annotate your fields asfield: Resolver[int] = ...
and sinceResolver
is an abstract final class you cannot create an instance of it. This will prevent you from mistakenly writing or reading that field.Types of Changes
Issues Fixed or Closed by This PR
... = field(resolver=...)
are treated like regular dataclass attributes by type checkers #3377Checklist