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

Data modeling generates wrong schema #788

Open
4 tasks done
tbecker opened this issue Jan 10, 2023 · 12 comments
Open
4 tasks done

Data modeling generates wrong schema #788

tbecker opened this issue Jan 10, 2023 · 12 comments
Labels
bug An issue which has been identified as a bug data Data modelling studio-ui An issue that needs to be tracked by Studio Console team

Comments

@tbecker
Copy link

tbecker commented Jan 10, 2023

Before opening, please confirm:

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.

@tbecker tbecker added the pending-triage An issue that is pending triage label Jan 10, 2023
@ykethan
Copy link
Member

ykethan commented Jan 10, 2023

Hey @tbecker, thank you for reaching out. I was able to reproduce the issue. Marking this as bug.

Note: Steps to reproduce.

  1. create 3 models A, B and C
  2. A 1:n B
  3. A: 1:n C
  4. B 1:n C
  5. add C belongsTo A
  6. add C belongsTo B

image

observed:

image

@ykethan ykethan added bug An issue which has been identified as a bug studio-backend An issue that needs to be tracked by Studio Backend team data Data modelling and removed pending-triage An issue that is pending triage labels Jan 10, 2023
@tbecker
Copy link
Author

tbecker commented Jan 10, 2023 via email

@ykethan ykethan changed the title Amplify Studio Data modeling Data modeling generates wrong schema Feb 10, 2023
@murali-j-99 murali-j-99 added studio-ui An issue that needs to be tracked by Studio Console team and removed studio-backend An issue that needs to be tracked by Studio Backend team labels Jul 6, 2023
@qwikag
Copy link

qwikag commented Sep 27, 2023

@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.

@tbecker
Copy link
Author

tbecker commented Sep 27, 2023

"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....

@qwikag
Copy link

qwikag commented Sep 27, 2023

@tbecker,
Sorry I should have been more specific
What does dart & flutter have to do with it?

How do they relate to Amplify.?

@tbecker
Copy link
Author

tbecker commented Sep 27, 2023

I have used Amplify in a flutter application.

@qwikag
Copy link

qwikag commented Sep 27, 2023

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.

1044
1045

@qwikag
Copy link

qwikag commented Sep 27, 2023

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

@qwikag
Copy link

qwikag commented Sep 28, 2023

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.

@qwikag
Copy link

qwikag commented Sep 28, 2023

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?

@ykethan
Copy link
Member

ykethan commented Sep 28, 2023

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 aws-amplify/amplify-category-api#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 #787

@qwikag
Copy link

qwikag commented Sep 29, 2023

@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 #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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue which has been identified as a bug data Data modelling studio-ui An issue that needs to be tracked by Studio Console team
Projects
None yet
Development

No branches or pull requests

4 participants