【发布时间】:2018-06-24 13:04:17
【问题描述】:
我正在使用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
}
}
谁能告诉我如何避免这个问题并将Players 添加到同一个Team?
【问题讨论】:
标签: javascript graphql graphcool