Giter Site home page Giter Site logo

tanduong / appsync-resolvers-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sbstjn/appsync-resolvers-example

0.0 2.0 0.0 170 KB

Example project for AppSync, GraphQL, and AWS Lambda resolvers using Go.

Home Page: https://sbstjn.com/serverless-graphql-with-appsync-and-lambda.html

License: MIT License

Makefile 47.20% Go 52.80%

appsync-resolvers-example's Introduction

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.

appsync-resolvers-example's People

Contributors

sbstjn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.