aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
301 stars 58 forks source link

Provide documentation on Context usage #70

Closed jeggy closed 4 years ago

jeggy commented 4 years ago

Currently there is no documentation on how to use context and the NotIntrospected annotation.

I quickly wrote an example of how it could be used:

val query = """
    query fetchHelloLabel($country: String!) {
        hello(country: $country) {
            label
        }
    }
"""
val variables = """
    {"country": "English"}
"""
val user = User(id = 1, name = "Username")
val ctx = context {
    +user
}
schema.execute(query, variables, ctx)
...
// In your schema definition
query("hello") {
    resolver { country: String, ctx: Context ->
        val user = ctx.get<User>()
        Hello(label = "Hello ${user?.name ?: "unknown"}")
    }
}
jeggy commented 4 years ago

This is now available here: https://kgraphql.in/docs/reference/resolver/