Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7a3c6c5
cli flow for connecting api to existing database
chrisbonifacio Nov 10, 2023
0dbb785
add sql data types to cspell
chrisbonifacio Nov 10, 2023
a9d9f85
add link to rds proxy pricing page
chrisbonifacio Nov 10, 2023
cba3c3c
make schema.sql.graphql consistent
chrisbonifacio Nov 10, 2023
1459bac
change cyan mapping to skyblue for better readability
chrisbonifacio Nov 10, 2023
38cd4b2
adjust date type colors
chrisbonifacio Nov 10, 2023
08e1bb7
Add page to directory.mjs
chrisbonifacio Nov 14, 2023
f572551
update cdk with csv script and schema gen step
chrisbonifacio Nov 14, 2023
7fcb385
add terms to cspell
chrisbonifacio Nov 14, 2023
621ee93
add callout for time zone offsets
chrisbonifacio Nov 14, 2023
6bde20b
adjust header levels
chrisbonifacio Nov 14, 2023
9a9e7b5
remove redundant text
chrisbonifacio Nov 14, 2023
118d06f
add step to replace <database-name> in sql script
chrisbonifacio Nov 14, 2023
422b332
add step to replace <database-name> in sql script
chrisbonifacio Nov 14, 2023
d80162b
mention updating the path to the graphql file
chrisbonifacio Nov 14, 2023
7f0b182
Merge branch 'next-release/main' of github.com:aws-amplify/docs into …
chrisbonifacio Nov 14, 2023
1a83236
Merge branch 'next-release/main' of github.com:aws-amplify/docs into …
chrisbonifacio Nov 14, 2023
8297896
update links to point to platform/<v6-path>
chrisbonifacio Nov 14, 2023
49afe34
remove gen2/existing-projects page from directory.mjs
chrisbonifacio Nov 14, 2023
0218aa1
update MySQL csv script
chrisbonifacio Nov 15, 2023
9d707e7
update cdk construct api
chrisbonifacio Nov 15, 2023
11121ec
update sql script for postgres
chrisbonifacio Nov 15, 2023
684cf66
update sql scripts under iterative changes section
chrisbonifacio Nov 15, 2023
0ec4fc7
merge main into cbonif/connect-api-to-db
chrisbonifacio Nov 23, 2023
8f2e19a
refactor to CDK only workflow
chrisbonifacio Nov 24, 2023
5e22369
Add experimental note to iterative change section
chrisbonifacio Nov 24, 2023
48b9a9f
Merge branch 'main' of github.com:aws-amplify/docs into cbonif/connec…
chrisbonifacio Nov 24, 2023
ff6e457
applied edits for launch
Nov 27, 2023
a33e67e
reverted unintende file changes
Nov 27, 2023
58ef119
reverted unencessary file changes
Nov 27, 2023
b5cfe13
removed empty line hack
Nov 27, 2023
e243d2e
removed final model reference
Nov 27, 2023
cee25d8
removed the reference fo the word "model"
Nov 27, 2023
bf26898
Merge branch 'main' into cbonif/connect-api-to-db
renebrandel Nov 27, 2023
a075928
removed sandbox reference
Nov 27, 2023
1863c02
Merge branch 'cbonif/connect-api-to-db' of github.com:aws-amplify/doc…
Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add experimental note to iterative change section
  • Loading branch information
chrisbonifacio committed Nov 24, 2023
commit 5e22369138e9662f18cd5b2c81bcfb6306c393dd
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,88 @@ Now the API has been deployed and you can start using it!

You can start querying from the AWS AppSync console or integrate it into your application using the AWS Amplify libraries!

### Rename & map models to tables

To rename models and fields, you can use the `@refersTo` directive to map the models in the GraphQL schema to the corresponding table or field by name.

By default, the Amplify CLI singularizes each model name using PascalCase and field names that are either snake_case or kebab-case will be converted to camelCase.

In the example below, the Post model in the GraphQL schema is now mapped to the posts table in the database schema. Also, the isPublished is now mapped to the published column on the posts table.

