Designing a GraphQL API - AWS AppSync

Designing a GraphQL API

If you are building a GraphQL API, there are some concepts you need to know, such as schema design and how to connect to data sources.

In this section, we show you how to build a schema from scratch, provision resources automatically, manually define a data source, and connect to it with a GraphQL resolver. AWS AppSync can also build out a schema and resolvers from scratch, if you have an existing Amazon DynamoDB table or build the entire backend with or without a pre-existing schema. Additionally, AWS AppSync provides a guided schema creation wizard that is recommended for first-time GraphQL or AWS AppSync users.

GraphQL Schema

Each GraphQL API is defined by a single GraphQL schema. The GraphQL Type system describes the capabilities of a GraphQL server and is used to determine if a query is valid. A server’s type system is referred to as that server’s schema. It is made up of a set of object types, scalars, input types, interfaces, enums, and unions. It defines the shape of the data that flows through your API and also the operations that can be performed. GraphQL is a strongly typed protocol and all data operations are validated against this schema.

Data Source

Data sources are resources in your AWS account that GraphQL APIs can interact with. AWS AppSync supports AWS Lambda, Amazon DynamoDB, relational databases (Amazon Aurora Serverless), Amazon Elasticsearch Service, and HTTP endpoints as data sources.

An AWS AppSync API can be configured to interact with multiple data sources, enabling you to aggregate data in a single location. AWS AppSync can use AWS resources from your account that already exist or can provision DynamoDB tables on your behalf from a schema definition.

Resolvers

GraphQL resolvers connect the fields in a type’s schema to a data source. Resolvers are the mechanism by which requests are fulfilled. AWS AppSync can automatically create and connect resolvers from a schema or create a schema and connect resolvers from an existing table without you needing to write any code.

Resolvers in AWS AppSync use mapping templates written in Apache Velocity Template Language (VTL) to convert a GraphQL expression into a format the data source can use.

An introductory tutorial-style programming guide for writing resolvers can be found in Resolver Mapping Template Programming Guide and helper utilities available to use when programming can be found in Resolver Mapping Template Context Reference. AWS AppSync also has built-in test and debug flows that you can use when you’re editing or authoring from scratch. For more information, see Test and Debug Resolvers.