happy new year everyone. we are creating a new gra...
# kgraphql
a
happy new year everyone. we are creating a new graphql application in kotlin and saw kgraphql. decided to use it over kotling-graphql as it looks more functional. we are fairly new to graphql and is learning as we go along. one question we have is how can we include the user session in the operations? since user session would not be part of schema, is there a way to include this in the resolvers?
btw, we are using it with ktor
j
Hi, thanks for using the library and please report any issues if you have any 🙂 To answer your question, you can provide any information you like to your execution like the following:
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"}")
	}
}
Context
is a special class and it won't get exposed to your GraphQL api.