Closed hisstoryxx closed 2 years ago
@hisstoryxx you have circular references here. DataStore does not currently support this. I believe removing the additional relationship from User to Message should clean this up for you. Please let me know if you have issues after.
If you've already added data and made fields required, this will break DataStore. You'll want to remove the required relationships and deploy, then clean up the data.
Running a schema like this will give you the relationships you're looking for. Ran a quick test to validate, but let me know if you're still experiencing issues.
@AechDub
I am testing with your schema....
But, BTW is there no way using m:n relationships??
There are, but using them in conjunction with 1:n relationships on the same model can cause issues with DataStore if you create a circular reference. Happy to sync up and chat through the use case here and get some data to take to the team.
@AechDub
OK.
I understood your meaning.
The Thing is that I build backend server and also front app using that schema(which is I suggest). And It worked well at that time.
However, It does not work now.
Then. what can I do now is re-design structures, right?
If you've already added data and made fields required, this will break DataStore. You'll want to remove the required relationships and deploy, then clean up the data.
Running a schema like this will give you the relationships you're looking for. Ran a quick test to validate, but let me know if you're still experiencing issues.
I need ChatRoomUser model!!
Hi @hisstoryxx,
Is your chatroomID
marked as required in the Message
model ? If so, can you uncheck it ? I was able to add Content to the above schema by not having chatroomID
required.
@abhi7cr hello~ are you saying in schema (I proposed at first) ??
Yea the same schema, I had the chatroomID not marked as required, can you check if you have chatroomID marked as required ? If it’s marked as required, uncheck it to make it optional and deploy it. I was able to reproduce the issue when I marked the chatroomID field as required.
@abhi7cr
no chatroomID is set to not required
The point is that if I add m:n relationships between ChatRoom and User, I can not see content tab in amplify studio. also server doesn't work.
Just copy the code the folder as the link to your project. Then use "amplify push" command in the console in the project path.
link source code: https://github.com/Savinvadim1312/SignalClone/tree/main/src/models
@togenius1
it doesn't help because if I add other data model or add lambda functions(post confirmation, post authentication ...) then I could not use content tab and also server!!
I just wish aws amplify team fix this bug ASAP.
this is deployment status after only build data model
@hisstoryxx
Sorry for this inconvenience. We will investigate the deployment error you are seeing. In the meantime, can you please post a screenshot of your dev console when the Content page is loaded?
@hisstoryxx Moving conversation to this issue from https://github.com/aws-amplify/amplify-adminui/issues/396.
Thank you, I received the invite. I see the following errors thrown by Datastore when trying to initialize your schema:
Validation error of type FieldUndefined: Field 'chatroom' in type 'ChatRoomUser' is undefined @ 'onUpdateChatRoomUser/chatroom'
These are related to the ChatRoomUser model, so it makes sense why the Content page is failing to load only when you add the m:n. We will dig into this further and get back to you ASAP.
For now, can you please clarify if you have any records successfully written to DynamoDB for these models? Specifically to the ChatRoomUser model.
@yppartyk First of all, thank you for your quick response. Im really looking forward to getting an answer from the amazon team. Yes, I added test item in ChatRoomUser table a few minutes ago.
@yppartyk And this is the one that the update(amplify updates) before
@hisstoryxx
From the error you are seeing, it seems like the field chatroom
is not defined on the ChatRoomUser model in AppSync.
I recreated your schema, deployed, and the Content tab works as expected for me. Looking at the ChatRoomUser model in AppSync Console, I see that chatRoom
is defined:
@aws_api_key {
id: ID!
chatRoomID: ID!
userID: ID!
chatRoom: ChatRoom!
user: User!
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
_version: Int!
_deleted: Boolean
_lastChangedAt: AWSTimestamp!
}
Can you please check your API in the AppSync Console?
ChatRoomUser
modelchatRoom
is defined as a field on the model@yppartyk Yes I checked chatRoom is defined well,, But the content tab is still not working(maybe if network disconnected then open the browser, the content tab looks like working. However, if refresh it, you can only see the error screen like below.)
@yppartyk I found a solution.!! I think that the Building data model using Amplify studio is not stable yet. So, I build my data model in amplify CLI. The Below code is mine and I will open code for you who need m:n relationships. @manyToMany is not work so should use @hasmany & @belongsTo and also the connected with @belongTo item be not required status.
Now I can use content Tab and server with no error.
`type ChatRoomUser @model @auth(rules: [{allow: public}]) { id: ID! chatroomID: ID @index(name: "byChatRoom") userID: ID @index(name: "byUser") chatroom: ChatRoom @belongsTo(fields: ["chatroomID"]) user: User @belongsTo(fields:["userID"]) }
type ChatRoom @model @auth(rules: [{allow: public}]) { id: ID! newMessages: String LastMessage: Message @hasOne Messages: [Message] @hasMany(indexName: "byChatRoom", fields: ["id"]) ChatRoomUsers: [ChatRoomUser] @hasMany(indexName: "byChatRoom", fields: ["id"]) }
type Message @model @auth(rules: [{allow: public}]) { id: ID! chatroomID: ID @index(name: "byChatRoom") userID: ID @index(name: "byUser") }
type User @model @auth(rules: [{allow: public}]) { id: ID! name: String! status: String Messages: [Message] @hasMany(indexName: "byUser", fields: ["id"]) ChatRoomUsers: [ChatRoomUser] @hasMany(indexName: "byUser", fields: ["id"]) }`
@hisstoryxx the manyToMany
directive was released as part of the new GraphQL Transformer v2 in the Amplify CLI. It is stable both in the CLI and Amplify Studio. One of its use cases is that it abstracts away the join table in m:n relationships so you don't have to explicitly define it in your schema. Before Transformer v2 was released, you had to explicitly define the join table and create 1:n relationships from each of the models in the m:n to the join table. The solution that you came up with is basically using that previous strategy but with Transformer v2 hasMany
directives. I am happy to hear that it works for you. Closing this issue, but feel free to re-open if you experience any other problems.
@yppartyk When I follow many to many tutorials in https://docs.amplify.aws/console/data/relationships/#model-data-for-a-one-to-many-relationship (between Author and book), I can not see content tab.
Also, when I build just simple data model on Ampilfy studio( only build m:n relationship between A and B) It doesn't work in content tab
If it's not an excuse, could you please test it? please
Before opening, please confirm:
App Id
d22mbikv8c429q
Region
ap-northeast-2
Environment name
macMdoc
Amplify CLI Version
No response
If applicable, what version of Node.js are you using?
14
What operating system are you using?
Mac
Browser type?
chrome
Describe the bug
After I made app and build data model like this with m:n relationships then I couldn't open content tap. if I delete m:n relationship between ChatRoom and User. It is working. what is wrong??
Expected behavior
please fix the bug
Reproduction steps
Additional information
When I run the vscode attached this amplify backend and save Datastore the error console saying