Closed
Description
Given schema:
type Query {
books: [Book]
}
type Book {
id: ID
name: String
}
and DGS codegen generated client request types, it's possible to do this:
GraphQlClient client = HttpGraphQlClient.create(WebClient.create("http://localhost:8080/graphql"));
BooksGraphQLQuery query = new BooksGraphQLQuery();
String document = new GraphQLQueryRequest(query, new BooksProjectionRoot<>().id().name()).serialize();
List<Book> books = client.document(document)
.retrieve(query.getOperationName())
.toEntityList(Book.class)
.block();
We can simplify this further through a DGS Codegen specific GraphQlClient
wrapper that prepares request document, so it looks more like this:
HttpGraphQlClient httpGraphQlClient =
HttpGraphQlClient.create(WebClient.create("http://localhost:8080/graphql"));
DgsCodegenGraphQlClient client = new DgsCodegenGraphQlClient(httpGraphQlClient);
List<Book> books = client.retrieve(new BooksGraphQLQuery(), new BooksProjectionRoot<>().id().name())
.toEntityList(Book.class)
.block();
This is only meant to sketch the idea, with the exact details of the API to be worked out.