Skip to content

Support SchemaMapping method to batch load related entities #130

Closed
@rstoyanchev

Description

@rstoyanchev

Now that the batch loading has explicit support in Spring GraphQL with #63 , we may be able to further simplify by hiding the use of a DataLoader for vanilla use cases.

For example the following:

@Controller
public class BookController {

	public BookController(BatchLoaderRegistry registry) {
		registry.forTypePair(Long.class, Author.class).registerBatchLoader((authorIds, env) -> {
			// load authors
		});
	}

	@SchemaMapping
	public CompletableFuture<Author> author(Book book, DataLoader<Long, Author> loader) {
		return loader.load(book.getAuthorId());
	}

}

would be replaced with:

@SchemaMapping
public List<Author> author(List<Book> books) {
	// ...
}

Internally, we would register a Book to Author batch loading function and bind a DataFetcher for type="Book" and field="author" that looks up the DataLoader<Book, Author> and uses it to load the author for its Book parent.

This would be a shortcut essentially, and completely optional. Applications can still use the longer, more explicit form above.

Metadata

Metadata

Assignees

Labels

in: coreIssues related to config and core supporttype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions