graphql:将字段添加到联接 table
graphql: adding a field to a join table
我有两组具有以下架构的记录
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
link 应该包含一个唯一的记录,因为它是一个多对多的关系,所以这个元数据应该存在于连接 table.
上是有道理的
通过 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’)
}
我有两组具有以下架构的记录
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
link 应该包含一个唯一的记录,因为它是一个多对多的关系,所以这个元数据应该存在于连接 table.
通过 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’)
}