• Stars
    star
    2,720
  • Rank 16,742 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serverless GraphQL Examples for AWS AppSync and Apollo

Build Status

Introduction

Part 1: Running a scalable & reliable GraphQL endpoint with Serverless
Part 2: AppSync Backend: AWS Managed GraphQL Service
Part 3: AppSync Frontend: AWS Managed GraphQL Service

Serverless GraphQL

This starter kit is an opinionated set of tools combined to help you get started building a Serverless application with a GraphQL endpoint and deploy them to production in minutes.

This example uses the following technologies:

System Architecture

serverless application architecture v2

Quick Setup

You need to have Node 6 or higher installed.

npm install -g serverless
npm install -g yarn
npm install -g netlify-cli

Install Dependencies.

yarn install

Feature Support in this repository

feature-support

Quick Start (Serverless Offline)

Please note: AWS CLI is required to be installed on your system

  1. Select Backend
  • AWS Appsync (Serverless Offline does not support Appsync at this point)

    • AWS DynamoDB
    • AWS ElasticSearch
    • AWS Lambda
  • Lambda Backend (Serverless Offline Supported)

    • Twitter Rest API
      cd app-backend/rest-api
      yarn start
      

    Generate your Consumer Key and Secret Key for a Twitter App and update config

    • DynamoDB

      cd app-backend/dynamodb
      yarn start
      
    • RDS

      cd app-backend/rds
      yarn start
      
  1. Start FrontEnd (Apollo Client or Appsync Client)
  • For Appsync Backend please select Appsync Client Integration:

    cd app-client/appsync-client/
    yarn start
    
  • For Lambda Backend please select Apollo Client Integration:

    cd app-client/apollo-client/
    yarn start
    

Also, please make sure GraphQL endpoint is configured correctly in config/security.env.local to run client on local.

  1. Start GraphiQL
http://localhost:4000/graphiql
  1. Start GraphQL Playground (GraphiQL replacement - coming soon)
http://localhost:4000/playground

rest-api and dynamodb backends route GET and POST to the same /graphql endpoint handler

http://localhost:4000/graphql
  1. Sample Query for GraphiQL, Playground or GraphQL
{
  getUserInfo(handle: "Madalyn61") {
    name
    tweets {
      items {
        retweeted
        retweet_count
        favorited
        tweet
      }
    }
    topTweet {
      retweeted
      retweet_count
      favorited
    }
  }
}

If you've followed me this far, DynamoDB will now be available and running on your local machine at http://localhost:8000/shell:

!Live Example

Setup for Production (Deploy resources to AWS)

Configure your AWS keys. Here you can find a 2min walkthrough how to do retrieve the keys.

sls config credentials --provider aws --key <your_aws_access_key> --secret <your_aws_secret_key>

!Live Example

You need to make sure you have access to your deployed lambda functions.

  1. Select Backend

Note Please make sure latest serverless package is installed npm install -g serverless@latest

To use aws appsync you will need to create cognito user pool to authenticate the API Reference

- AWS DynamoDB
    cd app-backend/appsync/dynamodb
    yarn deploy-prod
    yarn deploy-appsync
            
- AWS ElasticSearch
    
    cd app-backend/appsync/dynamo-elasticsearch-lambda
    yarn deploy-prod
    yarn deploy-appsync
            
