3

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.

peter flanagan
  • 9,195
  • 26
  • 73
  • 127

1 Answers1

1

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
    }
  }
}
peter flanagan
  • 9,195
  • 26
  • 73
  • 127