|
|
@@ -0,0 +1,30 @@
|
|
|
+package com.remy.graphql.resolvers.mutation;
|
|
|
+
|
|
|
+import com.remy.common.helper.BeanHelper;
|
|
|
+import com.remy.common.module.CommentDTO;
|
|
|
+import com.remy.common.module.UserDTO;
|
|
|
+import com.remy.graphql.evn.RestAPIEnv;
|
|
|
+import graphql.kickstart.tools.GraphQLMutationResolver;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
+import static java.util.concurrent.CompletableFuture.supplyAsync;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CommentMutation implements GraphQLMutationResolver {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RestAPIEnv apiEnv;
|
|
|
+
|
|
|
+ CompletableFuture<CommentDTO> createComment(CommentDTO commentDTO) {
|
|
|
+ log.info("start create comment: " + BeanHelper.toJSON(commentDTO));
|
|
|
+ return supplyAsync(() ->
|
|
|
+ new RestTemplate().postForObject(apiEnv.getCommentsEndpoint(),
|
|
|
+ commentDTO, CommentDTO.class));
|
|
|
+ }
|
|
|
+}
|