-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set some to the response #29
Comments
The Vapor request and response object are given as parameter to the context builder in the From there you can grab the context from the resolver and get the response object used to make the GraphQL response. |
It should look and work similarly to |
I did that, but how do I add cookies for example in the response of the Users function? |
The |
An example would look like let cookie = HTTPCookies.Value(string: "some-value", expires: expiryDate, maxAge: 300, isSecure: false, isHTTPOnly: true, sameSite: HTTPCookies.SameSitePolicy.none)
response.cookies["cookie-name"] = cookie |
I know how to add cookies to the response. Explain how I can add cookies to the response that is in the context of the users function. In the users function, I return the type [User] and not Response |
You can't reassigned the response object with your own. You have to use the response given. You can do something like context.response.cookies["my-cookie"] = ... but not context.response = ... In the func users(ctx: Context, _: NoArguments) async -> [User] {
ctx.response.cookies["refresh-token"] = /* refresh token */
ctx.response.cookies["access-token"] = /* access token */
return await getUsers()
} The response object given in the context builder is going to be the one used to respond to the request. You don't need to return it, just mutate its values (it's a class so its values can be mutated) There is currently no way for a resolver function to return a custom response. The schema library |
Thank you very much, everything is clear now |
How can I add something to the response? For example, I need to add cookies
The text was updated successfully, but these errors were encountered: