【发布时间】:2022-02-11 21:26:44
【问题描述】:
在带有 GraphQL 的 SpringBoot 中使用突变时,出现错误No Root resolvers for query type 'Query' found。查询工作正常,但在添加 GraphQLMutationResolver 时,它在 Spring Boot 启动时出现错误。
请多多指教。
.graphqls 文件
type Query {
allBooks: [Book]
getBookByIsn(isn: Int): Book
allPublishers: [Publisher]
}
type Book {
isn: Int
title: String
author: String
publishedDate: String
publisher: Publisher!
}
type Publisher {
pId : Int
publisherName: String
address: String
}
input CreatePublisher {
pId : Int
publisherName: String
address: String
}
type Mutation {
addPublisher(input: CreatePublisher!): Publisher
}
变异解析器
@Component
public class PublisherMutation implements GraphQLMutationResolver{
@Autowired
private PublisherRepository publisherRepository;
@Transactional
public Publisher addPublisher(CreatePublisher createPublisher ) {
Publisher publisher = new Publisher(createPublisher.getPId(), createPublisher.getPublisherName(), createPublisher.getAddress());
publisherRepository.save(publisher);
return publisher;
}
}
【问题讨论】:
标签: spring-boot graphql mutation