-
Notifications
You must be signed in to change notification settings - Fork 517
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
[REQUEST]: How to pass auth headers to dataloader #316
Comments
This should be as simple as "build what you need". Dataloader will call your function and pass an array of IDs. You then make the API call to get those IDs, passing the correct header from wherever it lives. Does that help? If not, could you provide a code example and explain what you expect it to do, vs what it's doing instead? |
@thekevinbrown consider below list of keys
|
There's not going to be a way to make it one call if you have to provide different auth tokens to get different users. You should be able to still batch it up per auth token though. Two options I can see:
(Pseudocode off the top of my head, not tested, but you should get the idea.) const dataloaderMap = new Map<string, DataLoader>();
const loaderFunctionFor = (authToken: string) => (keys: readonly string[]) => {
// Load in here using authToken and keys as you like
}
const dataloaderForAuthToken = (authToken: string) => {
if (!dataloaderMap.has(authToken)) {
dataloaderMap.set(authToken, new Dataloader(loaderFunctionFor(authToken)));
}
return dataloaderMap.get(authToken);
}
async function yourResolver() {
// Inside the resolver you're getting user_id and auth from somewhere already
const user_id, auth;
const user = await dataloaderForAuthToken(auth).load(user_id);
} This approach would allow you to apply the batching options and such. Does that help? |
@thekevinbrown thanks for your response..I will try this approach |
What problem are you trying to solve?
I have one API which takes an array of id's and returns the array of records. This API endpoint accepts auth headers for user authentication. Now the issue is while using data loader I am getting multiple auth headers from different resolvers. So how to authenticate these multiple auth tokens, as in the end data loader will pass only one auth token to the API end point.
The text was updated successfully, but these errors were encountered: