LoginSignup
0
0

More than 3 years have passed since last update.

【Amplify】graphqlでid以外を指定してupdateできるようにschemeを編集する

Posted at

解決策

player というtypeを用いroomIdが一致するデータのみ更新する例をあげる。
scheme の type と key を下記のように編集する


type Player 
@model(subscriptions:{ onCreate:["onCreatePlayer"], onDelete:["onDeletePlayer"],onUpdate: ["onUpdatePlayer","onUpdatePlayerByRoomId(roomId:String!)"]})
@key(name: "byRoomId", fields: ["roomId", "id"], queryField: "getPlayerByRoomId")
{
  id: ID
  userId: String
  roomId: String
  userName: String
}

その後生成されるAPIを使ってこう叩く

 await API.graphql(
    graphqlOperation(updatePlayer, { input: newPlayers })
 );

result に入れることで更新後の結果を取得することもできる。

const result = await API.graphql(
    graphqlOperation(updatePlayer, { input: newPlayers })
 );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0