带有变异图的重复项 cool / graphql

duplicated items with mutation graph cool / graphql

我正在使用 graphcool / graphql 并想将 Player 添加到 Team。我的架构如下所示:

type Team @model {
  id: ID! @isUnique
  name: String
  players: [Player!]! @relation(name: "TeamPlayers")
  fixtures: [Fixture!]! @relation(name: "TeamFixtures")
  results: [Result!]! @relation(name: "TeamResults")
}

type Player @model {
    id: ID! @isUnique
    name: String!
    gamesPlayed: Int!
    goalsScored: Int!
    yellowCards: Int!
    redCards: Int!
    photo: String!
    team: Team! @relation(name: "TeamPlayers")
}

我正在进行以下修改:

mutation {
      createPlayer(
      name: "Peter Flanagan",
      gamesPlayed: 1,
      yellowCards: 0,
      redCards: 1,
      goalsScored: 4,
      photo: "http://cdn2-www.craveonline.com/assets/uploads/2017/02/bret1.png",
      team: {
        name: "Man United"
      }
    ) {
        id
      }
}

这按预期工作,但如果我进行另一个突变,如下图所示,第二个团队,也称为 Man United 和一个新的 id

mutation {
      createPlayer(
      name: "Eric Cantona",
      gamesPlayed: 1,
      yellowCards: 0,
      redCards: 1,
      goalsScored: 4,
      photo: "http://cdn2-www.craveonline.com/assets/uploads/2017/02/bret1.png",
      team: {
        name: "Man United"
      }
    ) {
        id
      }
}

谁能告诉我如何避免这个问题并将两个 Player 添加到同一个 Team

这样,您总是在创建新的 Player 的同时创建新的 Team。如果你想将玩家连接到团队。先创建team,得到teamId。使用 teamId 然后你可以像这样创建连接到团队的突变:

mutation {
  createPlayer(
  name: "Peter Flanagan",
  gamesPlayed: 1,
  yellowCards: 0,
  redCards: 1,
  goalsScored: 4,
  photo: "http://cdn2-www.craveonline.com/assets/uploads/2017/02/bret1.png",
  teamId: "TEAM_ID"
) {
    id
  }
}