我正在通过 GraphQL 从数据库中获取数据。有两种类型:Group
和Person
。组有一个字段people
,它是一个Person
对象列表。
我正在尝试使用 GraphQL 的内置introspection从服务器获取模式。我遇到的问题是该people
字段是一个不可为空的类型,它包含一个包含一个不可为空类型的列表类型,我必须使用这个冗长的查询:
{
__type(name: "Group") {
name
fields {
name
type {
name
kind
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
要获取此架构:
{
"data": {
"__type": {
"name": "Group",
"fields": [
{
"name": "people",
"type": {
"name": null,
"kind": "NON_NULL",
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Person",
"ofType": null
}
}
}
}
}
]
}
}
}
除了不方便且难以阅读的查询之外,它不是通用的,我必须知道架构中包装器类型的最大深度才能构造它。
有没有办法在模式中获取所有包装器类型,无论深度如何?