Skip to content
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 pass argument to load method #26

Closed
fbucek opened this issue Nov 10, 2020 · 2 comments
Closed

how to pass argument to load method #26

fbucek opened this issue Nov 10, 2020 · 2 comments

Comments

@fbucek
Copy link

fbucek commented Nov 10, 2020

I am using async_graphql and dataloader and it works fine.

But when I want to limit output using last argument. I do not know how to do this with dataloader.

authors {
 name
 books(last: 30)
}

Getting books is called like this in graphql object ( without data loader )

pub async fn books(
    &self,
    ctx: &Context<'_>,
    last: i32,
) -> Result<Vec<Books>, AppError> {
    ctx.data_unchecked::<BooksRepository>()
        .get_for_id(self.id, last)
        .await
}

When using dataloader I do not know how to make it work.

pub async fn books(
    &self,
    ctx: &Context<'_>,
    last: i32,
) -> Result<Vec<books>, AppError> {
    let loader = ctx.data_unchecked::<BooksLoader>();
    loader.load(self.id).await
}

Maybe I just overlooked something or just do not have mu day, but I do not know how to solve it. Thanks for suggestion.

@cksac
Copy link
Owner

cksac commented Nov 11, 2020

You can implement with other key type, e.g BatchFn<(usize, usize)>, but in this case (1, 20) and (1, 30) is treat as two different request.

@fbucek
Copy link
Author

fbucek commented Nov 11, 2020

Thanks for suggestion, I have tried Arc<Mutex<Config>> mutex, so I can set variables for method in struct which implements BatchFn, but then I have realized that I do not know how to do SQL query to return for X items last X attributes.

For example for last 10 authors get last 10 books. Now it is 11 queries, but I do not know how to make it in 2 queries in SQL regardless of dataloader.

I am closing, thanks for advice. I will try it when I solve SQL problem.

@fbucek fbucek closed this as completed Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants