我在Prisma服务器上的类型定义为Device
type Device {
id: ID! @unique
type: DeviceType
settings: Json
}
但是在我的网关上,我想将字段设置解析为实际的联合类型
# import Node from './generated/prisma.graphql'
type MobileSettings {
firmware: String
}
type DesktopSettings {
os: String
}
union Settings = MobileSettings | DesktopSettings
type Device implements Node {
id: ID!
type: DeviceType
settings: Json
}
type Query {
devices: [Device]
node(id: ID!): Node
}
如果我在Device.settings
字段上添加了自定义解析器,则获取所有设备的初始查询仍会尝试检索设置字段。
如何将Json字段解析为实际的联合类型?
答案 0 :(得分:0)
我认为您忘记在架构中使用Settings
类型:
# import Node from './generated/prisma.graphql'
type MobileSettings {
firmware: String
}
type DesktopSettings {
os: String
}
union Settings = MobileSettings | DesktopSettings
type Device implements Node {
id: ID!
type: DeviceType
settings: Settings # <-- Here
}
type Query {
devices: [Device]
node(id: ID!): Node
}