Hi everyone! I was working on a graphql schema, an...
# kgraphql
v
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
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
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
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
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