https://github.com/tsubasaogawa/terraform-appsync-graphql-test
An example for using GraphQL with AWS AppSync provisioned by Terraform
https://github.com/tsubasaogawa/terraform-appsync-graphql-test
appsync aws terraform
Last synced: 3 months ago
JSON representation
An example for using GraphQL with AWS AppSync provisioned by Terraform
- Host: GitHub
- URL: https://github.com/tsubasaogawa/terraform-appsync-graphql-test
- Owner: tsubasaogawa
- License: mit
- Created: 2020-07-16T08:50:05.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-25T13:06:24.000Z (almost 6 years ago)
- Last Synced: 2025-10-25T21:36:23.413Z (9 months ago)
- Topics: appsync, aws, terraform
- Language: HCL
- Homepage:
- Size: 43.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# terraform-appsync-graphql-test
An example for using GraphQL with AWS AppSync provisioned by Terraform.
Terraform creates the following AWS resources:
- AppSync
- 1 API
- 1 Schema
- 2 Resolvers
- DynamoDB
- 1 Table (for datasource)
- IAM
- 1 Role (+ 1 inline policy)
## Requirements
- terraform v0.12 or later
- awscli
## Setup
```bash
cd terraform-appsync-graphql-test
terraform init
terraform apply
```
## Architecture

## Example
```bash
# Setup
cd terraform-appsync-graphql-test
terraform init
terraform apply
# Set environment variables from tfstate
API_KEY=$(cat terraform.tfstate | jq -r '.outputs.appsync_api_key.value')
HOST=$(cat terraform.tfstate | jq -r '.outputs.appsync_api_uris.value.GRAPHQL' | grep -oP '[^/]+\.amazonaws.com')
# Call GraphQL
## Create user
curl \
-H 'Content-Type: application/json' \
-H "x-api-key: $API_KEY" \
-H "Host: $HOST" \
-X POST -d '
{
"query": "mutation { createUser(name: \"yoshida\") { id name } }"
}
' https://$HOST/graphql
{"data":{"createUser":{"id":"2e591d0b-c4cd-41bd-b66a-ad637e506f5f","name":"yoshida"}}}
## Get User
curl \
-H 'Content-Type: application/json' \
-H "x-api-key: $API_KEY" \
-H "Host: $HOST" \
-X POST -d '
{
"query": "query { user(id: \"2e591d0b-c4cd-41bd-b66a-ad637e506f5f\") { name } }"
}' \
https://$HOST/graphql
{"data":{"user":{"name":"yoshida"}}}
```