Skip to content

Support finding queries and mutations in the same class #197

@pabl0rg

Description

@pabl0rg

Is 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions