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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is using this kind of cacheKeyFn bad practice? #75
Comments
You definitely need a cacheKeyFn if you're using an object as a key where you want to treat that object as a value rather than a reference. I like the one you made that considers keys being defined in a different order as equivalent, very good. |
@leebyron if we do like this, how can we make use of, say |
@kolpav Is this still the best way to do this? Is there a better (official) way to pass GraphQL args down to dataloader functions? |
@timscott You need to be able to turn your args to value which can be used as an object key ( |
@kolpav Yeah, I ended up adding the args to the key and doing just That's a great point about |
@timscott
Entire object is stringified just top levels keys are ordered but I guess thats what you meant. You could write recursive version of my |
@kolpav Ah, good point. Maybe something like this covers every scenario: https://github.com/puleos/object-hash |
2 similar comments
@kolpav Ah, good point. Maybe something like this covers every scenario: https://github.com/puleos/object-hash |
@kolpav Ah, good point. Maybe something like this covers every scenario: https://github.com/puleos/object-hash |
Hello,
First of all thank you for this cool library my db server is no longer on fire 馃槃
Before I jump to my question I would like to explain in detail problem I am trying to solve. Maybe I am doing it wrong alltogether but you can skip to question at the end if you like.
Explanation
I am using relay style pagination it could be described by these interfaces
And I have a query which returns
posts
based oncount
,after
,orderBy
like so:Everything works perfectly but if you want to resolve value for
hasNextPage
fromIPageInfo
you need to make same request to db as you would foredges
but withcount + 1
and see ifhasNextPage = results.length > count
. Hope that makes sense.I didn't liked that very much. We are making quite expensive query just to know if there are any more results. I solved this by using
postModel.getPosts.load({ after, orderBy, count: count + 1 })
foredges
and just droping last result if there were more thancount
. Now I can make same request as I made foredges
forhasNextPage
it looks completelly samepostModel.getPosts.load({ after, orderBy, count: count + 1 })
so I get cached version, bypassing call to db alltogether! But I need to use this uglycacheKeyFn
This question can be applied to any call to
load
where its argument is an object and not just simpleid
.Is this wrong?
Question
I basically need this:
The text was updated successfully, but these errors were encountered: