放大模式抱怨,因为参数类型不是 'List<UserWallet>?'
Amplify Schema complains because argument type is not 'List<UserWallet>?'
我正在尝试使用 DataStore 在本地添加新数据,这是我遇到的错误:
Cannot convert value of type 'User' to expected argument type 'List<UserWallet>?'
我定义了以下架构(用户和钱包之间的多对多):
type Wallet @model @auth(rules: [{allow: public}]) {
id: ID!
address: String
users: [UserWallet] @connection(keyName: "byWallet", fields: ["id"])
}
type User @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
UserWallets: [UserWallet] @connection(keyName: "byUser", fields: ["id"])
}
type UserWallet @model(queries: null) @key(name: "byUser", fields: ["userID", "walletID"]) @key(name: "byWallet", fields: ["walletID", "userID"]) @auth(rules: [{allow: public}, {allow: public}]) {
id: ID!
userID: ID!
walletID: ID!
user: User! @connection(fields: ["userID"])
wallet: Wallet! @connection(fields: ["walletID"])
}
我正在尝试在 official docs 之后添加一些数据,所以我尝试了这个:
let newUser = User(name: "Arturo")
let newWallet = Wallet(address: "0xewefwef32", users: newUser)
Amplify.DataStore.save(newUser) { userResult in
switch userResult {
case .failure(let error):
print("Error adding post - \(error.localizedDescription)")
case .success:
Amplify.DataStore.save(newWallet) { newWalletResult in
switch newWalletResult {
case .success:
print("User saved!")
case .failure(let error):
print("Error adding newWallet - \(error.localizedDescription)")
}
}
}
}
但是我收到上面的错误。是什么让这个过程失败了?
谢谢
经过大量的时间我找到了答案,它正在寻找模式关系名称,在本例中我将其命名为 wallet,天哪...无论如何,这是万一有人遇到的解决方案同样的问题:
let newWallet = Wallet(address: "0xewefwef32", user: newUser.wallet)
注意最后的 newUser.wallet。那是棘手的部分:)
我正在尝试使用 DataStore 在本地添加新数据,这是我遇到的错误:
Cannot convert value of type 'User' to expected argument type 'List<UserWallet>?'
我定义了以下架构(用户和钱包之间的多对多):
type Wallet @model @auth(rules: [{allow: public}]) {
id: ID!
address: String
users: [UserWallet] @connection(keyName: "byWallet", fields: ["id"])
}
type User @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
UserWallets: [UserWallet] @connection(keyName: "byUser", fields: ["id"])
}
type UserWallet @model(queries: null) @key(name: "byUser", fields: ["userID", "walletID"]) @key(name: "byWallet", fields: ["walletID", "userID"]) @auth(rules: [{allow: public}, {allow: public}]) {
id: ID!
userID: ID!
walletID: ID!
user: User! @connection(fields: ["userID"])
wallet: Wallet! @connection(fields: ["walletID"])
}
我正在尝试在 official docs 之后添加一些数据,所以我尝试了这个:
let newUser = User(name: "Arturo")
let newWallet = Wallet(address: "0xewefwef32", users: newUser)
Amplify.DataStore.save(newUser) { userResult in
switch userResult {
case .failure(let error):
print("Error adding post - \(error.localizedDescription)")
case .success:
Amplify.DataStore.save(newWallet) { newWalletResult in
switch newWalletResult {
case .success:
print("User saved!")
case .failure(let error):
print("Error adding newWallet - \(error.localizedDescription)")
}
}
}
}
但是我收到上面的错误。是什么让这个过程失败了?
谢谢
经过大量的时间我找到了答案,它正在寻找模式关系名称,在本例中我将其命名为 wallet,天哪...无论如何,这是万一有人遇到的解决方案同样的问题:
let newWallet = Wallet(address: "0xewefwef32", user: newUser.wallet)
注意最后的 newUser.wallet。那是棘手的部分:)