Currently, in the Ballerina GraphQL service, users cannot access the HTTP response. This was done intentionally to decouple the HTTP and GraphQL protocols.
But this was before we introduced the graphql:Context object, which is, as the name suggests, contextual. Therefore, we can include the http:Response object in the graphql:Context so the users can access the response object inside the GraphQL service.
This can be helpful in many scenarios, including handling cookies, sending specific status codes with the GraphQL response, etc.
The http:Response object should be created inside the graphql:Context object and should be accessed via an API (either context.get() or a separate one like context.getResponse()).
Description:
Currently, in the Ballerina GraphQL service, users cannot access the HTTP response. This was done intentionally to decouple the HTTP and GraphQL protocols.
But this was before we introduced the
graphql:Context
object, which is, as the name suggests, contextual. Therefore, we can include thehttp:Response
object in thegraphql:Context
so the users can access the response object inside the GraphQL service.This can be helpful in many scenarios, including handling cookies, sending specific status codes with the GraphQL response, etc.
The
http:Response
object should be created inside thegraphql:Context
object and should be accessed via an API (eithercontext.get()
or a separate one likecontext.getResponse()
).