【问题标题】:graphql: adding a field to a join tablegraphql:将字段添加到连接表
【发布时间】:2018-09-16 18:50:36
【问题描述】:

我有两组具有以下架构的记录

type Player {
    id: ID! @unique
    name: String!
    links: [NPC!]! @relation(name: 'linkedNpcs')
}

type NPC {
        id: ID! @unique
        name: String!
        playerLinks: [Player!]! @relation(name: 'linkedNpcs')
}

我想向linkedNpcs 添加一个名为relationType 的附加字段。

如何在我的types.graphql 文件中写入此内容?每个player-npc 链接都应该包含一个唯一的记录,并且由于它是多对多的关系,所以这个元数据应该存在于连接表上是有意义的。

【问题讨论】:

    标签: graphql graphql-js apollo-server graphcool


    【解决方案1】:

    通过 graphcool 论坛回答:https://www.graph.cool/forum/t/adding-a-field-to-a-relation-table-in-prisma/3086/2

    感谢@matic!

    enum RelationType {
      A
      B
      C
    }
    
    type Player {
      id: ID! @unique
      name: String!
      links: [PlayerNPC!]! @relation(name: 'linkedPlayer')
    }
    
    type PlayerNPC {
      id: ID! @unique
    
      relationType: RelationType!
    
      player: Player! @relation(name: 'linkedPlayer')
      npc: NPC! @relation(name: 'linkedNPC')
    }
    
    type NPC {
      id: ID! @unique
      name: String!
      links: [PlayerNPC!]! @relation(name: ‘linkedNPC’)
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-13
      • 1970-01-01
      • 2018-06-02
      • 2021-06-19
      • 2018-12-07
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多