Giter VIP home page Giter VIP logo

Comments (9)

d-exclaimation avatar d-exclaimation commented on May 24, 2024

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.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

It should look and work similarly to apollo-server-express

from pioneer.

ZirgVoice avatar ZirgVoice commented on May 24, 2024

I did that, but how do I add cookies for example in the response of the Users function?

from pioneer.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

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.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

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.

ZirgVoice avatar ZirgVoice commented on May 24, 2024

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.

ZirgVoice avatar ZirgVoice commented on May 24, 2024

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?
Bildschirmfoto 2022-05-18 um 19 39 02

from pioneer.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

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.

ZirgVoice avatar ZirgVoice commented on May 24, 2024

Thank you very much, everything is clear now

from pioneer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.