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

Allow providing custom default value for missing key in MappedBatchLoader result #1403

Closed
vojtapol opened this issue Jan 24, 2019 · 2 comments

Comments

@vojtapol
Copy link

MappedBatchLoader is a great addition to the data loading architecture. Sadly, we can't use it in many cases. Frequently we data load lists like so:

type Parent {
  id: String!
  children: [Child!]!  # lazy-loaded via data loader, can not be null
}

When data loading children the return type of the mapped batch loading function is Map<String, List<Child>>. When a key is not present in the map, DataLoaderHelper::invokeMapBatchLoader substitutes null. However, in this case outlined above it should instead substitute an empty list.

I propose adding an additional data loader option that would let us set this default value to an arbitrary value. Another solution that might suffice would be the helper first testing whether the loadResult is a Collection and if so, substituting an empty collection by default.

@vojtapol vojtapol changed the title Allow providing default value for missing key in MappedBatchLoader result Allow providing custom default value for missing key in MappedBatchLoader result Jan 24, 2019
@bbakerman
Copy link
Member

Its your batch loading code that is returning the map given the set of keys

public interface MappedBatchLoader<K, V> {
     CompletionStage<Map<K, V>> load(Set<K> keys);
 }

So if you want empty list values - then put them in in that loader

The problem with a default value is that DataLoaderOptions has not concept of the type V that dataloader returns. I mean we could cast it I guess.

Also this issue would be better over in the https://github.com/graphql-java/java-dataloader/issues project

I made graphql-java/java-dataloader#40 for this

@bbakerman
Copy link
Member

I am going to close this issue here and follow up in the dataloader project

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