GraphQL facade for REST API with AWS Lambda

What exactly are we doing here?

What is a REST API?

What is GraphQL?

Setting up the serverless project

Our existing REST API

Resolvers, Schema & Types

What is a GraphQL Query?

What is a GraphQL Mutation?

What is GrapiQL?

{ posts{  _id,  title,  subtitle }}
mutation { addPost(    title: "Brand New Post",    subtitle: "This is super interesting",    text: "The body for the new blog post" ) {    title    subtitle    text }}

Putting it all together

  • clone the repo
  • install dependencies (yarn or npm install)
  • run: node server

Node setup:

app.use( ‘/’, graphqlHTTP({ 
graphiql: true,
schema: GraphQLSchema
}));

Lambda setup:

functions:  
getPosts:
handler: lambda.handler
events:
- http:
path: posts
method: get
cors: true
- http:
path: posts
method: post
cors: true

GraphQL setup:

Wrapping up:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store