-
-
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
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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3383 +/- ##
==========================================
- Coverage 96.55% 95.36% -1.20%
==========================================
Files 523 498 -25
Lines 33357 31148 -2209
Branches 5521 3809 -1712
==========================================
- Hits 32208 29703 -2505
- Misses 914 1236 +322
+ Partials 235 209 -26 |
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 |
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 😊 |
@patrick91 friendly ping :) |
Hey, I just went through your PR but I'm not fully into the details yet. Couldn't we also solve this with |
@erikwrede not sure what you are proposing as this solution is changing the overload case for when the resolver is passed. Introducing the Resolver type is the core of this design, so removing the need for it would be missing the point here :) |
4bd3bca
to
8802c75
Compare
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