Comments (9)
The Vapor request and response object are given as parameter to the context builder in the Pioneer
initiator (more details here). You can use that to create a Context
struct that contains the request specific response (An example of context builder)
From there you can grab the context from the resolver and get the response object used to make the GraphQL response.
from pioneer.
It should look and work similarly to apollo-server-express
from pioneer.
I did that, but how do I add cookies for example in the response of the Users function?
from pioneer.
The Response
object should have the cookies
property (Response
's cookie). You can just add the cookie manually by mutating that cookies
if I am not mistaken (HTTPCookies
object have subscript method that handle setting values)
from pioneer.
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
from pioneer.
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
from pioneer.
in this case, the function createCookies returns a response with a cookie. How can i return a ClientTokenReponse so that there are cookies in the header?
from pioneer.
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 users
function example you give, the code would look like
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 Graphiti
only take functions that return the type describe in the schema, and this library also have to handle encoding the returned value into a response that follow the proper GraphQL format.
from pioneer.
Thank you very much, everything is clear now
from pioneer.
Related Issues (20)
- Public structs have no public initialisers
- After pausing the websocket connection from Apollo iOS, it can't reconnect. HOT 12
- Documentation search is pointing to incorrect path HOT 2
- Better typing for payload HOT 1
- Improvement to Test HOT 1
- Improvement to optional spec-compliant HOT 4
- Field Resolve Middleware HOT 1
- VaporMiddleware responding incorrectly to all paths HOT 7
- Plugins
- Error: 'ConcurrentResolve' is only available in macOS 12 or newer HOT 4
- TestConsumer Improvement
- Agnostic Server Library HOT 1
- Use operation specific Response to return an GraphQL Result when formatting thrown error by resolver
- AbortError headers are ignored HOT 2
- Ambiguous use of async `init` on `Field` and `SubscriptionField`
- GraphQL over WebSocket validation and timeout on init
- JSON Incorrectly Encoded HOT 7
- Custom Directives HOT 2
- Contributing Guide
- `websocketOnInit` has not been implemented
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pioneer.