```graphql
type Post @refersTo(name: "posts") @model {
id: String! @primaryKey
title: String!
content: String!
isPublished: Boolean @refersTo(name: "is-published")
publishedDate: AWSDate @refersTo(name: "published_date")
}
```

## Create relationships between models

You can use the `@hasOne`, `@hasMany`, and `@belongsTo` relational directives to create relationships between models. The field named in the `references` parameter of the relational directives must exist on the child model.

### Has One relationship

Create a one-directional one-to-one relationship between two models using the `@hasOne` directive.

In the example below, a User has a single Profile.

```graphql
type User
@refersTo(name: "users")
@model
@auth(rules: [{ allow: owner }, { allow: groups, groups: ["Admin"] }]) {
id: String! @primaryKey
name: String!
owner: String
profile: Profile @hasOne(references: ["userId"])
}
```

### Has Many relationship

Create a one-directional one-to-many relationship between two models using the `@hasMany` directive.

In the example below, a Blog has many Posts.

```graphql
type Blog @model {
id: String! @primaryKey
title: String!
posts: [Post] @hasMany(references: ["blogId"])
}

type Post @model {
id: String! @primaryKey
title: String!
content: String!
}
```

### Belongs To relationship

Make a "has one" or "has many" relationship bi-directional with the `@belongsTo` directive.

In the example below, a Post belongs to a Blog.

```graphql
type Post @model {
id: String! @primaryKey
title: String!
content: String!
blogId: String! @refersTo(name: "blog_id")
blog: Blog @belongsTo(references: ["blogId"])
}
```

## Apply iterative changes from the database definition

<Callout>
**NOTE:** This feature is experimental and is subject to change.
</Callout>

<Accordion
title="Mapping of SQL Data Types to GraphQL Types"
headingLevel="3"
Expand Down Expand Up @@ -593,82 +673,6 @@ cdk deploy

</Accordion>

### Rename & map models to tables

To rename models and fields, you can use the `@refersTo` directive to map the models in the GraphQL schema to the corresponding table or field by name.

By default, the Amplify CLI singularizes each model name using PascalCase and field names that are either snake_case or kebab-case will be converted to camelCase.

In the example below, the Post model in the GraphQL schema is now mapped to the posts table in the database schema. Also, the isPublished is now mapped to the published column on the posts table.

```graphql
type Post @refersTo(name: "posts") @model {
id: String! @primaryKey
title: String!
content: String!
isPublished: Boolean @refersTo(name: "is-published")
publishedDate: AWSDate @refersTo(name: "published_date")
}
```

## Create relationships between models

You can use the `@hasOne`, `@hasMany`, and `@belongsTo` relational directives to create relationships between models. The field named in the `references` parameter of the relational directives must exist on the child model.

### Has One relationship

Create a one-directional one-to-one relationship between two models using the `@hasOne` directive.

In the example below, a User has a single Profile.

```graphql
type User
@refersTo(name: "users")
@model
@auth(rules: [{ allow: owner }, { allow: groups, groups: ["Admin"] }]) {
id: String! @primaryKey
name: String!
owner: String
profile: Profile @hasOne(references: ["userId"])
}
```

### Has Many relationship

Create a one-directional one-to-many relationship between two models using the `@hasMany` directive.

In the example below, a Blog has many Posts.

```graphql
type Blog @model {
id: String! @primaryKey
title: String!
posts: [Post] @hasMany(references: ["blogId"])
}

type Post @model {
id: String! @primaryKey
title: String!
content: String!
}
```

### Belongs To relationship

Make a "has one" or "has many" relationship bi-directional with the `@belongsTo` directive.

In the example below, a Post belongs to a Blog.

```graphql
type Post @model {
id: String! @primaryKey
title: String!
content: String!
blogId: String! @refersTo(name: "blog_id")
blog: Blog @belongsTo(references: ["blogId"])
}
```

## Auto-generate CRUDL operations for existing tables

<Callout>
Expand Down