Open
Description
https://github.com/facebook/dataloader
- Caching resolving the same data
- Instead of normal resolving:
@FieldResolver()
author(@Root() recipe: Recipe) {
return this.userRepository.findById(recipe.authorId);
}
Introduce batched resolving - taking array of roots:
@FieldResolver()
async author(@Root() recipes: Recipe[]) {
const ids = recipes.map(r => r.authorId);
return this.userRepository.findByIds(ids);
}
- Decorator:
@Mutation()
async mutationThatAffectLoader(
@Arg("input") input: SomeInput,
@DataLoader(User) loader,
) {
const result = await this.mutateSomething(input);
loader.clear(input.someKey);
return result;
}