如何使用spqr从查询根节点排除突变?

问题描述 投票:1回答:1

我使用io.leangen.graphql.spqr库版本0.9.6,我需要将Query根节点中的突变排除到文档中。>

我的GraphQLController.kt看起来是这样的:

@RestController
class GraphQLController {

    private var graphQL: GraphQL? = null

    @Autowired
    fun GraphQLController(bookGraph: BookGraph) {
        val schema = GraphQLSchemaGenerator()
                .withResolverBuilders(
                        AnnotatedResolverBuilder(),
                        PublicResolverBuilder("com.example.graphql.spqr"))
                .withOperationsFromSingleton(bookGraph)
                .withValueMapperFactory(JacksonValueMapperFactory())
                .generate()
        graphQL = GraphQL.newGraphQL(schema)
                .build()
    }

    @PostMapping(value = ["/graphql"], consumes = [MediaType.APPLICATION_JSON_UTF8_VALUE], produces = [MediaType.APPLICATION_JSON_UTF8_VALUE])
    @ResponseBody
    fun execute(@RequestBody request: Map<String?, Any?>): ExecutionResult? {
        return graphQL!!.execute(ExecutionInput.newExecutionInput()
                .query(request["query"] as String?)
                .variables(request["variables"] as Map<String, Object>?)
                .operationName(request["operationName"] as String?)
                .build())

和我的BookGraph.kt看起来是这样的:

@Component
class BookGraph {

    @Autowired
    private lateinit var bookService: BookService

    @GraphQLQuery(name = "books")
    fun books() : List<Book> {
        return bookService.findAll()
    }

    @GraphQLMutation(name = "createBook")
    fun createBook(@GraphQLInputField(name = "name") name: String) : Book {
        return bookService.findAll()
    }
}

我该怎么办?

我在StackOverflow和SPQR issues中都搜索了可能的解决方案,但找不到解决方案。

下面的查询根节点示例,我想排除createBook

enter image description here

虽然我希望Mutation根节点保持不变:

enter image description here

我使用io.leangen.graphql.spqr库版本0.9.6,我需要将查询根节点中的突变排除到文档中。我的GraphQLController.kt看起来是这样的:@RestController类GraphQLController ...

kotlin graphql graphql-spqr
1个回答
1
投票

是错误。您正在使用非常

© www.soinside.com 2019 - 2024. All rights reserved.