Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

enable building graphql schema using KFunction method references #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pabl0rg
Copy link

@pabl0rg pabl0rg commented Mar 22, 2019

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()
    }
}

@coveralls
Copy link

coveralls commented Mar 22, 2019

Coverage Status

Coverage decreased (-0.01%) to 87.846% when pulling e8dfd02 on pabl0rg:master into 42fef4a on pgutkowski:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants