Joe
07/28/2022, 11:12 PMKotlinDataLoaderRegistryFactory
and `GraphQLContext`:
• Our dataloaders sometimes need access to things in the GraphQLContext
, which we've dealt with by setting the GraphQLContext
as the BatchLoaderContextProvider
, and then accessing within a dataloader by doing environment.getContext<GraphQLContext>()
• It seems like in order to do the same thing, we'd need to make the GraphQLContext
accessible to each KotlinDataLoader
that we construct and create the BatchLoaderContextProvider
option when using DataLoaderFactory.newDataLoader()
• That's all doable, but seems a little awkward (leads us down a FactoryFactory / FactoryProvider type route which always seems a little too JEE-ish) -- would it make sense to have a way for the RegistryFactory to handle DataloaderOptions directly instead ? or is there another way to expose the GraphQLContext
to the `KotlinDataLoader`s that I'm missing?Dariusz Kuc
07/29/2022, 2:26 AMSamuel Vazquez
07/29/2022, 2:45 AMGraphQLContext
from the BatchLoaderContext
, the way we do it is slightly different and recommend pass the dataFetchingEnvironment
as a second argument of your DataLoader.load fn
foDataLoader.load(key, dataFetchingEnviroment)
then in your batch loader function you can just
DataLoaderFactory.newDataLoader { keys, environment: BatchLoaderEnvironment ->
val graphQLContext = environment.getGraphQLContext()
}
Samuel Vazquez
07/29/2022, 2:48 AMBatchLoaderEnvironment
contains a context yes, but also contains a context by key (that would be the dataFetchingEnvironment)
https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/BatchLoaderEnvironment.java#L48Samuel Vazquez
07/29/2022, 2:49 AM(batchLoaderEnvironment.keyContextsList.firstOrNull() as? DataFetchingEnvironment)?.graphQLContext
Samuel Vazquez
07/29/2022, 2:50 AMSamuel Vazquez
07/29/2022, 2:51 AM.load()
fnJoe
07/29/2022, 2:31 PMDariusz Kuc
07/29/2022, 2:51 PMJoe
07/29/2022, 4:29 PMSamuel Vazquez
07/29/2022, 5:54 PMah interesting, so you end up with the same keyContext object for every key that gets dataloaded, and just assume the first one? Thanks for that idea, will play with which approach makes more sense for us.yes, at the end is just a reference to an object so should not be expensive, plus it opens the door for the capability to access to a the DataFetchingEnvironment by loaded key