Skip to content

Question: Field selection and error handling in a batch loader? #53

@timrourke

Description

@timrourke

I have two unrelated questions:

1. Error handling

Neither org.dataloader.BatchLoader::load nor org.dataloader.BatchLoaderWithContext::load allow one to throw an exception while attempting to fetch some data from some source, because the interface does not declare that an exception is thrown:

    CompletionStage<List<V>> load(List<K> keys);

What is the correct way to handle an error, when, for example, my repository blows up while trying to load a list of entities by the provided keys? Similarly, what if some external HTTP request to fetch a list of entities fails in an unrecoverable way? It seems wrong in these cases to return an empty list; I would prefer to throw an exception and cause the entire GraphQL call stack to unwind instead of returning partial data.

2. Field selection

The BatchLoaderEnvironment passed to a BatchLoaderWithContext::load call does not allow me to inspect the request for the selected fields that caused loading of some entities to occur. Is there a way to do this? I prefer to select only the columns absolutely necessary from the database/API/etc. to optimize performance.

I can imagine that it may be difficult to traverse all nodes on the query to aggregate the minimum acceptable selection of fields from a given type, but it doesn't seem impossible. What I'm hoping is possible is something like this:

Given a query like this:

query {
  foo {
    bar {
      fieldA
      fieldB
      fieldC
    }
  }
  bar {
    fieldA
    fieldD
  }
}

...that I can be able to then only select fields A, B, C, and D, instead of a SELECT * (assuming a relational database is the backing store).

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions