-
Just posted a question on StackOverflow about the ability to call GraphQL from Java in a Spring Boot + GraphQL Java Tools' context. All details are explained: https://stackoverflow.com/questions/58188938/how-to-execute-java-calls-to-graphql-in-a-spring-boot-graphql-java-tools-cont Thanks if someone has an answer. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I finally found how to do this, browsing through the code of different classes in the |
Beta Was this translation helpful? Give feedback.
-
Edit: Nvm, it seems like you just want to create Rest API specific request/response and not use graphql api specific/request response. Then that's the only way to go. I was under the assumption than you just require rest endpoints, but will still still send graphql requests and expect graphql response. Actually the better cleaner way to implement this would be as follows. This rest api will automatically route all requests to the graphql endpoint and the response will be received by your client without any intervention as is. You can call this rest-api endpoint just as you would call the normal graphql context What you are doing in that StackOverflow answer is not needed. /**
* This controller can be enabled by setting property com.yourcompany.mock.enabled.
*/
@RestController
@RequestMapping("${com.yourcompany.mock.endpoint}")
@ConditionalOnProperty(value = "com.yourcompany.mock.endpoint.enabled", havingValue = "true", matchIfMissing = true)
public class GraphQLEndpointController {
// if property is not set the default mapping will be /graphql
@Value("${graphql.servlet.mapping:/graphql}")
private String graphqlServletMapping;
@RequestMapping(method = RequestMethod.POST)
public void processRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
httpServletRequest.getRequestDispatcher(graphqlServletMapping).forward(httpServletRequest, httpServletResponse);
}
} |
Beta Was this translation helpful? Give feedback.
-
You got it! ;) |
Beta Was this translation helpful? Give feedback.
I finally found how to do this, browsing through the code of different classes in the
graphql-spring-boot-autoconfigure
but I wonder if this could be documented...?https://stackoverflow.com/a/58299150/666414