内省时获取必填字段/非null字段

问题描述 投票:0回答:1

我正在使用自省来查询InputType,以一般性地创建用于更改实体的表单。

query introspection($updateInputName: String!) {
  __type(name: $updateInputName) {
    inputFields {
      name
      type {
        name
        kind
        ofType {
          kind
          name
        }
      }
    }
  }
}

据我了解,type.kind信息对于必需/非空字段应该返回NON_NULL。但是我收到了SCALAR,...

如何获取有关查询的inputField的必填字段的信息?

graphql
1个回答
0
投票

kind字段确实可以解析为NON_NULL,如果该字段不可为空。如果看到SCALAR,则该字段为空。

这是包装器类型的每种组合的内省结果的外观:

Int

"type": {
  "name": "Int",
  "kind": "SCALAR",
  "ofType": null
}

Int!

"type": {
  "name": null,
  "kind": "NON_NULL",
  "ofType": {
    "name": "Int",
    "kind": "SCALAR",
    "ofType": null
  }
}

[Int!]

"type": {
  "name": null,
  "kind": "LIST",
  "ofType": {
    "name": null,
    "kind": "NON_NULL",
    "ofType": {
      "name": "Int",
      "kind": "SCALAR",
      "ofType": null
    }
  },

}

[Int!]!

"type": {
  "name": null,
  "kind": "NON_NULL",
  "ofType": {
    "name": null,
    "kind": "LIST",
    "ofType": {
      "name": null,
      "kind": "NON_NULL",
      "ofType": {
        "name": "Int",
        "kind": "SCALAR",
        "ofType": null
      }
    },
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.