Sfoglia il codice sorgente

add uncommit files

remy.liu 4 anni fa
parent
commit
280c1cf6b8

+ 30 - 0
graphql-api/src/main/java/com/remy/graphql/resolvers/mutation/CommentMutation.java

@@ -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));
+    }
+}

+ 0 - 1
graphql-api/src/main/resources/application.yml

@@ -7,7 +7,6 @@ graphql:
   extended-scalars: BigDecimal, DateTime, Date
   servlet:
     exception-handlers-enabled: true
-#    async-timeout: 500
   graphiql:
     enabled: true
   playground:

+ 2 - 0
graphql-api/src/main/resources/graphqls/mutation.graphqls

@@ -5,4 +5,6 @@ type Mutation{
     createOrder(input:OrderInput): Order!
     # 新增用户
     createUser(input:UserInput): User!
+    # 新增评论
+    createComment(input:CommentInput): Comment!
 }

+ 10 - 0
graphql-api/src/main/resources/graphqls/order.graphqls

@@ -26,10 +26,15 @@ type Order {
 }
 
 type Comment{
+    # 评论ID
     id: ID
+    # 订单号
     orderNo: String!
+    # 用户ID
     userID:ID!
+    # 商品编码
     goodsSerialNo:String!
+    # 评论内容
     content:String!
 }
 
@@ -38,4 +43,9 @@ input OrderInput{
     goodsSerialNo: String!
     # 用户ID
     userID: ID!
+}
+
+input CommentInput{
+    orderNo: String!
+    content: String!
 }

+ 1 - 1
order-service/src/main/resources/application.yml

@@ -7,7 +7,7 @@ spring:
     username: graphql
     password: graphql
   jpa:
-    generate-ddl: true
+#    generate-ddl: true
     show-sql: true
 #    properties:
 #      hibernate:

+ 0 - 5
pom.xml

@@ -111,11 +111,6 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
-            <dependency>
-                <groupId>com.graphql-java</groupId>
-                <artifactId>graphql-java-extended-scalars</artifactId>
-                <version>16.0.0</version>
-            </dependency>
             <dependency>
                 <groupId>org.apache.commons</groupId>
                 <artifactId>commons-lang3</artifactId>

+ 2 - 2
user-service/src/main/resources/application.yml

@@ -7,8 +7,8 @@ spring:
     username: graphql
     password: graphql
   jpa:
-    generate-ddl: true
-#    show-sql: true
+#    generate-ddl: true
+    show-sql: true
 #    properties:
 #      hibernate:
 #        format_sql: true