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

vio

07/29/2021, 12:32 PM
Hi everyone! I was working on a graphql schema, and I would like to have a logout mutation. Is there a way to clear the context for future mutations/queries? Any help is appreciated, thank you 🙏
j

jeggy

07/29/2021, 12:46 PM
Hi Vio, The context is fully built by you on a per request basis. So I would need to know more information about your setup to help you here 😕
v

vio

07/29/2021, 1:14 PM
Given a configuration like this, where I store some user details in a variable called
user
, Is there a way to remove the user details from context with a logout mutation?
Copy code
context { +user }

schema {

    mutation("logout") {
        resolver { ctx: Context ->
            val user = ctx.get<User>()
            
            // I'm looking for something like bellow
            ctx.clear() 
        }
    }

}
j

jeggy

07/29/2021, 1:53 PM
No, something like that is not directly possible. But what you are looking for is to understand the logic of
context { +user }
. As that code is being run upon every request. So if you want to clear the session, it's something that needs happen outside of KGraphQL
🙏 1
I'm not sure of how your user object is built?
and where are you calling the
schema.execute()
?
v

vio

07/30/2021, 8:08 AM
Thank you, your explanation makes sense. I'm calling the
schema.execute
at the start of the application, my confusion was around understanding that the context is build at each request but makes sense now 🙂 I've tried clearing the session outside of
kgraphql
and that was just what I needed, thanks 🚀
👍 1
4 Views