-
Notifications
You must be signed in to change notification settings - Fork 99
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 bug with prefetching on different nesting levels #702
Conversation
Thanks for this @sudevva. I'll review soon. Anyone else that's using prefetch, a review would be appreciated. |
@sudevva can I get a little more explanation on this PR? I'm having a hard time understanding why a boolean value is a good idea, and what |
👋 So about returnRequested. Basically previous when prefetch is used, the function with Prefetch annotation receives an array of resolved values, that should be mapped to source(like $prefetchResult[$blog->getId()]).
About bool value for annotation, maybe it will be better to create another type of annotation and mark prevous one as depricated. Previous implementation where method recieves an array of values creates some confusion for me, why I recieve an array from which I should extract my value. Thank you @oojacoboo, I hope this will clarify my intentions) |
Okay, so am I right in assuming that you added this boolean property as a way of achieving BC? Can we just merge the functionality without adding any additional properties to the |
Do you think I should leave a prefetch behavior as it was previously?
Btw, I can wrap \TheCodingMachine\GraphQLite\QueryField::__construct $callResolver in deferred as I have done for args until return type is resolved to call assertReturnType with proper value, then I will not use Prefetch anymore. |
Allow Promise to be returned from prefetchMethod with returnRequested: true
b20f9a6
to
ffbb68b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #702 +/- ##
============================================
- Coverage 95.72% 95.18% -0.55%
- Complexity 1773 1824 +51
============================================
Files 154 174 +20
Lines 4586 4796 +210
============================================
+ Hits 4390 4565 +175
- Misses 196 231 +35 ☔ View full report in Codecov by Sentry. |
On ffbb68b, why is this being called The overall goal would be to create a more uniform implementation for resolving. Promises seem like a good idea to me for preload functionality. Wrapping non promise prefetch returns seems like a logical way of implementing things. Please be sure to put line spaces between your control structures - easier for people to read. We're not worried about trying to optimize file sizes. |
hey, I renamed a method, added a forgotten nesting levels test, and added some line spaces. Is this PR more or less ok? |
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.
This is much better now. Just a couple remaining things. We also need updated docs to include details on using promises.
}); | ||
} | ||
|
||
/** @param array<string, mixed> $args */ | ||
private function computePrefetch(array $args, mixed $context, ResolveInfo $info, PrefetchBuffer $prefetchBuffer): mixed | ||
private function computePrefetch(array $args, mixed $context, ResolveInfo $info, PrefetchBuffer $prefetchBuffer): void |
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.
If this is storing the results, maybe "compute" isn't the right term to use for this method name. Also "compute" isn't really a great term to be using here.
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.
This method was not named by me)
Should I rename it?
doPrefetch | prefetchValues | prefetchResults | processPrefetch | ... ?
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.
Renaming a method where the logic contained within it has materially changed, is the right move. Otherwise, reading and understanding the code for the next developer becomes more confusing.
Being that it's return type is void, it's not really "prefetching results" - you'd expect a return value on that IMO. processPrefetch
, cachePrefetchResults
, bufferPrefetch
; maybe something along these lines.
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.
Renamed method name to processPrefetch pushed to branch
If you want I can squash and rebase commits. There is no value in commits about CR fixes and reverting my initial changes. |
No that's fine. We do need the docs updated though, with details on using promises. That's the |
Promise mapping added |
Thanks @sudevva! |
Fix the bug with prefetching on different nesting levels
As a side effect, it's now allowed a Promise to be returned from prefetchMethod with returnRequested: true, so Overblog Dataloader can be used.
Also, there's no need to map a prefetched result to return a value.
update version of related PR #519
also can potentially help with #187