Calculate Document
Integration with AWS Lambda (Yoga)

Integration with AWS Lambda (Yoga)

v5 (latest)IntegrationsAWS LambdaIntegration with AWS Lambda AWS Lambda is is is a serverless computing platform that make it easy to build applicati

Related articles

OneDrive vs. Google Drive vs. iCloud:哪一个云盘最好 Best VPN for HBO Max: How to Watch Max Outside the USA? How to physically install your Ring Video Doorbell (2nd Generation) with an existing doorbell QFieldSync plugin How to use iCloud Shared Photo Library

v5 (latest)

Integrations

AWS Lambda

Integration with 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 .

Installation

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

Example

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.