We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There are several helpers in Vertx 4.1.0 to build GraphQL DataLoader / BatchLoaders.
public class AuthorsDataLoader implements VertxBatchLoader<String, Author> { final AuthorService authorService; @Override public CompletionStage<List<Author>> load(List<String> keys, BatchLoaderEnvironment environment) { return null; } }
But there is no helpers to use Future or Flowable when building a DataLoader.
Future
Flowable
Hope there are some interfaces to use Future or Flowable directly.
public class AuthorsDataLoader implements VertxFavoredBatchLoader<String, Author> { final AuthorService authorService; @Override public Future<List<Author>> load(List<String> keys, BatchLoaderEnvironment environment) { return null; } }
or
public class AuthorsDataLoader implements VertxFavoredBatchLoader<String, Author> { final AuthorService authorService; @Override public Flowable<List<Author>> load(List<String> keys, BatchLoaderEnvironment environment) { return null; } }
The text was updated successfully, but these errors were encountered:
In your example, AuthorsDataLoader implements VertxBatchLoader but it shouldn't.
AuthorsDataLoader
VertxBatchLoader
Vert.x Web GraphQL already has helpers for futurized API.
Consider a GraphQL server that exposes blog posts data. The server can retrieve all blog posts along with their comments.
To avoid sending a query fetching comments for each post, you could create a DataLoader:
DataLoader
DataLoader<Integer, JsonArray> commentDataLoader = DataLoader.newMappedDataLoader( VertxMappedBatchLoader.create((postIds, batchLoaderEnvironment) -> findComments(postIds, batchLoaderEnvironment)) );
The findComments method returns a Future:
findComments
private Future<Map<Integer, JsonArray>> findComments(Set<Integer> postIds, BatchLoaderEnvironment env) { Collector<Row, ?, Map<Integer, JsonArray>> collector = groupingBy( row -> row.getInteger("post_id"), mapping(this::toComment, collectingAndThen(toList(), JsonArray::new)) ); return pgClient.preparedQuery("select * from comments where post_id = any($1)") .collecting(collector) .execute(Tuple.of(postIds.toArray(new Integer[0]))) .map(SqlResult::value); }
You can find the code here.
Concerning the RxJava integration, you may use the RxJavaJdk8Interop libraray as explained in the doc.
RxJavaJdk8Interop
So I think what we could add some documentation about VertxBatchLoader to avoid confusions.
Sorry, something went wrong.
35407fc
GraphQL: added example of VertxBatchLoader to the doc
5b549bc
Closes #1981 Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont
No branches or pull requests
There are several helpers in Vertx 4.1.0 to build GraphQL DataLoader / BatchLoaders.
But there is no helpers to use
Future
orFlowable
when building a DataLoader.Hope there are some interfaces to use
Future
orFlowable
directly.or
The text was updated successfully, but these errors were encountered: