Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Latest commit

 

History

History
53 lines (32 loc) · 1.42 KB

README.md

File metadata and controls

53 lines (32 loc) · 1.42 KB

Batched GraphQL execution

Note: This is not an open source project. It is not licensed under an open source compatible license at this moment.

This is a custom execution engine for GraphQL Java which is optimized for batching to avoid the N+1 problem.

This is an alternative approach to using batched data loading

It is fully reactive using Reactor.

Overview

The N+1 problem occurs when one Object can lead to N queries per child. For example:

type Query {
    people: [Person]
}
type Person {
    id: ID
    friends: [Person]
}

A query like this {people{friends{name}} needs to load the friends for each person. If we have 5 people and each person has 5 friends we need to load 25 persons overall.

Instead of making 25 calls (to a DB or another service) we would like to make 1 call which loads all 25 people at once.

In order to make this as easy as possible this engine provides a BatchedDataFetcher:

public interface BatchedDataFetcher {
    Mono<BatchedDataFetcherResult> get(BatchedDataFetcherEnvironment environment);
}

A BatchedDataFetcherEnvironment contains the list of fields and sources which should be loaded:

    List<Object> sources;
    List<NormalizedField> normalizedFields;
    List<ExecutionPath> executionPaths;