<gson.version>2.8.7</gson.version>
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.projectlombok
lombok
${lombok.version}
provided
com.graphql-java-kickstart
graphql-java-tools
${graphql-java-tools.version}
com.google.code.gson
gson
${gson.version}
org.springframework.boot
spring-boot-maven-plugin
初始化GraphQL实例
我们将创建一个GraphQL实例并将其注册到spring容器中,代码如下:
创建一个GraphQLProvider类:
@Component
public class GraphQLProvider {
private GraphQL graphQL;
@Autowired
private IItemService itemService;
@Bean
public GraphQL graphQL() {
return graphQL;
}
@PostConstruct
public void init() throws IOException {
GraphQLSchema graphQLSchema = SchemaParser.newParser()
.file(“graphql/base.graphqls”)
.resolvers(new Query(), new Mutation())
.file(“graphql/item.graphqls”)
.resolvers(new ItemResolver(itemService))
// .file(“book.graphqls”)
//