使用如下所示的GraphQL自省查询,我获得了GraphQL模式的突变类型上的所有字段名称。另外,我想获取参数及其类型。我又如何查询这些?
query {
__schema {
mutationType {
name
fields {
name
}
}
}
}
query {
__schema {
mutationType {
name
fields {
name
args {
name
defaultValue
type {
...TypeRef
}
}
}
}
}
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
递归ofType
对于“解包”任何包装类型(例如List和Non-Null)是必要的。您可以在here中查找“完整”自省查询的示例。您还可以使用Graph i QL或GraphQL Playground的自动完成功能来帮助您编写这类查询。