|
| 1 | +package com.baeldung.graphql; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.springframework.context.annotation.Bean; |
| 7 | +import org.springframework.context.annotation.Configuration; |
| 8 | + |
| 9 | +@Configuration |
| 10 | +public class GraphqlConfiguration { |
| 11 | + @Bean |
| 12 | + public PostDao postDao() { |
| 13 | + List<Post> posts = new ArrayList<>(); |
| 14 | + for (int postId = 0; postId < 10; ++postId) { |
| 15 | + for (int authorId = 0; authorId < 10; ++authorId) { |
| 16 | + Post post = new Post(); |
| 17 | + post.setId("Post" + authorId + postId); |
| 18 | + post.setTitle("Post " + authorId + ":" + postId); |
| 19 | + post.setText("Post " + postId + " + by author " + authorId); |
| 20 | + post.setAuthorId("Author" + authorId); |
| 21 | + posts.add(post); |
| 22 | + } |
| 23 | + } |
| 24 | + return new PostDao(posts); |
| 25 | + } |
| 26 | + |
| 27 | + @Bean |
| 28 | + public AuthorDao authorDao() { |
| 29 | + List<Author> authors = new ArrayList<>(); |
| 30 | + for (int authorId = 0; authorId < 10; ++authorId) { |
| 31 | + Author author = new Author(); |
| 32 | + author.setId("Author" + authorId); |
| 33 | + author.setName("Author " + authorId); |
| 34 | + author.setThumbnail("http://example.com/authors/" + authorId); |
| 35 | + authors.add(author); |
| 36 | + } |
| 37 | + return new AuthorDao(authors); |
| 38 | + } |
| 39 | + |
| 40 | + @Bean |
| 41 | + public PostResolver postResolver(AuthorDao authorDao) { |
| 42 | + return new PostResolver(authorDao); |
| 43 | + } |
| 44 | + |
| 45 | + @Bean |
| 46 | + public AuthorResolver authorResolver(PostDao postDao) { |
| 47 | + return new AuthorResolver(postDao); |
| 48 | + } |
| 49 | + |
| 50 | + @Bean |
| 51 | + public Query query(PostDao postDao) { |
| 52 | + return new Query(postDao); |
| 53 | + } |
| 54 | + |
| 55 | + @Bean |
| 56 | + public Mutation mutation(PostDao postDao) { |
| 57 | + return new Mutation(postDao); |
| 58 | + } |
| 59 | +} |
0 commit comments