-
Notifications
You must be signed in to change notification settings - Fork 228
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
association_proxy support #267
association_proxy support #267
Conversation
07b20a8
to
3b43bb7
Compare
81c4cb4
to
4f3d44f
Compare
@jnak : any initial thoughts on adding AssociationProxy support? |
Just checked your PR out. It's a feature I could use as well! I know it's been some time, but since checks are passing, I'm going to test this a bit in the upcoming days and give you a review. Confident we can get this merged soon. |
Just saw that I accidentally posted these comments instead of adding them to the review. I'm still busy with that and expect to have everything I have in mind tested by the end of the week! |
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.
It took me longer than expected, but the rest looks fine for basic feature integration. We should add Hybrid Property support before this gets merged.
Thanks for the great work; this is helpful! If you @dpep have the time to implement the additional features, I'd highly appreciate that. Otherwise, I will work on it myself once I find the time.
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #267 +/- ##
==========================================
+ Coverage 96.39% 96.46% +0.06%
==========================================
Files 9 9
Lines 915 933 +18
==========================================
+ Hits 882 900 +18
Misses 33 33
☔ View full report in Codecov by Sentry. |
Quick update: using this in dev, but there seem to be problems regarding batching/dataloader, especially if the association proxy "skips" an intermediate class in a relationship and maps to another relationship with backrefs (A.b->B.c->C => A.c->C). Will need to investigate further once I find the time. I don't want to merge this unless it is clear which problems exist and what existing features this addition is incompatible with. |
Fixed the review comment I've had. The issue with dataloaders should be solved in a follow-up PR. We could easily create a optional custom resolver for the proxies that first calls the dataloader for the specific relationship, so no implicit load takes place upon access. |
Generally like the change as it probably saves a lot of code. One thing we have to be cautious about is that when variables are proxied they might be proxied between nodes. This will eventually conflict with the caching relay and apollo do internally. Imagine the following classes: class A:
id = str()
b = relationship(B)
proxied_c = association_proxy(B.c)
class B:
id = str()
c = str() If we now run the mutation:
the cache for B is update to contain the new value of c but the cache for a, which might have been queried before wouldn’t be updated. We just have to make sure to document this possible conflict, as it probably goes a bit against the patter of just having on root per property. What do you think? 🙂 |
Good idea to mention that in the docs, probably best to scope that to an additional PR. It's more of a frontend task to take care of caching, but we cannot expect all of our users to know all about the best practices and patterns in GQL upfront. Let's address this after the release of 3.0 @jendrikjoe 👍 |
Sounds reasonable 👍 The rest of the code is fine by me 👍 |
I now find |
@conao3 It's on my list to get it done for this month. If you have time to test it, I'd really appreciate a review! |
This patch is already cherrypicked own fork and it's ready to ship :) |
@conao3 how would you addrss the |
I want to use this patch now, I haven't investigated it. The issue I face is, the |
@conao3 I just checked, and I can't reproduce that behavior. For me, association proxies are always |
OK, thanks for letting me know! |
support for sqlalchemy AssociationProxy properties (https://docs.sqlalchemy.org/en/13/orm/extensions/associationproxy.html)
Fixes #136