-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
result transformer #378
result transformer #378
Conversation
6aab46c
to
0e593db
Compare
0e593db
to
665fd2d
Compare
Prompted by apollographql#376's brittleness; this helps keep common state/configuration around when performing a query. --- Also, as part of this, I noticed there are two seemingly unused functions: `diffQueryAgainstStore`, `diffFragmentAgainstStore`
You can pass `resultTransformer` as an optional callbak to make changes to result objects before they're returned via the query interface.
665fd2d
to
69599ad
Compare
69599ad
to
53bd72a
Compare
Is this a PR you guys would accept, or should I try a different approach? |
Hey sorry, I've been totally swamped with PRs, trying to get through them all as fast as possible. Started out with 17 this morning and down to 12 now... |
I think this could be a good hook to have, so definitely in favor of it. But I'm not sure about the implementation. Why not just transform the whole result blob right before it's returned from |
No rush, mostly just wanted to make sure it's worth maintaining & rebasing :)
Hmm, that I don't have a great answer for. I initially went down that road because I already had the However, it does have the nice property that the callback fires for every returned node. If I got only a single call (right before But, the single callback approach allows for transformations that need to look at more than just a node at a time. I think your approach makes more sense, unless I've inadvertently convinced you otherwise |
Yeah I just like the approach that has the least internal machinery. Just having a callback that runs on every result seems the most sense, and if we have a concrete reason to add something more complicated later we can do it then. |
Gonna close this since the other approach will probably have totally different code! |
Yup, SGTM |
Please note that this PR depends on, and includes #377. For a standalone diff, see convoyinc/apollo-client@store-context...store-result-transformer
This adds a
resultTransformer
callback that can be used to modify the results of a query just before they are handed off to the caller.For example, we're crazy and like to attach a prototype to response objects, as a convenient place to hang read only helpers.