KGraphQL
KGraphQL copied to clipboard
enable building graphql schema using KFunction method references
Many times a project already has Services with methods. These methods can have many arguments and it is tedious to expose them with the lambda style that is currently supported.
These changes allow using KFunction method references which include all argument information and reduce boilerplate.
For example:
val mlService = MovieLensService(MovieRepository, GenresRepository, OccupationRepository, RatingRepository, UserRepository)
val schema = KGraphQL.schema{
query("allUsers"){
resolver{ -> mlService.getAllUsers() }
}
query("getUser"){
resolver{ id: Int -> mlService.getUser(id) }
}
mutation("createUser"){
resolver{ age: Int, gender: String, occupationId: Long, zipCode: String -> mlService.createUser(age, gender, occupationId, zipCode) }
}
}
becomes:
val mlService = MovieLensService(MovieRepository, GenresRepository, OccupationRepository, RatingRepository, UserRepository)
val schema = KGraphQL.schema{
query("allUsers"){
mlService::getAllUsers.toResolver()
}
query("getUser"){
mlService::getUser.toResolver()
}
mutation("createUser"){
mlService::createUser.toResolver()
}
}