通过如下所示的 GraphQL 自省查询,我获取了 GraphQL 模式的突变类型的所有字段名称。此外,我想获取参数及其类型。我怎样才能额外查询这些?
query {
__schema {
mutationType {
name
fields {
name
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
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
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
阅读GraphQL 规范。找出可以内省的类型确实很有帮助。
递归ofType对于“解开”任何包装器类型(即列表和非空)是必要的。您可以在此处查看“完整”内省查询的示例。您还可以使用 Graph i QL 或 GraphQL Playground 的自动完成功能来帮助您编写此类查询。
| 归档时间: |
|
| 查看次数: |
4943 次 |
| 最近记录: |