简体   繁体   English

GraphQL / graphcool-关系突变

[英]GraphQL/graphcool - Mutation for relation

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 . 我正在遵循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. 您需要创建一个球员和一个团队,然后使用它们的ID来创建两者之间的关系。

mutation{
  addToTeamPlayers(
    playersPlayerId:"cjcabmoecfadx0199k5kqfpjp" 
    teamTeamId: "cjc8up2mie32h015280wkqmdy"
  ) {
    playersPlayer {
      name
    }
    teamTeam {
      name
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM