export const meta = {
  title: "Data modeling",
  description: "Get started with Amplify Studio",
};

## Data modeling example

In this example you will build a data model for a bookstore to maintain information about books, authors, and publishers with relationships and authorization rules. The schema template below is a starting point for the bookstore backend.

<Grid grid-gap="2" columns={1} className="margin-top-lg margin-bottom-lg">
  <Card
    external
    href="https://sandbox.amplifyapp.com/schema-design/8771638b-a00a-4a1d-af23-26913967cc5f/clone"
    containertag="amplify-external-link"
  >
    <CardGraphic alt="Amplify Studio logo" src="/images/console/adminui.svg" />
    <CardDetail>
      <h4>Clone in Sandbox</h4>
      <p>
        A bookstore data model template with four models called Book, ISBN,
        Publisher, and Author
      </p>
    </CardDetail>
  </Card>
</Grid>
<br />

Skip ahead to [relationships](/console/data/relationships) or read below on how data modeling works in Amplify Studio.

## Data modeling in Amplify Studio

The Studio data model designer provides a visual way to define your app's data model, relationships, and authorization rules. Studio generates a `schema.graphql` GraphQL Transform for the data model you create. To learn more about how the GraphQl transform works, see [GraphQL Transform Overview](/cli/graphql-transformer/overview).

![datamodel](/images/console/datamodel.gif)

The experience for modeling data is the same in the sandbox and in Studio. With an AWS account, you will have real-time data synchronization capabilities and you will also be able to set authorization rules on your models. For more information, see [Authorization](/console/authz/authorization). All data models are provisioned in your account as AWS AppSync GraphQL APIs and Amazon DynamoDB tables. As with every feature of Studio, it can be further extended with the CLI.

### DataStore and GraphQL
By default, all data models built with Studio are provisioned with Amplify DataStore. However, Studio applications work with both DataStore and an Amplify GraphQL API. 

**[DataStore](/lib/datastore/getting-started)** is an on-device storage engine that automatically synchronizes data between your mobile and web apps and your database, enabling offline use. DataStore requires a **Conflict Resolution** method to function. 

An **[Amplify GraphQL API](../../cli/graphql/overview/)** is an online-only API that uses a GraphQL and DynamoDB via AWS AppSync. 

To change your app's Conflict Resolution settings, or to change your app from using DataStore to using an Amplify GraphQL API, take the following steps:
1. Navigate to **[Amplify Studio](/console/adminui/start/#log-into-the-amplify-console) > Data**
2. Select **GraphQL API settings** at the top of the page
3. Toggle DataStore off or on, or change your Conflict Resolution strategy
4. Return to the Data Modeling screen and select **Save and Deploy**

<Callout warning>

**IMPORTANT NOTE**: Changing between DataStore and an Amplify GraphQL API is a significant change to your data structure, and can take up to 30 minutes to complete. Frequently changing between data structures is not recommended.

</Callout>

### Limitations
Applications that use an Amplify GraphQL API have limited feature availability in Studio. 
- The Content Manager is not supported, and is [replaced by a GraphiQL interface](content-management/#limitations)
- [Binding UI Components to data](../uibuilder/databinding/), and [generating Collections](../uibuilder/collections/) is not supported
- [Binding Forms to data, and auto-generated forms](../formbuilder/overview/) are not supported

To get access to these features, turn on DataStore and select a Conflict Resolution strategy.

### Unsupported directives and field-level parameters

If a data model contains unsupported directives or field-level parameters the **Visual editor** under Data modeling and **Data manager** under Content will not be available to use. However, you can continue using other Amplify Studio features and use the Amplify CLI to make modifications to GraphQL schemas.

- [`@default` directive](/cli/graphql/data-modeling/#assign-default-values-for-fields)
- [`@index` directive](/cli/graphql/data-modeling/#configure-a-secondary-index)
- [`@function` directive](/cli/graphql/custom-business-logic/#lambda-function-resolver)
- [`@http` directive](/cli/graphql/custom-business-logic/#http-resolver)
- [`@predictions` directive](/cli/graphql/connect-to-machine-learning-services/)
- [`@primaryKey` directive](/cli/graphql/data-modeling/#configure-a-primary-key)
- [`@searchable` directive](/cli/graphql/search-and-result-aggregations/)
- [`@mapsTo` directive](/cli/graphql/schema-evolution/)
- [`@auth` `groupClaim` property](/cli/graphql/authorization-rules/#user-group-based-data-access)
- [`@auth` `groupsField` property](/cli/graphql/authorization-rules/#field-level-authorization-rules)
- [`@auth` custom `groupClaim`](/cli/graphql/authorization-rules/#configure-custom-identity-and-group-claims)
- [`@auth` custom `identityClaim`](/cli/graphql/authorization-rules/#configure-custom-identity-and-group-claims)
- [`@auth` field-level rules](/cli/graphql/authorization-rules/#field-level-authorization-rules)
- [OIDC and Function providers](/cli/graphql/authorization-rules/#using-oidc-authorization-provider)
- [OwnerField as Array type](/cli/graphql/authorization-rules/#multi-user-data-access) 
- [`Query` type](/cli/graphql/custom-business-logic/#create-a-custom-query-or-mutation)
- [`Mutation` type](/cli/graphql/custom-business-logic/#create-a-custom-query-or-mutation)
- [`Subscription` type](/cli/graphql/custom-business-logic/#create-a-custom-query-or-mutation)

<Callout>

Data modeling only supports `@index` directive on a hasMany relationship. 

</Callout>

### Split GraphQL files

```console
Your schema file could not be loaded
The schema.graphql file in your project could not be loaded. This may be because the file was moved, or because you are using a split schema, which is not supported.
```

This message occurs as Amplify Studio does not support splitting GraphQL schemas, such as saving as a set of `.graphql` files in the `amplify/backend/api/<api-name>/schema/` directory. E.g. `Query.graphql`, `User.graphql`, and `Post.graphql`. 
To resolve the issue, you will need to combine the files using the following steps.

1. [Pull your Amplify project](/console/adminui/extend-cli/#to-configure-the-amplify-cli-for-use-without-an-aws-account) to a local directory
2. In the `amplify/backend/api/` directory, create a file named `schema.graphql`
3. Copy all the contents of the `amplify/backend/api/<api-name>/schema/` directory files and paste them into the `schema.graphql` file
4. Remove the `amplify/backend/api/<api-name>/schema/` directory.
5. Run `amplify push`