-
Notifications
You must be signed in to change notification settings - Fork 433
Documentation on how to use LookAhead*
features.
#234
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
Comments
/cc @weiznich |
I think the released version on crates.io does not contain that feature yet. So to make this work you need to dependent directly on the git version. |
Oh, yes, sorry...I should have read closer. You need to use master/git until a new release (#210). Sadly I can't do a release because I don't have permissions and @theduke and @mhallin haven't been around lately. It would still be good to get some docs on how to actually use it in the book so keeping this open. |
Ah I see, I suspected as much, thanks! Out of curiosity are these the main way people are recommended to tackle the N+1 query problem? I find that even in the most simple case it gets pretty chatty and haven't been able to find much guidance on that in particular. (Well other than using dataloader-rs, which I believe requires async support to work?) |
There are basically 2 ways to solve the N+1 query problem:
The first solution won't work with juniper as implemented currently, because it needs async support, so this leaves currently only the lookahead solution. (Btw: If you are trying to integrate juniper with a relational database checkout wundergraph) |
This discussion may also be of use: |
Yup that's what alerted me to wundergraph's existence 😄. During my first pass through I found it a bit hard to grok, but I haven't set some time aside to really dig into it so I'll do that and report back. |
Writing documentation is a big point of what's left before wundergraph will be released officially. For now the two examples are the only documentation that exists beside the code. |
@weiznich: While it isn't as complete as facebook's GraphQL dataloader, at work we've got a pretty decent to solution to handle batching of nested objects. Our solution to handle nested objects is to wrap our
and then load the data out of the Rc in the Here is a gist with part of the bits you might use https://gist.github.com/kestred/6cac1149b072228bd398e2c60e3c7871. The gist example is fairly unusual, because all of our typical batching has been replaced a |
Would anyone, please, mind to show a basic example of how this works? I am not a Rust begginer, but neither a pro... And I could not get any cue from the wundergraph project :( |
The basic idea is quite simple: @LegNeato I think this could be closed because the documentation was released. |
@weiznich Thanks, but should this |
A simple pseudo code implementation would look like this: struct Query;
#[derive(GraphQLObject)]
struct User {
id: String,
posts: Vec<Post>,
}
impl User {
fn from_lookahead(selection: LookAheadSelection) -> Self {
// do something with the selection here
}
}
#[derive(GraphQLObject)]
struct Post {
id: String,
content: String,
}
graphql_object!(Query: () |&self| {
field user(&executor) -> User {
let lookahead = executor.look_ahead();
User::from_lookahead(lookahead)
}
}); |
@weiznich Thank you very much for the effort. But could you please clarify on this?
So, if I return the users, along with the posts, in the Thank you very much for your time! |
That depends on the exact implementation. In the example above juniper will continue to traverse the graph. In detail because of the derives it will just select the right fields from the response. If |
Thanks @weiznich I'll try to use your wishdom to implement it when I got home. BTW, you said that the documentation was released. Where has this been done? Thank you very much! |
Basically the api documentation here and for all other lookahead related types. |
Circling back around on this; the example in #234 (comment) no longer compiles because |
It's generic over the lifetime and the scalar type, which will be |
- rework and update existing chapters - mention correct case transformation for GraphQL enums (#1029) - document N+1 mitigation techniques and look-ahead features (#234, #444) - mention all integration crates (#867) - fix Book links (#679, #974, #1056) - remove old version of Book (#1168) Additionally: - disable `bson`, `url`, `uuid` and `schema-language` Cargo features by default in `juniper` crate Co-authored-by: Christian Legnitto <[email protected]>
I saw that support for look ahead functionality was added in #136, but I'm a bit confused as to how to use it since it's not at all documented. I see they are exported here, but attempting to use them throws a compiler error:
Any help here would be greatly appreciated, thanks!
The text was updated successfully, but these errors were encountered: