【问题标题】:SpringBoot GraphQL mutation giving error No Root resolvers for query type 'Query' foundSpringBoot GraphQL 突变给出错误 No Root resolvers for query type 'Query' found
【发布时间】: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


    【解决方案1】:

    完成,通过为 Create 添加 Mutation 类型的 newTypeWiring 解决

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    相关资源
    最近更新 更多