[英]Newrelic : GraphQL Query resolvers as separate Web transactions
[英]SpringBoot GraphQL mutation giving error No Root resolvers for query type 'Query' found
在帶有 GraphQL 的 SpringBoot 中使用突變時,我收到錯誤No Root resolvers for query type 'Query' found 。查詢工作正常,但在添加 GraphQLMutationResolver 時,它在 Spring 引導啟動時給出錯誤。
好心提醒。
.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;
}
}
完成,通過為 Create 添加 Mutation 類型的newTypeWiring
來解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.