amplify-studio
amplify-studio copied to clipboard
Data modeling generates wrong schema
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
App Id
/dsuhzpzj2hmel/dev/datastore
Region
eu-central-1
Environment name
dev
Figma File Version (if applicable)
No response
Amplify CLI Version
10.6.1
If applicable, what version of Node.js are you using?
No response
What operating system are you using?
Mac
Browser type?
Safari
Describe the bug
I add three models idea, location, profile
Locations is 1:n relationship to profile and ideas, so one location can belong to many profiles and many ideas. If I create these relationships between the models in visual editor, the code generated for the graphql creates wrong code. This is the code generated
locationID: ID! @index(name: "byLocation")
location: Location @belongsTo(fields: ["locationID"])
profileID: ID! @index(name: "byProfile")
profile: Profile @belongsTo(fields: ["locationID"])
The last line contains the error.
Expected behavior
I would expect the following result
locationID: ID! @index(name: "byLocation")
location: Location @belongsTo(fields: ["locationID"])
profileID: ID! @index(name: "byProfile")
profile: Profile @belongsTo(fields: ["**profile**ID"])
Reproduction steps
Create three models Create two 1:n relationships in the visual editor Change to graphQL scheme
Project Identifier
No response
Additional information
Workaround is to create the file in visual editor, deploy it, fix it locally and push it back
It would also be good, if the relationship name suggestion would be lowercase, as the uppercase creates problems with dart models.
Hey @tbecker, thank you for reaching out. I was able to reproduce the issue. Marking this as bug.
Note: Steps to reproduce.
- create 3 models A, B and C
- A 1:n B
- A: 1:n C
- B 1:n C
- add C belongsTo A
- add C belongsTo B

observed:

Hi ykethan,
great. Please also note that the relationship names are all uppercase, which would create a problem in Flutter afterwards.
Am 10.01.2023 um 20:45 schrieb ykethan @.***>:
Hey @tbecker https://github.com/tbecker, thank you for reaching out. I was able to reproduce the issue. Marking this as bug.
Note: Steps to reproduce.
create 3 models A, B and C A 1:n B A: 1:n C B 1:n C add C belongsTo A add C belongsTo B https://user-images.githubusercontent.com/87995712/211647319-63df6985-8fad-410b-8be1-0babae6c4029.png observed:
https://user-images.githubusercontent.com/87995712/211647077-8cf95ceb-3a9d-420f-8e2d-a620284d8992.png — Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-studio/issues/788#issuecomment-1377762645, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEEN3QKVSBNCNQZPCSR33WRW33ZANCNFSM6AAAAAATWKU624. You are receiving this because you were mentioned.
Dr. Torsten Becker BESTgroup Consulting GmbH Zum Heckeshorn 42k 14109 Berlin Germany Phone +49 30 80401210 Mobile +49 171 443 1973 www.best-group.eu
@tbecker Could you please expand upon this:
great. Please also note that the relationship names are all uppercase, which would create a problem in Flutter afterwards.
I am seeing other issues with relationships with Pascal Case field names.
It would seem like Amplify studio is very broken.
I am also seeing this in the schema.graphql:
type Organisation @model @auth(rules: [{allow: public, operations: [read]}]) {
id: ID!
Name: String!
ParentOrg: ID
CSSPath: String
LogoPath: String
IconPat: String
Assets: [Asset] @hasMany(indexName: "byOrganisation", fields: ["id"])
S3LocationURL: AWSURL
Listings: [Asset] @hasMany(indexName: "byOrganisation", fields: ["id"])
Bookings: [Asset] @hasMany(indexName: "byOrganisation", fields: ["id"])
}
I am logging separate issues now for these. but your comment above seemed interesting so I would like to understand the technical constraints. as they are poorly/not documented.
"great. Please also note that the relationship names are all uppercase, which would create a problem in Flutter afterwards."
Dart (the language in Flutter) expect lower case first letter for variables, and the relation would be a variable....
@tbecker, Sorry I should have been more specific What does dart & flutter have to do with it?
How do they relate to Amplify.?
I have used Amplify in a flutter application.
OK, so that is a great point, the schema should really be cross-framework capable. multiple front ends capable.
I am now looking for a new Platform Amplify is really f'd me.
Hi @ykethan, This document is not very explanatory, is there any better explanations of GraphQL for Amplify?: https://docs.amplify.aws/cli/graphql/data-modeling/#setup-database-tables
I am unable to fix my issues. So to proceed I will have to start again from scratch (again!) with a whole new app and a new schema. To deploy an updated schema with --destructive-changes over the existing broken one the deployment is lengthy and just fails:
2023-09-28T01:01:29.736Z [INFO]: [K 2023-09-28T01:01:29.738Z [INFO]: Rolled back (6 of 5) 2023-09-28T01:01:29.738Z [WARNING]: ✖ There was an error initializing your environment. 2023-09-28T01:01:29.739Z [INFO]: 🛑 ["Index: 4 State: {"deploy":"waitingForDeployment"} Message: Resource is not in the state stackUpdateComplete"] Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/ 2023-09-28T01:01:29.784Z [INFO]:
I will test amplify on a few common scenarios before I start again properly.
I just built a new app with new data model with a few relatioship between tables.
I deployed it in Amplify Studio. Result: Data Model gone!
What on earth is going on?
Hey @qwikag, sorry to hear about your experience on this. Amplify uses a file called deployment-state.json to maintain deployment state of a push. It appears the file may have not been cleaned on a previous deploy or push. To mitigate the issue we will need to delete this file from the S3 bucket and redo the push. The issue is currently being tracked on https://github.com/aws-amplify/amplify-category-api/issues/940
Additionally, the newly created application on studio was the data modelling page greyed out and does the screen show the schema? if not was there a deployment failure or was the page refreshed? On a deployment failure Amplify Studio reverts back to a last know good state which may have removed the changes in your data modelling. Amplify Studio is currently actively tracking this behavior. The issue open on https://github.com/aws-amplify/amplify-studio/issues/787
@ykethan, I believe your last point is most accurate...
if not was there a deployment failure or was the page refreshed? On a deployment failure Amplify Studio reverts back to a last know good state which may have removed the changes in your data modelling. Amplify Studio is currently actively tracking this behavior. The issue open on https://github.com/aws-amplify/amplify-studio/issues/787
- brand new app
- brand new schema designed instudio
- deploy
- gone!
no schema completely gone. but because it took an hour, and the logs showed nothing during deployment. I assumed the browser had timedout, on amplify/dynamodb end failed and it never started the deploy and then I refreshed the page and it was back to square one.
So something in the deployment failed as you suggested.
I tried again moments later and it deployed.
But fundamenatally the Studio built relational datamodels are very very broken when designed in Studio. to those watching attempt with caution because if it is built wrong then you may have to start again I have an open case for this via support. better approach is deliver your schema via CLI (schema.graphql)