https://kotlinlang.org logo
#kgraphql
Title
# kgraphql
y

Yuri Kornienko

04/15/2020, 9:29 AM
another question. How I can access to context in resolver? For example, I need check token from header
j

jeggy

04/15/2020, 1:33 PM
Copy code
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"}")
	}
}
Here's an example
👍 1
sorry about this. I will try to get this into the documentation later today 🙂
Added this same sample to the documentation 🙂 https://kgraphql.in/docs/reference/resolver/
3 Views