https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
m

Mitchell Syer

03/10/2024, 11:04 PM
With DataLoaders, is there a way to limit the fetched data based on a outside value like a user id?
d

Dariusz Kuc

03/11/2024, 3:26 PM
hello 👋 can you elaborate what you are trying to do?
i.e. data loaders are just a fancy name for a batching strategy across different resolvers
the example from the graphql.org is fetching friends of friends
that being said -> dataloaders do take arguments (e.g. user ids)
m

Mitchell Syer

03/11/2024, 3:35 PM
This is what I am trying to do https://github.com/Suwayomi/Suwayomi-Server/pull/623/files#diff-25a0ffe5ac2c4acb0b77f1ea02942ca05a5170a5fd10562d61298e601d52c6b3 Basically I want to be able to join userdata to an existing relational dataloader thats already taking arguments. I don't think my approach here is correct, as I think userdata may get sent to the wrong person since I only take userid from 1 request
d

Dariusz Kuc

03/11/2024, 3:38 PM
well that is a very large PR so you got to be more specific in what you are trying to do
m

Mitchell Syer

03/11/2024, 3:43 PM
The link I sent goes to a specific file, I'll try to explain it. Basically I grab the userid from the dataloader env, but I am grabbing the userId from the first request. I think dataloaders can have multiple different requests in one batch, which would cause my code to send user data to the wrong user. There isn't a simple way to group specific dataloaders to something like a key from what I can see, which would let me use the userid as a key
d

Dariusz Kuc

03/11/2024, 3:51 PM
if you need two different ids to fetch data I believe your data loader should be accepting both of them as input? unsure what you are trying to fetch from env
unsure how you calculate the user -> if it is associated to a request then it should be same user for all the dataloader calls
dataloaders are created per request (or at least should be)
m

Mitchell Syer

03/11/2024, 3:56 PM
UserId is attached to the request GraphQLContext based on a jwt. We pass the chapter Ids we are fetching, not the user ids. We get the chapter userdata along with the chapter. I was under the impression that dataloaders could be the same if the requests happen basically at the same time, does that mean that even if 2 requests of the same type happen, that it will still create 2 different dataloaders? I couldn't find any info on this, it would solve my issue
d

Dariusz Kuc

03/11/2024, 3:58 PM
dataloaders are created per request so if you receive 2 requests then each request will have their own data loader* *assuming your server library does it, we do it for Spring + Ktor, if you use another server -> check that server implementation
m

Mitchell Syer

03/11/2024, 4:00 PM
Great, I and another guy wrote the implementation we use since we use Javalin. It should be the same. Thanks for the help 👍