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

enable building graphql schema using KFunction method references#61

Open
pabl0rg wants to merge 2 commits into
pgutkowski:masterfrom
pabl0rg:master
Open

enable building graphql schema using KFunction method references#61
pabl0rg wants to merge 2 commits into
pgutkowski:masterfrom
pabl0rg:master

Conversation

@pabl0rg

@pabl0rg pabl0rg commented Mar 22, 2019

Copy link
Copy Markdown

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

coveralls commented Mar 22, 2019

Copy link
Copy Markdown

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.

2 participants