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

@@ -44,19 +44,18 @@ See documentation for the `ExecutionGraphQlResponse` how to process the GraphQL
[source, java]
----
@Bean
GraphQlMessageHandler handler(ExecutionGraphQlService graphQlService) {
GraphQlMessageHandler graphQlMessageHandler = new GraphQlMessageHandler(graphQlService);
graphQlMessageHandler.setOperation("""
query HeroNameAndFriends($episode: Episode) {
hero(episode: $episode) {
name
friends {
name
}
}
}""");
graphQlMessageHandler.setVariablesExpression(new SpelExpressionParser().parseExpression("{episode:'JEDI'}"));
return graphQlMessageHandler;
GraphQlMessageHandlerSpec graphQlMessageHandlerSpec(ExecutionGraphQlService graphQlService) {
return GraphQl.gateway(graphQlService)
.operation("""
query HeroNameAndFriends($episode: Episode) {
hero(episode: $episode) {
name
friends {
name
}
}
}""")
.variablesExpression("{episode:'JEDI'}");
}
@Bean
@@ -102,4 +101,4 @@ public SubscriptionPublisher obtainSubscriptionResult(RequestOutput output) {
====
Such an outbound gateway can be used not only for GraphQL request via HTTP, but from any upstream endpoint which produces or carries a GraphQL operation or its arguments in the message.
The result of the `GraphQlMessageHandler` handling can be produces as a reply to the upstream request or sent downstream for further processing in the integration flow.
The result of the `GraphQlMessageHandler` handling can be produced as a reply to the upstream request or sent downstream for further processing in the integration flow.