WebClient 로 graphql 서버에 요청보내기 - mutation, variables

728x90

https://cokes.tistory.com/172

 

스프링 WebClient로 graphql 서버에 요청응답받기

org.springframework.boot spring-boot-starter-webflux 3.0.2 com.graphql-java-kickstart graphql-webclient-spring-boot-starter 1.0.0 WebClient 가 webflux에 포함되어 있습니다. WebClient webClient = WebClient .builder() .baseUrl("https://apijosu.com/g

cokes.tistory.com

이전에는 query 문만 넣어서 보내는 요청이었다면, 이번에는 데이터까지 같이 보내는 요청입니다.

GraphQLRequest request = GraphQLRequest.builder().query("query").variables("variables").build()

query 처럼 variables 도 넣을 수 있도록 되어있습니다.  

 

String block = webClient.post().bodyValue(request.getRequestBody()).retrieve().bodyToMono(String.class).block();
System.out.println(block);

body 값을 읽어옵니다.
해당 request 에 바디를 가져와서 post 요청합니다.

반응형