Directives reference
These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.
The Amplify CLI provides GraphQL directives to enhance your schema with additional capabilities such as custom indexes, authorization rules, function triggers, and more.
| Directive | Description |
|---|---|
@model | Defines top level object types in your API that are backed by Amazon DynamoDB |
@primaryKey | Configures custom primary key for @model types |
@index | Configures custom secondary index structures for @model types |
@auth | Defines authorization rules for your @model types and fields |
@hasOne | Create 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 |
@hasMany | Create 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 |
@belongsTo | Use 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 |
@manyToMany | Configures 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 |
@function | Configures a Lambda function resolvers for a field |
@http | Configures an HTTP resolver for a field |
@predictions | Queries an orchestration of AI/ML services such as Amazon Rekognition, Amazon Translate, and/or Amazon Polly |
@searchable | Makes your data searchable by streaming it to Amazon OpenSearch |
@mapsTo | Once a table contains production data that cannot be deleted, @mapsTo can be used to specify the original name |