I am having difficulties figuring out how to make a relation mutation using graph cool.
My schema looks like this:
type Team @model {
id: ID! @isUnique
name: String
players: [Player!]! @relation(name: "TeamPlayers")
}
type Player @model {
id: ID! @isUnique
name: String
team: Team @relation(name: "TeamPlayers")
}
I am trying to then add a player to a team. I have written my mutation like the following but it isn't working.
mutation {
addToTeamPlayers(id: "cjc8up2mie32h015280wkqmdy") {
playersPlayer(name: "Jimmy") {
name
}
}
}
I am not finding the docs particularly helpful for this type of mutation. Can anyone advise how to do this? I am following this section of the docs .
I figured out the answer. You need to create a player and a team and then you use the ids of each to create the relationship between the two.
mutation{
addToTeamPlayers(
playersPlayerId:"cjcabmoecfadx0199k5kqfpjp"
teamTeamId: "cjc8up2mie32h015280wkqmdy"
) {
playersPlayer {
name
}
teamTeam {
name
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.