From e5eedc7d02bcfbfcf57ffa4b3840575121d1355e Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Mon, 1 Jul 2024 08:49:44 -0600 Subject: [PATCH 1/6] add gen 2 SDL docs --- .../data/data-modeling/index.mdx | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index 607aa077d4c..f6cb0f0d76b 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -83,4 +83,38 @@ export const data = defineData({ }); ``` +GraphQL Schema Definition Language (SDL) may also be used to define your schema. +Doing so will not result in the same level of type safety offered by the data schema builder. +The data schema builder is the recommended method for defining your schema. + + + +**Note:** Some features available in Gen 1 GraphQL SDL are not available in Gen 2. + +* Use of `@manyToMany`. +* Use of `fields` argument on `@hasOne`, `@hasMany`, and `@belongsTo`. +* Use of `@hasOne`, `@hasMany`, and `@belongsTo` on required fields. + + + +```ts +import { defineData } from '@aws-amplify/backend'; + +const schema = ` + type Todo @model @auth(rules: [{ allow: owner }]) { + content: String + isDone: Boolean + } +`; +export const data = defineData({ + schema, + authorizationModes: { + defaultAuthorizationMode: "apiKey", + apiKeyAuthorizationMode: { + expiresInDays: 30, + }, + }, +}); +``` + From 6a3754f36348b082441d8ba952a1cb7f52fc7f6f Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Tue, 2 Jul 2024 10:25:37 -0600 Subject: [PATCH 2/6] Update src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx Co-authored-by: josef --- .../[platform]/build-a-backend/data/data-modeling/index.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index f6cb0f0d76b..ebbaf1a29a1 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -83,9 +83,7 @@ export const data = defineData({ }); ``` -GraphQL Schema Definition Language (SDL) may also be used to define your schema. -Doing so will not result in the same level of type safety offered by the data schema builder. -The data schema builder is the recommended method for defining your schema. +GraphQL Schema Definition Language (SDL) may also be used to define your schema. Doing so will not result in the same level of type safety offered by the data schema builder. The data schema builder is the recommended method for defining your schema. From 57a143cdb22cffad8f1b825fe8f5ae3b91bff714 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Tue, 2 Jul 2024 10:25:56 -0600 Subject: [PATCH 3/6] Update src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx Co-authored-by: josef --- .../[platform]/build-a-backend/data/data-modeling/index.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index ebbaf1a29a1..f49595e6e10 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -95,15 +95,16 @@ GraphQL Schema Definition Language (SDL) may also be used to define your schema. -```ts +```ts title="amplify/data/resource.ts" import { defineData } from '@aws-amplify/backend'; -const schema = ` +const schema = /* GraphQL */` type Todo @model @auth(rules: [{ allow: owner }]) { content: String isDone: Boolean } `; + export const data = defineData({ schema, authorizationModes: { From 3f287ee0599ac1ffdc28a261b36152c9aa2499d5 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Tue, 2 Jul 2024 10:46:38 -0600 Subject: [PATCH 4/6] move support callout to migration page --- .../build-a-backend/data/data-modeling/index.mdx | 6 +----- src/pages/[platform]/start/migrate-to-gen2/index.mdx | 12 +++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index f49595e6e10..7299f5a0b03 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -87,11 +87,7 @@ GraphQL Schema Definition Language (SDL) may also be used to define your schema. -**Note:** Some features available in Gen 1 GraphQL SDL are not available in Gen 2. - -* Use of `@manyToMany`. -* Use of `fields` argument on `@hasOne`, `@hasMany`, and `@belongsTo`. -* Use of `@hasOne`, `@hasMany`, and `@belongsTo` on required fields. +**Note:** Some features available in Gen 1 GraphQL SDL are not available in Gen 2. See the [feature matrix](/[platform]/start/migrate-to-gen2/#gen-1-vs-gen-2-feature-matrix) for features supported in Gen 2. diff --git a/src/pages/[platform]/start/migrate-to-gen2/index.mdx b/src/pages/[platform]/start/migrate-to-gen2/index.mdx index 41c660245c5..3338f48277b 100644 --- a/src/pages/[platform]/start/migrate-to-gen2/index.mdx +++ b/src/pages/[platform]/start/migrate-to-gen2/index.mdx @@ -41,7 +41,7 @@ The tables below present a feature matrix for Gen 1 customers who are considerin ### Auth | Feature | Gen 1 | Gen 2 | -|---|---|---| +|---|---|---| | Configure username | Yes | Yes with CDK | | Configure email | Yes | Yes | | Configure phone number | Yes | Yes | @@ -92,7 +92,7 @@ The tables below present a feature matrix for Gen 1 customers who are considerin | hasOne | Yes | Yes | | hasMany | Yes | Yes | | belongsTo | Yes | Yes | -| manyToMany | Yes | Yes | +| manyToMany | Yes | No | | default | Yes | Yes | | **auth - model level** | | | | auth - public - apiKey | Yes | Yes | @@ -143,6 +143,8 @@ The tables below present a feature matrix for Gen 1 customers who are considerin | Custom GraphQL Transformer plugins | Yes | No | | MySQL and PostgreSQL support | No | Yes | | In-IDE end-to-end type safety | No | Yes | +| @hasOne, @hasMany, and @belongsTo on required fields | Yes | No | +| fields argument on @hasOne, @hasMany, and @belongsTo | Yes | No | ### Storage @@ -200,7 +202,7 @@ The tables below present a feature matrix for Gen 1 customers who are considerin | Feature | Gen 1 | Gen 2 | -|---|---|---| +|---|---|---| | REST API| Yes| No | Analytics| Yes| Yes with custom CDK | Geo| Yes| Yes with custom CDK @@ -212,7 +214,7 @@ The tables below present a feature matrix for Gen 1 customers who are considerin | Feature | Gen 1 | Gen 2 | -|---|---|---| +|---|---|---| | REST API| Yes| Yes with custom CDK | Analytics| Yes| Yes with custom CDK | Geo| No| No @@ -224,7 +226,7 @@ The tables below present a feature matrix for Gen 1 customers who are considerin | Feature | Gen 1 | Gen 2 | -|---|---|---| +|---|---|---| | REST API| Yes| Yes with custom CDK | Analytics| Yes| Yes with custom CDK | Geo| Yes| Yes with custom CDK From 8f31e82d674a9829c67486671835f71d5dc34ff3 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Tue, 2 Jul 2024 10:57:24 -0600 Subject: [PATCH 5/6] update doc to state ddb-backed sources only --- .../[platform]/build-a-backend/data/data-modeling/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index 7299f5a0b03..40cc65e1c36 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -83,7 +83,7 @@ export const data = defineData({ }); ``` -GraphQL Schema Definition Language (SDL) may also be used to define your schema. Doing so will not result in the same level of type safety offered by the data schema builder. The data schema builder is the recommended method for defining your schema. +GraphQL Schema Definition Language (SDL) may also be used to define your schema for DynamoDB based data sources. Doing so will not result in the same level of type safety offered by the data schema builder. The data schema builder is the recommended method for defining your schema. From 08251e185832af3ee37f6d9ebe5ded3844aef757 Mon Sep 17 00:00:00 2001 From: Nikhil Swaminathan Date: Wed, 3 Jul 2024 13:29:48 -0700 Subject: [PATCH 6/6] made updates to the sdl explanation --- .../build-a-backend/data/data-modeling/index.mdx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx index 40cc65e1c36..2b4072013b8 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/index.mdx @@ -32,6 +32,7 @@ export function getStaticProps(context) { }; } +## Data modeling capabilities Every data model is defined as part of a data schema (`a.schema()`). You can enhance your data model with various fields, customize their identifiers, apply authorization rules, or model relationships. Every data model (`a.model()`) automatically provides create, read, update, and delete API operations as well as real-time subscription events. Below is a quick tour of the many functionalities you can add to your data model: @@ -83,7 +84,11 @@ export const data = defineData({ }); ``` -GraphQL Schema Definition Language (SDL) may also be used to define your schema for DynamoDB based data sources. Doing so will not result in the same level of type safety offered by the data schema builder. The data schema builder is the recommended method for defining your schema. + + +## Gen 1 schema support + +If you are coming from Gen 1, you can continue to use the GraphQL Schema Definition Language (SDL) for defining your schema. However, we strongly recommend you use the TypeScript-first schema builder experience in your project as it provides type safety and is the recommended way of working with Amplify going forward. @@ -111,5 +116,3 @@ export const data = defineData({ }, }); ``` - -