Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

The Simple GraphQL Service

architecture

This is an example CDK stack to deploy The Simple GraphQL Service inspired by Thorsten Hoeger's contributions to the CDK AppSync Module example

An advanced version of this pattern was talked about by Heitor Lessa at re:Invent 2019 as "The Cherry Pick".

This is the most basic of AppSync implementations and would have to be hardened before production use. e.g. cognito user pools configured

Note, never print your API Key to the logs in a production system. This was added to make learning AppSync and GraphQL easier. If you want to use this pattern in a production system remove the two cloudformation outputs

Testing

  1. After CDK Deploy, capture outputs from the log.
TheSimpleGraphqlServiceStack: deploying...
TheSimpleGraphqlServiceStack: creating CloudFormation changeset...

   TheSimpleGraphqlServiceStack

Outputs:
TheSimpleGraphqlServiceStack.APIKey = <API Key>
TheSimpleGraphqlServiceStack.Endpoint = https://<endpoint URL>.appsync-api.us-east-1.amazonaws.com/graphql
  1. Setup Postman as outlined in Postman's Using GraphQL Instructions

  2. Set POST request URL, x-api-key and Content-Type

  • x-api-key = 'your API Key'
  • Content-Type = application/graphql

postman

  1. Execute Mutations and Queries to exercice resolvers to dynamo and Lambda datasources

postman

// Inserts to Dynamo
mutation add {
  addCustomer(customer: { name: "CDKPatterns"}) {
    id
    name
  }
}

// Queries the Dynamo DB
query getCustomers {
  getCustomers{id name}
}

// Executes the Lambda
query getLoyalty {
  getLoyaltyLevel { level }
}

Available Versions