I use io.leangen.graphql.spqr
library version 0.9.6
and I need to exclude mutations from Query
root node into the Doc.
My GraphQLController.kt
looks this way:
@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())
and my BookGraph.kt
looks this way:
@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()
}
}
How can I do it?
I searched for possible solutions both in StackOverflow and SPQR issues but cannot find a solution.
Example of Query root node below, I want to exclude createBook
:
While I want Mutation root node to remain untouched: