Closed
Description
calling getKeyContexts
on BatchLoaderEnvironment
returns a list of nulls. I think this is caused by Spring's BatchMappingDataFetcher
not propagating the local context. Specifically line 606:
static class BatchMappingDataFetcher implements DataFetcher<Object>, SelfDescribingDataFetcher<Object> {
private final DataFetcherMappingInfo mappingInfo;
private final ResolvableType returnType;
private final String dataLoaderKey;
BatchMappingDataFetcher(DataFetcherMappingInfo info, ResolvableType valueType, String dataLoaderKey) {
this.mappingInfo = info;
this.returnType = ResolvableType.forClassWithGenerics(CompletableFuture.class, valueType);
this.dataLoaderKey = dataLoaderKey;
}
@Override
public String getDescription() {
return "@BatchMapping " + this.mappingInfo.getHandlerMethod().getShortLogMessage();
}
@Override
public ResolvableType getReturnType() {
return this.returnType;
}
@Override
public Object get(DataFetchingEnvironment env) {
DataLoader<?, ?> dataLoader = env.getDataLoaderRegistry().getDataLoader(this.dataLoaderKey);
Assert.state(dataLoader != null, "No DataLoader for key '" + this.dataLoaderKey + "'");
return dataLoader.load(env.getSource()); <-- HERE
}
@Override
public String toString() {
return getDescription();
}
}
Changing it to: return dataLoader.load(env.getSource(), env.getLocalContext())
might fix the issue.(I think)