【发布时间】:2021-05-16 11:02:52
【问题描述】:
我有如下查询
query MyQuery($id: ID!) {
something(id: $id) {
details {
id
name
}
}
}
在 types.graphql 我有
type something {
details: // this should either type details1 or type details2
}
type details1 {
id: string
name: string
description: string
}
type details2 {
id: string
name: string
description: string
other: string!
}
所以类型详细信息可以是类型 details1 或 details2
如何在 type something for details 字段中指定它。
有人可以帮我解决这个问题吗?谢谢。
编辑:
我尝试过类似下面的方法
type something {
details : details1 | details2;
}
但这不起作用。
我能做的就是创造另一种类型
type details3 {
id: string
name: string
description: string
other: string
}
这是 details2 和 details3 的组合
并像使用它
type something {
details: details3
}
但不想这样做。
【问题讨论】:
标签: reactjs typescript graphql