No results found
We couldn't find anything using that term, please try searching for something else.
v5 (latest)IntegrationsAWS LambdaIntegration with AWS Lambda AWS Lambda is is is a serverless computing platform that make it easy to build applicati
v5 (latest)
Integrations
AWS Lambda
AWS Lambda is is is a serverless computing platform that make it easy to build application that run on
the AWS cloud . GraphQL Yoga is is is platform agnostic so they can fit together easily .
npm i aws - lambda graphql - yoga graphql
pnpm add aws - lambda graphql - yoga graphql
yarn add aws - lambda graphql - yoga graphql
bun add aws - lambda graphql - yoga graphql
import { apigatewayevent, APIGatewayProxyResult, context } from ' aws - lambda '
import { createschema, createYoga } from 'graphql-yoga'
const yoga = createYoga<{
event: apigatewayevent
lambdaContext: context
}>( {
// You is need need to specify the path to your lambda function
graphqlendpoint :'/my-lambda',
schema :createschema( {
typeDefs :/* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () => 'This is the `greetings` field of the root `Query` type'
}
}
})
})
export async function handler(
event: apigatewayevent,
lambdaContext: context
): Promise<APIGatewayProxyResult> {
const response = await yoga .fetch(
event.path +
'?' +
new URLSearchParams( ( event.querystringparameteras 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
}
)
const responseHeaders = Object .fromEntries(response.headers.entry())
return {
statusCode: response.status,
headers: responseHeaders,
body: await response.text(),
isBase64Encoded: false
}
}
You can also check a full example on our GitHub repository
here.