- AWS Lambda
    
    cd app-backend/appsync/lambda
    yarn deploy-prod
    yarn deploy-appsync
  • Lambda Backend (Serverless Offline Supported)

    • Twitter Rest API

      cd app-backend/rest-api
      yarn deploy-prod
      
    • DynamoDB

      cd app-backend/dynamodb
      yarn deploy-prod
      
    • RDS

      • Create RDS Instance. For example - PostGres Tutorial

      • Please make sure connectivity to production RDS instance works (For example: test via razersql)

      • Edit the config/security.env.prod file and replace the DATABASE_URL variable with your amazon rds endpoint (eg: postgres://${username}:{password}@${endpoint):5432/${dbName}).

      • Run the deployment command

        cd app-backend/rds
        yarn deploy-prod
        
  1. Config: Get your /graphql POST endpoint as shown below and use it in config/security.env.prod NOTE Please remove all quotes and <> and place only your POST endpoint url otherwise you will get 405 method not allowed error on POST to your endpoint

deploy feedback

  1. Select Frontend (apollo-client or appsync-client)
  • Note:

    • For lambda please use apollo-client
    • For appsync backend please use appsync-client
    • Please note that backend is deployed before deploying frontend.
    • You can deploy the client on AWS S3 or Netlify.
  • AWS S3

    • First you will need to choose custom s3 bucket name for client. For ex: s3-firstname-serverless-graphql. Please note that bucket name must be unique across all aws buckets.

    • Now, in app-client/<client-name>/serverless.yml edit the custom.client.bucketName property and replace it the bucket name above.

    • Now, in app-client/<client-name>/package.json edit the homepage property with https://${yourBucketName}.s3-website-us-east-1.amazonaws.com. For ex: https://s3-bucketname-serverless-graphql.s3-website-us-east-1.amazonaws.com

    • Run the deployment command

      cd app-client/<client-name>/
      yarn deploy-s3
      # Your deployment url will be printed on the console
      
    • Your deployment url will be : https://s3.amazonaws.com/[bucket-name]/index.html

  • Netlify

    • First you will need to create a new account. Please see https://www.netlify.com/docs/cli/ for details.

    • Remove homepage property in app-client/<client-name>/package.json. This property is not required while deploying to netlify but is required for aws s3 deployment.

    • The first time you use the cli tool, you’ll be asked to authenticate through the browser. After you authenticate netlify will store an access token in a global ~/.netlify/config

    • Run deployment command

      cd app-client/<client-name>/
      yarn deploy-netlify
      
      • ? No site id specified, create a new site (Y/n) Y
      • ? Path to deploy? (current dir) build
    • Your deployment url will be printed on the console

Example: Appsync Backend Integration

  • GraphQL Schema:
type Mutation {
	# Create a tweet for a user
	# consumer keys and tokens are not required for dynamo integration
	createTweet(
		tweet: String!,
		consumer_key: String,
		consumer_secret: String,
		access_token_key: String,
		access_token_secret: String,
		created_at: String!
	): Tweet!

	# Delete User Tweet
	deleteTweet(
	    tweet_id: String!,
	    consumer_key: String,
        consumer_secret: String,
        access_token_key: String,
        access_token_secret: String
    ): Tweet!

	# Retweet existing Tweet
	reTweet(
	    tweet_id: String!,
	    consumer_key: String,
        consumer_secret: String,
        access_token_key: String,
        access_token_secret: String
    ): Tweet!

	# Update existing Tweet
	updateTweet(tweet_id: String!, tweet: String!): Tweet!

    # Create user info is available in dynamo integration
	updateUserInfo(
		location: String!,
		description: String!,
		name: String!,
		followers_count: Int!,
		friends_count: Int!,
		favourites_count: Int!,
		followers: [String!]!
	): User!
}

type Query {
	meInfo(consumer_key: String, consumer_secret: String): User!
	getUserInfo(handle: String!, consumer_key: String, consumer_secret: String): User!

	# search functionality is available in elasticsearch integration
	searchAllTweetsByKeyword(keyword: String!): TweetConnection
}

type Subscription {
	addTweet: Tweet
		@aws_subscribe(mutations: ["createTweet"])
}

type Tweet {
	tweet_id: String!
	tweet: String!
	retweeted: Boolean
	retweet_count: Int
	favorited: Boolean
	created_at: String!
}

type TweetConnection {
	items: [Tweet!]!
	nextToken: String
}

type User {
	name: String!
	handle: String!
	location: String!
	description: String!
	followers_count: Int!
	friends_count: Int!
	favourites_count: Int!
	followers: [String!]!
	topTweet: Tweet
	tweets(limit: Int!, nextToken: String): TweetConnection

	# search functionality is available in elasticsearch integration
    searchTweetsByKeyword(keyword: String!): TweetConnection
}

schema {
	query: Query
	mutation: Mutation
	subscription: Subscription
}
  • GraphQL Query:

query

Directory Layout

.
├── /app-client/                             # React JS Client Integrations
│   ├── /appsync-client                         # Appsync Client Itegrations
│   │   ├── /public/                            # front End Utils
│   │   │   ├── /index.html                     # main html file to render react app
│   │   │   ├── /...                            # front end metadata
│   │   ├── /src/                               # react app code logic
│   │   │   ├── /components/                    # react components
│   │   │   ├── /App.js                         # react application logic
│   │   │   ├── /index.js                       # react dom render
│   │   │   ├── /aws-exports.js                 # AWS Authentication
│   │   │   ├── /...                            # etc.
│   │   ├── /package.json                       # react app dependencies
│   │   ├── /serverless.yml                     # Serverless yaml for AWS deployment
│   ├── /apollo-client                       # Apollo Client Itegrations
│   │   ├── /public/                            # front End Utils
│   │   │   ├── /index.html                     # main html file to render react app
│   │   │   ├── /...                            # front end metadata
│   │   ├── /src/                               # react app code logic
│   │   │   ├── /components/                    # react components
│   │   │   ├── /App.js                         # react application logic
│   │   │   ├── /index.js                       # react dom render
│   │   │   ├── /...                            # etc.
│   │   ├── /package.json                       # react app dependencies
│   │   ├── /serverless.yml                     # Serverless yaml for AWS deployment
├── /app-backend/                            # Server Backend Integrations
├   ├── /appsync/                               # AWS Appsync Integrations
├   ├   ├── /dynamodb/*                         # AWS Appsync Dynamodb 
├   ├   ├── /elasticsearch/*                    # AWS Appsync Elasticsearch
├   ├   ├── /lambda/                            # AWS Appsync Lambda
│   ├── /dynamodb                            # Integration with DynamodDB Backend
│   │   ├── /seed-data/                         # seed test data
│   │   │   ├── /create_seed_data.js            # Create Seed data to be inserted in dynamodb local and remote
│   │   │   ├── /insert_seed_data_prod.js       # Insert seed data in aws dynamodb (serverless)
│   │   │   ├── /sample-query.txt               # Test Query on DynamoDB Local Client http://localhost:8000
│   │   ├── /handler.js                         # AWS Lambda - Apollo Lambda Server
│   │   ├── /package.js                         # server side dependencies
│   │   ├── /resolvers.js                       # graphql resolvers
│   │   ├── /schema.js                          # graphql schema
│   │   ├── /serverless.yml                     # Serverless yaml for AWS deployment
│   │   ├── /webpack.config.js                  # Webpack server side code with ES6
│   ├── /rest-api                           # Integration with REST API Backend
│   │   ├── /handler.js                         # AWS Lambda - Apollo Lambda Server
│   │   ├── /package.js                         # server side dependencies
│   │   ├── /resolvers.js                       # graphql resolvers
│   │   ├── /schema.js                          # graphql schema
│   │   ├── /serverless.yml                     # Serverless yaml for AWS deployment
│   │   ├── /webpack.config.js                  # Webpack server side code with ES6
│   ├── /rds                                # Integrations for PostGres, MySQL and Aurora Backend
│   │   ├── /seed-data/                         # seed test data
│   │   │   ├── /create_seed_data.js            # Create Seed data to be inserted in dynamodb local and remote
│   │   │   ├── /seed_local.js                  # Insert seed data in aws dynamodb (serverless)
│   │   │   ├── /seed_prod.js                   # Test Query on DynamoDB Local Client http://localhost:8000
│   │   ├── /migrations/                        # Create DDL statements
│   │   ├── /knexfile.js                        # Database Configurations 
│   │   ├── /handler.js                         # AWS Lambda - Apollo Lambda Server
│   │   ├── /package.js                         # server side dependencies
│   │   ├── /resolvers.js                       # graphql resolvers
│   │   ├── /schema.js                          # graphql schema
│   │   ├── /serverless.yml                     # Serverless yaml for AWS deployment
│   │   ├── /webpack.config.js                  # Webpack server side code with ES6
├── /config/                                # Configuration files
│   ├── /security.env.local                     # local config
│   ├── /security.env.prod                      # production config

Coming Soon

  1. Schema Stitching
  2. Lambda Backend: GraphCool, Druid
  3. Aggregations at Scale - Druid
  4. Lambda Backend: Authentication and Authorization
  5. Lambda Backend: Pagination
  6. Swagger Integration
  7. Integration with Azure, IBM and Google Coud

Who uses Serverless GraphQL Apollo?

As the Serverless GraphQL Apollo community grows, we'd like to keep track of who is using the platform. Please send a PR with your company name and @githubhandle if you may.

Currently officially using Serverless GraphQL Apollo :

  1. Serverless @nikgraf
  2. Glassdoor @sid88in
  3. @pradel
  4. EMC School @JstnEdr

Feedback

Send your questions or feedback at: @nikgraf, @sidg_sid

More Repositories

1

serverless

⚡ Serverless Framework – Use AWS Lambda and other managed cloud services to build apps that auto-scale, cost nothing when idle, and boast radically low maintenance.
JavaScript
46,101
star
2

examples

Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more.
JavaScript
11,353
star
3

components

The Serverless Framework's new infrastructure provisioning technology — Build, compose, & deploy serverless apps in seconds...
JavaScript
2,306
star
4

event-gateway

React to any event with serverless functions across clouds
Go
1,647
star
5

serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages
JavaScript
1,108
star
6

plugins

Serverless Plugins – Extend the Serverless Framework with these community driven plugins –
JavaScript
970
star
7

aws-ai-stack

AWS AI Stack – A ready-to-use, full-stack boilerplate project for building serverless AI applications on AWS
JavaScript
911
star
8

serverless-graphql-blog

A Serverless Blog leveraging GraphQL to offer a REST API with only 1 endpoint using Serverless v0.5
JavaScript
793
star
9

serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
TypeScript
776
star
10

github-action

⚡:octocat: A Github Action for deploying with the Serverless Framework
Dockerfile
642
star
11

scope

🔭 Scope - Create a birdeye's view of your Github project and embed on your site
JavaScript
456
star
12

guide

Serverless Guide - An open-source definitive guide to serverless architectures.
Shell
439
star
13

serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
JavaScript
302
star
14

serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
JavaScript
272
star
15

serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
TypeScript
266
star
16

post-scheduler

Schedule posts & content updates for static websites (Jekyll, Hugo, Gatsby, Phenomic etc)
JavaScript
191
star
17

serverless-starter

A boilerplate for new Serverless Projects
JavaScript
190
star
18

blog

serverless.com/blog – Posts from the Serverless community & core team. Contributions welcome!
JavaScript
183
star
19

serverless-client-s3

A plugin to deploy front-end assets to S3 via the Serverless Framework
JavaScript
171
star
20

serverless-websockets-plugin

Websocket support for Serverless Framework on AWS
JavaScript
149
star
21

serverless-openwhisk

Adds Apache OpenWhisk support to the Serverless Framework!
JavaScript
143
star
22

typescript

TypeScript definitions for Serverless Framework service configuration
TypeScript
140
star
23

serverless-slackbot

[Deprecated] A Serverless Module to create your own SlackBot without servers/websockets via Slash Commands
JavaScript
135
star
24

cloud

Serverless Cloud makes building, deploying, and managing serverless applications easier and more accessible to everyone.
HTML
112
star
25

compose

Orchestrate Serverless Framework in monorepos
JavaScript
109
star
26

event-gateway-example

JavaScript
104
star
27

serverless-optimizer-plugin

Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -
JavaScript
102
star
28

enterprise

Documentation for the Serverless Framework Enterprise Edition –
95
star
29

multicloud

The serverless @multicloud library provides an easy way to write your serverless handlers 1 time and deploy them to multiple cloud providers include Azure & AWS.
TypeScript
90
star
30

aws-event-mocks

JavaScript
83
star
31

emulator

Serverless Emulator which lets you run serverless functions locally
JavaScript
78
star
32

serverless-local-schedule

⚡️🗺️⏰ Schedule AWS CloudWatch Event based invocations in local time(with DST support!)
JavaScript
72
star
33

event-mocks

TypeScript
72
star
34

fdk

This library is deprecated. Please use https://github.com/serverless/event-gateway-sdk instead.
JavaScript
69
star
35

serverless-open-runtime

WIP - An extensible, community-driven, open-runtime for serverless compute
Go
68
star
36

serverless-runtime-babel

Babel runtime for v.0.5 of the Serverless Framework
JavaScript
68
star
37

forms-service

Serverless Forms Service to collect form data with Admin UI
JavaScript
66
star
38

serverless-secrets-plugin

JavaScript
66
star
39

serverless-golang

Serverless Template for Golang
Go
64
star
40

serverless-tencent

⚡️ 🐧 Serverless Tencent CLI 及中文讨论社区
JavaScript
63
star
41

serverless-slack

A Serverless Module featuring pre-written Slack functions from authorization to slash commands!
JavaScript
49
star
42

dashboard-plugin

The Serverless Framework Dashboard plugin
JavaScript
49
star
43

event-gateway-getting-started

Walkthrough application for using the Event Gateway. -- https://www.serverless.com
JavaScript
48
star
44

workshop

A complete full-stack application and walkthrough for learning the features of the Serverless Framework.
CSS
45
star
45

desktop

A native GUI application that makes it easy to explore and test Serverless Framework applications built on AWS Lambda.
45
star
46

serverless-swagger-plugin

JavaScript
44
star
47

serverless-meta-sync

Secure syncing of serverless project meta data across teams
JavaScript
44
star
48

event-gateway-sdk

Event Gateway JavaScript SDK
JavaScript
43
star
49

safeguards-plugin

Serverless Framework Plugin to enforce safeguard policies
JavaScript
33
star
50

serverless-graphql-relay

Serverless GraphQL Boilerplate using Relay – Ready to be deployed to production within minutes …
JavaScript
32
star
51

utils

General serverless utilities
JavaScript
29
star
52

serverless-event-gateway-plugin

Event Gateway plugin for Serverless Framework
JavaScript
28
star
53

eslint-config

Common ESLint & Prettier config for Serverless projects
JavaScript
27
star
54

serverless-knative

Serverless Knative Provider Plugin – Adds Knative to the Serverless Framework
JavaScript
25
star
55

serverless-plugin-boilerplate

A Starter Project to help you build Plugins for the Serverless Framework -
JavaScript
24
star
56

dashboard

JavaScript
24
star
57

fullstack-course

The entire fullstack application course as seen on serverless.com/learn
JavaScript
24
star
58

serverless-babel-plugin

A Serverless plugin to compile your JavaScript code with Babel before deployment
JavaScript
23
star
59

serverless-plugin-log-retention

Control the retention of your serverless function's cloudwatch logs.
JavaScript
20
star
60

cloud-computing-conferences

A curated list of all the best cloud computing conferences happening in 2019! Check here to find a serverless or cloud event happening near you.
18
star
61

event-gateway-workshop

Learn what the Event Gateway is, how it works and build your first event-driven multi-cloud application!
JavaScript
18
star
62

fdk-tmp

The Serverless Function Development Kit (FDK)
JavaScript
18
star
63

aws-sdk-extra

The AWS SDK + a handful of extra convenience methods.
JavaScript
18
star
64

platform-sdk

Serverless Platform SDK
JavaScript
17
star
65

meetups

Want to start a Serverless usergroup? We can help you get started and be an official Serverless Usergroup. Join us to be part of the family of many Serverless Usergroups across the world.
17
star
66

boilerplate-googlecloudfunctions-nodejs

A Serverless Framework Boilerplate for Google Cloud Functions support in Node.js
JavaScript
15
star
67

cli

Serverless Components CLI
JavaScript
14
star
68

serverless-helpers-py

Python
12
star
69

tutorial

A tutorial repo with multiple projects designed to help teach users
JavaScript
11
star
70

serverless-helpers-js

Serverless Helpers Node.Js: An NPM module that provides helper functions for Serverless Modules written in Node.js -
JavaScript
11
star
71

template

Compose & provision a collection of Serverless Components
JavaScript
10
star
72

template-package

Repository template for serverless packages
JavaScript
9
star
73

serverlessconf-workshop

JavaScript
9
star
74

serverless-search-engine

Part of the Serverless Live series where we build a very simplistic search engine and spider
JavaScript
9
star
75

artwork

Official design elements of Serverless Inc. and its projects
8
star
76

extensions

Use / make / monetize developer experiences.
JavaScript
8
star
77

event-gateway-connector

Serverless Event Gateway Connector Framework
Go
7
star
78

raffleapp

A serverless raffle app
JavaScript
7
star
79

netlify-landing-page

Components Landing page demo
CSS
7
star
80

compose-example

JavaScript
6
star
81

demo-todo

An example serverless-todo app
JavaScript
5
star
82

serverless-raffle

JavaScript
5
star
83

enterprise-template

JavaScript
5
star
84

workshops

Companion repo for workshops with instructions and code examples
JavaScript
5
star
85

sls-action

GitHub action for Serverless CLI
TypeScript
5
star
86

test

Test setup and utilities for serverless projects
JavaScript
4
star
87

compose-website-example

JavaScript
4
star
88

console

4
star
89

cli-design

Repository to discuss Serverless Framework v3 redesign
HTML
4
star
90

event-gateway-tracer

JavaScript
3
star
91

core

Serverless Components Core
JavaScript
3
star
92

status

The Serverless Status Page
JavaScript
3
star
93

partner-examples

JavaScript
2
star
94

components-core

WIP
TypeScript
2
star
95

azure-build-task

A Serverless build task for Azure Dev Ops
TypeScript
1
star
96

sfe-nodejs-service

JavaScript
1
star
97

inquirer

inquirer with enforced serverless theme
JavaScript
1
star
98

template-getting-started-node-js

Application templates used by the Serverless Platform
1
star
99

serverless-cloud-gitpod

Starter repository for running Serverless Cloud on GitPod
1
star
100

user-testing

Tests of product concepts
JavaScript
1
star