-
Notifications
You must be signed in to change notification settings - Fork 569
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
Create Cookies in Resolvers using AWS Lambda Integration #2554
Comments
Maybe something like this? I have not tested it but you get the idea. import { createYoga, createSchema } from 'graphql-yoga'
import { APIGatewayEvent, APIGatewayProxyResult, Context } from 'aws-lambda'
type ResponseHeaders = Record<string, string>
const yoga = createYoga<{
event: APIGatewayEvent
lambdaContext: Context
responseHeaders: ResponseHeaders
}>({
graphqlEndpoint: '/graphql',
landingPage: false,
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: (_, _args, { request, params, responseHeaders, event, lambdaContext }) => {
responseHeaders['Cookies'] = 'test';
return 'This is the `greetings` field of the root `Query` type';
},
},
},
}),
context({ event, lambdaContext, request, responseHeaders }) {
return {
event, lambdaContext, request, responseHeaders
}
}
})
export async function handler(
event: APIGatewayEvent,
lambdaContext: Context,
): Promise<APIGatewayProxyResult> {
const responseHeaders: ResponseHeaders = {};
const response = await yoga.fetch(
event.path +
'?' +
new URLSearchParams(
(event.queryStringParameters as Record<string, string>) || {},
).toString(),
{
method: event.httpMethod,
headers: event.headers as HeadersInit,
body: event.body
? Buffer.from(event.body, event.isBase64Encoded ? 'base64' : 'utf8')
: undefined,
},
{
event,
lambdaContext,
responseHeaders,
},
)
response.headers.forEach((value, name) => {
responseHeaders[name] = value
})
return {
statusCode: response.status,
headers: responseHeaders,
body: await response.text(),
isBase64Encoded: false,
}
} |
Merged
@ardatan I am assuming @whatwg-node/server-plugin-cookies plugin is not available yet, but is ready to be merged? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Hi I am using the graphql-yoga integration with AWS Lambda sample from below link 👇🏼
https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-aws-lambda
I am unable to access the response object in the context function. I would like to access it in the AWS Lambda Integration so it can be passed onto the resolvers.
Describe the solution you'd like
I want to grab the response object in the context function, which I believe is available in node.js environment, but not sure if it is available in the lambda env or not.
If not is there a way to send cookies with the actual response after generating them from within a resolver?
Describe alternatives you've considered
I could potentially use the node.js version of graphql-yoga with lambda integration so that I have access to the response object in addition to the request. Is that possible?
The text was updated successfully, but these errors were encountered: