Add Java DSL for GraphQL (#3934)

* Add Java DSL for GraphQL

* GraphQl.outboundChannelAdapter() -> outboundGateway()

* * Add `private` ctor to `GraphQl`

* * Just `GraphQl.gateway()` - there is not going to be any other components
to handle GraphQL operations.
Also, the `outbound` in the name might confuse, where we, essentially, query a GraphQL data

* Fix typo in the doc

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
Artem Bilan
2022-11-02 10:19:58 -04:00
committed by GitHub
parent a4ac531c4a
commit e3e55c3a85
5 changed files with 174 additions and 36 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.MessageChannels;
import org.springframework.integration.graphql.dsl.GraphQl;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.PollableChannel;
@@ -121,8 +122,8 @@ public class GraphQlMessageHandlerTests {
Locale locale = Locale.getDefault();
this.graphQlMessageHandler.setLocale(locale);
Mono<ExecutionGraphQlResponse> resultMono =
(Mono<ExecutionGraphQlResponse>) this.graphQlMessageHandler.handleRequestMessage(new GenericMessage<>(fakeQuery));
var resultMono = (Mono<ExecutionGraphQlResponse>) this.graphQlMessageHandler.handleRequestMessage(
new GenericMessage<>(fakeQuery));
StepVerifier.create(resultMono)
.consumeNextWith(result -> {
assertThat(result).isInstanceOf(ExecutionGraphQlResponse.class);
@@ -243,18 +244,9 @@ public class GraphQlMessageHandlerTests {
@SubscriptionMapping
public Flux<QueryResult> results() {
return Flux.just(
new QueryResult("test-data-01"),
new QueryResult("test-data-02"),
new QueryResult("test-data-03"),
new QueryResult("test-data-04"),
new QueryResult("test-data-05"),
new QueryResult("test-data-06"),
new QueryResult("test-data-07"),
new QueryResult("test-data-08"),
new QueryResult("test-data-09"),
new QueryResult("test-data-10")
);
return Flux.range(1, 10)
.map(d -> String.format("test-data-%02d", d))
.map(QueryResult::new);
}
}
@@ -280,14 +272,9 @@ public class GraphQlMessageHandlerTests {
static class TestConfig {
@Bean
GraphQlMessageHandler handler(ExecutionGraphQlService graphQlService) {
return new GraphQlMessageHandler(graphQlService);
}
@Bean
IntegrationFlow graphqlQueryMessageHandlerFlow(GraphQlMessageHandler handler) {
IntegrationFlow graphqlQueryMessageHandlerFlow(ExecutionGraphQlService graphQlService) {
return IntegrationFlow.from(MessageChannels.flux("inputChannel"))
.handle(handler)
.handle(GraphQl.gateway(graphQlService))
.channel(c -> c.flux("resultChannel"))
.get();
}