Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen 1 to Gen 2 Migration - Schema Usage #3102

Open
sajithkumarsb opened this issue Jan 2, 2025 · 2 comments
Open

Gen 1 to Gen 2 Migration - Schema Usage #3102

sajithkumarsb opened this issue Jan 2, 2025 · 2 comments
Labels
pending-maintainer-response Issue is pending a response from the Amplify team. question Further information is requested

Comments

@sajithkumarsb
Copy link

Amplify CLI Version

v12.13.1

Question

I want to migrate my Gen 1 app to a Gen 2 app, and I wish to reuse my existing Gen 1 GraphQL Schema (SDL) in Gen 2 . My Gen 1 schema includes features such as @model queries, mutations, subscriptions, directives like @hasone, @hasmany, and @belongsTo on required fields, as well as many-to-many relationships. However, according to the Gen 2 documentation and the Gen 1 vs. Gen 2 feature matrix, these features are not supported in Gen 2.

My questions are:
Is there any way to combine both Gen 1 and Gen 2 schemas to make them usable in Gen 2?
What alternative approaches are available to implement the above features in Gen 2?

Documents referred :
Gen 1 schema support: https://docs.amplify.aws/react/build-a-backend/data/data-modeling/#gen-1-schema-support
Gen 1 vs. Gen 2 feature matrix : https://docs.amplify.aws/react/start/migrate-to-gen2/#gen-1-vs-gen-2-feature-matrix

@sajithkumarsb sajithkumarsb added pending-triage question Further information is requested labels Jan 2, 2025
@dpilch
Copy link
Member

dpilch commented Jan 2, 2025

  1. It is not possible to combine a string SDL schema and schema from the data schema builder at this time. If you use only a string SDL schema (as you linked here) you will be able to use the unsupported Gen 1 features in your Gen 2 app (it will just print a warning until the next major version release). At this time I would recommend that you modify your schema in your Gen 1 app to be compatible with your Gen 2 app.
  2. Required relational fields will not be possible in Gen 2. For many to many relationship you will need to create a join model https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-many-to-many-relationship.

However, if you recreate your app in Gen 2 your data will not be copied over automatically and you will need to implement your own replication if you go this route.

We are planning to release official migration support in the future that will replicate your data in the Gen 2 app automatically.

@AnilMaktala AnilMaktala added pending-community-response Issue is pending a response from the author or community. and removed pending-triage labels Jan 2, 2025
@sajithkumarsb
Copy link
Author

sajithkumarsb commented Jan 3, 2025

  1. It is not possible to combine a string SDL schema and schema from the data schema builder at this time. If you use only a string SDL schema (as you linked here) you will be able to use the unsupported Gen 1 features in your Gen 2 app (it will just print a warning until the next major version release). At this time I would recommend that you modify your schema in your Gen 1 app to be compatible with your Gen 2 app.
  2. Required relational fields will not be possible in Gen 2. For many to many relationship you will need to create a join model https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-many-to-many-relationship.

However, if you recreate your app in Gen 2 your data will not be copied over automatically and you will need to implement your own replication if you go this route.

We are planning to release official migration support in the future that will replicate your data in the Gen 2 app automatically.

Thank you for the clarfication. I also want to know about the filed level querying in gen 2.

Example :

I have a model Tenant in gen 1 with the field logoImage how to achieve this in gen 2.

type Tenant
@model(subscriptions: null, mutations: {create: null}
logoImage: ImageUploadS3Object
@function(name: "MainCoreResolvers-${env}")
@auth(rules: [{ allow: groups, groupsField: "id" }])
}

What i have done in gen 2  (In this getting a typescript error )

Tenant: a.model({
logoImage: a.query(a.ref(ImageUploadS3Object))..authorization((allow) => 

[allow.groupDefinedIn("id")])).handler(a.handler.custom({ entry: "../resolvers/tenant/logo-image.ts", dataSource:
a.ref("ImageUploadS3Object") })), })

ImageUploadS3Object: a.customType({ url: a.string(), uploadUrl: a.url() })

@github-actions github-actions bot added pending-maintainer-response Issue is pending a response from the Amplify team. and removed pending-community-response Issue is pending a response from the author or community. labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-maintainer-response Issue is pending a response from the Amplify team. question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants