-
Notifications
You must be signed in to change notification settings - Fork 324
Need to have ability to configure dataloader #44
Description
Hi, based on the example here, I've set up the following Spring config in the context of a Spring Boot app levering the present project:
@Configuration
@Slf4j
public class DataLoaderConfig {
@Autowired
private Dao<Author> authorDao;
@Autowired
private Dao<Publisher> publisherDao;
@Autowired
private Dao<Book> bookDao;
@Bean
public Instrumentation instrumentation() {
log.info("Creating GraphQL execution instrumentation");
final AuthorBatchLoader authorBatchLoader = new AuthorBatchLoader(authorDao);
final BookBatchLoader bookBatchLoader = new BookBatchLoader(bookDao);
final PublisherBatchLoader publisherBatchLoader = new PublisherBatchLoader(publisherDao);
final DataLoader<Integer, Author> authorDataLoader = new DataLoader<>(authorBatchLoader);
final DataLoader<Integer, Book> bookDataLoader = new DataLoader<>(bookBatchLoader);
final DataLoader<Integer, Publisher> publisherDataLoader = new DataLoader<>(publisherBatchLoader);
final DataLoaderRegistry registry = new DataLoaderRegistry();
registry.register("authors", authorDataLoader);
registry.register("books", bookDataLoader);
registry.register("publishers", publisherDataLoader);
return new DataLoaderDispatcherInstrumentation(registry);
}
}
And BTW, I'm using the resolver support, as in the following:
@RequiredArgsConstructor
public class AuthorResolver implements GraphQLResolver<Author> {
private final Dao<Author> authors;
public Author author(int id) {
return authors.findById(id);
}
public List<Author> authors(int index, int maxResults) {
return authors.paginate(index, maxResults);
}
}
There seems to be a bit of abstraction involved, and I'm uncertain about how resolvers correspond to data fetchers (I suspecting that my resolvers are invoked by some generic that fetcher wrapping them). So I'm not clear as to how this type of abstraction may play into the data loading I've configured being used or not...
At runtime, I can see the the SimpleGraphQLServlet instance uses the DataLoaderDispatcherInstrumentation created above (added traces that show the servlet holding the instrumentation instance), but the instrumentation is not being used for loading. Not sure how to wire things up in the context of the Spring Boot starter so that Dataloader is used, there's no doc I could find on the topic. It would be very useful to be able to benefit from the Dataloader support when using the Spring Boot starter.
Can you provide steps to move forward? Thanks.