-
Notifications
You must be signed in to change notification settings - Fork 1
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
How to use with dataloader? #8
Comments
Can you give a bit more context? |
In this case when get friends ‘ResolveFriends’ will execute 3 times,if it load from database is not good for performance。 |
Ah now I get it. Tough for the library you provided as example you'll need the request's |
I've added a |
Thanks for your reply! The problem is the
Here is a demo https://github.com/ichaly/yarql-example |
I've filled a bit around with your example and now I get the idea of the library. I'm not yet sure what I'm going to do with this but I'm thinking of a few things: func (Schema) PreResolveUser(ctx *yarql.Ctx, args struct{Id int}) {
dataLoader.Load("User", args.Id, ctx.GetContext())
}
func (Schema) ResolveUser(ctx *yarql.Ctx, struct{Id int}) User {
// This one is called after all PreResolve.. methods are executed
return dataLoader.Get("User", args.Id, ctx.GetContext())
} 2. Make it possible for a func (Schema) ResolveUser(ctx *yarql.Ctx, args struct{Id int}) func() User {
dataLoader.Load("User", args.Id, ctx.GetContext())
return func() {
// This one is called after all of the above are executed
return dataLoader.Get("User", args.Id, ctx.GetContext())
}
} 3. Have some sort of method to identify in the args of a query to preload data type UserID int
func (id UserID) Preload(ctx *yarql.Ctx) {
// This method will be called whenever you use the UserID type as arg
dataLoader.Load("User", args.Id, ctx.GetContext())
}
type ResolveUserArgs struct {
Id UserID
}
func (Schema) ResolveUser(ctx *yarql.Ctx, args ResolveUserArgs) func() User {
return dataLoader.Get("User", args.Id, ctx.GetContext())
} Have our own data loader inside this library as the data loader you provided as example is not build for performance (this is not really a solution as this one still needs one of the above to work) |
support plan 2, simple and understandable,no extra concept |
Can use dataloader to avoid N+1?
The text was updated successfully, but these errors were encountered: