graphql-dotnet / server

ASP.NET Core GraphQL Server
MIT License
578 stars 163 forks source link

Set-Cookie not set #228

Closed shoe-diamente closed 4 years ago

shoe-diamente commented 5 years ago

I have a mutation which accesses the HttpContext from IHttpContextAccessor and sets the cookies in the response via:

 _httpContext.HttpContext.Response.Cookies.Append("access_token", "abc", new CookieOptions()
{
    Domain = "example.com",
    Secure = false,
    HttpOnly = false,
    IsEssential = true,
});

This same exact code, put in a .NET Core controller works. When put in a GraphQL mutation it doesn't seem to expose the Set-Cookie header in the response.

My setup code is the following:

services.AddGraphQL(options =>
{
    options.ExposeExceptions = false;
})
.AddDataLoader()
.AddUserContextBuilder(httpContext => 
    httpContext.RequestServices.GetService<IMediator>());

What could be the cause of this?

sungam3r commented 4 years ago

@shoe-diamente I conducted an experiment. I copied your code to one of my resolvers (.net core 2.2). In the posponse I found the required header Set-Cookie. Is this problem still actual?

shoe-diamente commented 4 years ago

I started using graphql-dotnet/conventions and moved away from graphl-dotnet/server. In hindsight I don't think it was due to graphql-dotnet/server, but it's just a feeling. I'll close it.