Support finding queries and mutations in the same class
See original GitHub issueIs your feature request related to a problem? Please describe. I have a traditional java/kotlin service (that handles both mutations and queries) and I’d like to expose most of it’s methods without repeating myself too much, while adding a necessary layer for authorization checks.
Currently, I have to create two classes: one that exposes my existing service’s queries and another that exposes the mutations.
For example:
class UserService {
val users = mutableMapOf<Int, String>()
fun getUser(id: Int) = users[id]
fun createUser(name: String) {
val id = users.keys.max() ?: 0 + 1
users[id] = name
}
}
class UserQueries(private val userService: UserService) {
fun getUser(id: Int) = userService.getUser(id)
}
class UserMutations(private val userService: UserService) {
fun createUser(name: String) = userService.createUser(name)
}
This gets tedious when user has a lot of fields
Describe the solution you’d like I’m not sure, but I think this might be easier if there was a way to pass lists of functions or function references to SchemaGenerator or QueryBuilder instead of having to define a class. Your library would allow users to compose a graphql api from functions and existing services.
Describe alternatives you’ve considered You are probably aware of https://github.com/pgutkowski/KGraphQL. That project seems to have lost some steam, but has some cool characteristics in that it allows composing the graphql api in a direct, simple manner. Unfortunately, there’s a lot of boilerplate involved.
Additional context Add any other context or screenshots about the feature request here.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
🤦♂️ thanks!
I was hoping the
MovieLensQueries
andMovieLensMutations
classes could be that layer and not require much boilerplate. (We like having something like theMovieLensService
for consumption by other kotlin/java modules in the same process. Monoliths are fast and easy to maintain)I’ll try another approach. Thanks!