dev
minuk926 3 years ago
parent 8cb4fe3573
commit 443c77d363

@ -79,8 +79,14 @@ dependencies {
// graphql
implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:12.0.0'
//implementation 'com.graphql-java-kickstart:graphiql-spring-boot-starter:12.0.0'
implementation 'com.graphql-java-kickstart:graphql-java-tools:12.0.1'
// implementation 'com.graphql-java-kickstart:graphiql-spring-boot-starter:12.0.0'
// implementation 'io.projectreactor:reactor-core:3.4.14' // react
//implementation 'com.graphql-java:graphql-spring-boot-starter:5.0.2'
//implementation 'com.graphql-java:graphql-java:17.3'
//implementation 'com.graphql-java:graphql-java-tools:5.2.4'
//implementation 'com.graphql-java:graphiql-spring-boot-starter:5.0.2'
// graphql-like sql usual
implementation 'io.leangen.graphql:graphql-spqr-spring-boot-starter:0.0.6'

@ -1,6 +1,5 @@
package com.xit.biz.cmm.resolver;
//import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import com.xit.biz.cmm.dto.CmmUserDto;
import com.xit.biz.cmm.dto.struct.CmmUserMapstruct;
import com.xit.biz.cmm.entity.CmmUser;

@ -1,6 +1,5 @@
package com.xit.biz.cmm.resolver;
//import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.xit.biz.cmm.dto.CmmUserDto;
import com.xit.biz.cmm.dto.struct.CmmUserMapstruct;
import com.xit.biz.cmm.entity.CmmUser;

@ -1,31 +0,0 @@
package com.xit.biz.sample.graphql;
//import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import com.xit.biz.sample.graphql.dto.PostResponse;
import com.xit.biz.sample.graphql.entity.Post;
import com.xit.biz.sample.graphql.repository.AuthorRepository;
import com.xit.biz.sample.graphql.repository.PostRepository;
import graphql.kickstart.tools.GraphQLMutationResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class MyMutation implements GraphQLMutationResolver {
private final PostRepository postRepository;
private final AuthorRepository authorRepository;
public PostResponse writePost(String title, String text, String category) {
//public Post writePost(String title, String text, String category) {
Post post = new Post();
post.setTitle(title);
post.setText(text);
post.setCategory(category);
//post.setAuthor(authorRepository.getOne(1L));
final Post save = postRepository.save(post);
return PostResponse.from(save);
//return save;
}
}

@ -1,22 +0,0 @@
package com.xit.biz.sample.graphql;
//import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.xit.biz.sample.graphql.dto.PostResponse;
import com.xit.biz.sample.graphql.entity.Post;
import com.xit.biz.sample.graphql.repository.PostRepository;
import graphql.kickstart.tools.GraphQLQueryResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@RequiredArgsConstructor
public class MyQuery implements GraphQLQueryResolver {
private final PostRepository postRepository;
public List<PostResponse> getRecentPosts(int count, int offset) {
final List<Post> all = postRepository.findAll();
return PostResponse.from(all);
}
}

@ -1,19 +0,0 @@
package com.xit.biz.sample.graphql;
//import com.coxautodev.graphql.tools.GraphQLResolver;
import com.xit.biz.sample.graphql.dto.PostResponse;
import com.xit.biz.sample.graphql.entity.Author;
import com.xit.biz.sample.graphql.repository.AuthorRepository;
import graphql.kickstart.tools.GraphQLResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class PostResolver implements GraphQLResolver<PostResponse> {
private final AuthorRepository authorRepository;
public Author getAuthor(PostResponse postResponse) {
return authorRepository.findById(postResponse.getAuthor().getId()).orElseThrow(NullPointerException::new);
}
}

@ -1,36 +0,0 @@
package com.xit.biz.sample.graphql.dto;
import com.xit.biz.sample.graphql.entity.Author;
import com.xit.biz.sample.graphql.entity.Post;
import lombok.*;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PostResponse {
private long id;
private String title;
private String text;
private String category;
private Author author;
public static List<PostResponse> from(Collection<Post> entities) {
return entities.stream().map(PostResponse::from).collect(Collectors.toList());
}
public static PostResponse from(Post entity) {
return PostResponse.builder()
.id(entity.getId())
.title(entity.getTitle())
.text(entity.getText())
.category(entity.getCategory())
//.author(entity.getAuthor())
.build();
}
}

@ -1,22 +0,0 @@
package com.xit.biz.sample.graphql.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@Getter
@Setter
@EqualsAndHashCode(of = "id")
public class Author {
@Id
@GeneratedValue
private Long id;
private String name;
private String thumbnail;
}

@ -1,25 +0,0 @@
package com.xit.biz.sample.graphql.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
@Entity
@Getter
@Setter
@EqualsAndHashCode(of = "id")
public class Post {
@Id
@GeneratedValue
private Long id;
private String title;
private String text;
private String category;
// @ManyToOne(fetch = FetchType.LAZY, optional = false)
// @JoinColumn(name = "author_id")
// private Author author;
}

@ -1,9 +0,0 @@
package com.xit.biz.sample.graphql.repository;
import com.xit.biz.sample.graphql.entity.Author;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AuthorRepository extends JpaRepository<Author, Long> {
}

@ -1,15 +0,0 @@
package com.xit.biz.sample.graphql.repository;
import com.xit.biz.sample.graphql.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
//@Query("SELECT p FROM Post p JOIN FETCH p.author")
@Query("SELECT p FROM Post p")
List<Post> findAll();
}

@ -34,7 +34,7 @@ public class LoggerAspect {
@Value("${api.reponse.logging}")
private boolean isResLogging;
@Pointcut("execution(* com.xit..*Controller.*(..))") // 이런 패턴이 실행될 경우 수행
@Pointcut("execution(* com.xit..*Controller.*(..)) || execution(* graphql(..))") // 이런 패턴이 실행될 경우 수행
public void loggerPointCut() {
}

@ -1,8 +1,3 @@
schema {
query: Query,
mutation: Mutation
}
type CmmUser {
cmmUserId: String
userId: String!
@ -19,8 +14,8 @@ type CmmUser {
}
enum RoleType {
USER
ADMIN
USER,
ADMIN,
GUEST
}

@ -0,0 +1,4 @@
schema {
query: Query,
mutation: Mutation
}
Loading…
Cancel
Save