Page updated Jan 16, 2024

Preview: AWS Amplify's new code-first DX (Gen 2)

The next generation of Amplify's backend building experience with a TypeScript-first DX.

Get started

Directives reference

The Amplify CLI provides GraphQL directives to enhance your schema with additional capabilities such as custom indexes, authorization rules, function triggers, and more.

DirectiveDescription
@modelDefines top level object types in your API that are backed by Amazon DynamoDB
@primaryKeyConfigures custom primary key for @model types
@indexConfigures custom secondary index structures for @model types
@authDefines authorization rules for your @model types and fields
@hasOneCreate a one-directional one-to-one relationship between two models. For example, a Project "has one" Team. This allows you to query the team from the project record
@hasManyCreate a one-directional one-to-many relationship between two models. For example, a Post has many comments. This allows you to query all the comments from the post record
@belongsToUse a "belongs to" relationship to make a "has one" or "has many" relationship bi-directional. For example, a Project has one Team and a Team belongs to a Project. This allows you to query the team from the project record and vice versa
@manyToManyConfigures a "join table" between two models to facilitate a many-to-many relationship. For example, a Blog has many Tags and a Tag has many Blogs
@functionConfigures a Lambda function resolvers for a field
@httpConfigures an HTTP resolver for a field
@predictionsQueries an orchestration of AI/ML services such as Amazon Rekognition, Amazon Translate, and/or Amazon Polly
@searchableMakes your data searchable by streaming it to Amazon OpenSearch
@mapsToOnce a table contains production data that cannot be deleted, @mapsTo can be used to specify the original name