Reputation: 626
I'm using an introspection to query InputTypes to generically create a form to alter an entity.
query introspection($updateInputName: String!) {
__type(name: $updateInputName) {
inputFields {
name
type {
name
kind
ofType {
kind
name
}
}
}
}
}
As far as I understood the type.kind information should return NON_NULL for required/non-null fields. But I receive SCALAR, ...
How can I get the information about the required fields of the queried inputField?
Upvotes: 1
Views: 532
Reputation: 84697
The kind
field will indeed resolve to NON_NULL
if the field is non-nullable. If you are seeing SCALAR
, then the field is nullable.
Here's how an introspection result would look like for each combination of wrapper types:
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
}
},
}
}
Upvotes: 3