Skip to content

Latest commit

 

History

History
139 lines (108 loc) · 3.46 KB

README.md

File metadata and controls

139 lines (108 loc) · 3.46 KB

AWS AppSync Resolvers w/ CloudFormation, Lambda & SAM

MIT License Read Tutorial Code Library

Fully working GraphQL API example project using appsync-resolvers for AWS AppSync and ready to be deployed with CloudFormation using the Serverless Application Model. Includes AWS Lambda functions for custom Query and Field resolvers written in Go. You only need the aws CLI application and no other third-party frameworks!  🎉

See Serverless GraphQL with AWS AppSync and Lambda on sbstjn.com for a detailed guide how to set up and configure this project. Or just run make configure build package deploy and you are ready to go …

Schema

type Person {
    id: Int!
    name: String!
    age: Int!

    friends: [Person!]!
}

type Query {
    people: [Person!]!
    person(id: Int): Person!
}

schema {
    query: Query
}

Configuration

The Makefile contains all tasks to set up the CloudFormation stack.

# Install Go dependencies
$ > make install

# Create S3 Bucket to store deploy artifacts
$ > make configure

# Build go binary for AWS Lambda
$ > make build

# Create deployable artifact
$ > make package

# Deploy CloudFormation stack
$ > make deploy

Usage

# Show CloudFormation stack output
$ > make outputs

[
  {
    "OutputKey": "APIKey",
    "OutputValue": "da2-jlewwo38ojcrfasc3dpaxqgxcc",
    "Description": "API Key"
  },
  {
    "OutputKey": "GraphQL",
    "OutputValue": "https://3mhugdjvrzeclk5ssrc7qzjpxn.appsync-api.eu-west-1.amazonaws.com/graphql",
    "Description": "GraphQL URL"
  }
]

Send GraphQL Requests

Request list of all people

$ > curl \
    -XPOST https://3mhugdjvrzeclk5ssrc7qzjpxn.appsync-api.eu-west-1.amazonaws.com/graphql \
    -H "Content-Type:application/graphql" \
    -H "x-api-key:da2-jlewwo38ojcrfasc3dpaxqgxcc" \
    -d '{ "query": "query { people { name } }" }' | jq
{
  "data": {
    "people": [
      {
        "name": "Frank Ocean"
      },
      {
        "name": "Paul Gascoigne"
      },
      {
        "name": "Uwe Seeler"
      }
    ]
  }
}

Request specific person

$ > curl \
    -XPOST https://3mhugdjvrzeclk5ssrc7qzjpxn.appsync-api.eu-west-1.amazonaws.com/graphql \
    -H "Content-Type:application/graphql" \
    -H "x-api-key:da2-jlewwo38ojcrfasc3dpaxqgxcc" \
    -d '{ "query": "query { person(id: 2) { name friends { name } } }" }' | jq
{
  "data": {
    "person": {
      "name": "Paul Gascoigne",
      "friends": [
        {
          "name": "Frank Ocean"
        }
      ]
    }
  }
}

License

Feel free to use the code, it's released using the MIT license.

Contribution

You are welcome to contribute to this project! 😘

To make sure you have a pleasant experience, please read the code of conduct. It outlines core values and beliefs and will make working together a happier experience.