我正在使用杜松子酒和 gqlgen。我需要从解析器设置 cookie,但我的解析器中只有上下文和来自 graphQL 的输入。这个问题已经在github中得到了解答。ctx.Writer.Write但这一个不同,因为当你尝试传递时我无法改变,也什么也做不了ctx.Next。因为gin不是那样工作的。
func (r *mutationResolver) Login(ctx context.Context, email string, password string) (bool, error) {
// You need ctx.Writer to set a cookie and can't access that from here
}
Run Code Online (Sandbox Code Playgroud)
我已经解决了这个问题,我想在下面回答我自己的问题。