-
Notifications
You must be signed in to change notification settings - Fork 317
Update documentation to show setting response headers with value from @SchemaMapping
method
#428
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
From where would you like to set this cookie value? A Servlet filter? A |
I want to use it in @schemamapping controller method. |
Spring for GraphQL is transport-agnostic, meaning that the The interception section is probably still the best way to achieve this: you can set a value in the GraphQL context and later use it to set response headers. |
I guess the example shows how to take a value from the request, put it in the @Controller
class MyController {
@QueryMapping
Person person(GraphQLContext context) {
context.put("cookie", "123");
}
} And then access that from an class ResponseHeaderInterceptor implements WebGraphQlInterceptor {
@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
return chain.next(request).doOnNext(response -> {
String value = response.getExecutionInput().getGraphQLContext().get("cookie");
ResponseCookie cookie = ResponseCookie.from("cookieName", value).build();
response.getResponseHeaders().add(HttpHeaders.SET_COOKIE, cookie.toString());
});
}
} I think we could improve a bit the example in the docs based on this. |
@SchemaMapping
method
@rstoyanchev |
As the title suggests, I am trying to set cookie in signin using graphql.
I am using spring mvc and I know that the existing cookie setting method using HttpServletResponse is not available.
Is there no way to set cookie in graphql?
The text was updated successfully, but these errors were encountered: