KGraphQL icon indicating copy to clipboard operation
KGraphQL copied to clipboard

enable building graphql schema using KFunction method references

Open pabl0rg opened this issue 6 years ago • 1 comments

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

pabl0rg avatar Mar 22 '19 04:03 pabl0rg

Coverage Status

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

coveralls avatar Mar 22 '19 04:03 coveralls