我在 JS 中将 GraphQL 与 Apollo Server 和 Client 一起使用,并尝试自省我的模式。
简化后,我有一个类似的架构:
input LocationInput {
lat: Float
lon: Float
}
input CreateCityInput {
name: String!
location: LocationInput
}
我用这样的内省来查询这个:
fragment InputTypeRef on __Type {
kind
name
ofType {
kind
name
inputFields {
name
type {
name
kind
ofType {
kind
name
inputFields {
name
type {
name
kind
}
}
}
}
}
}
}
query CreateCityInputFields {
input: __type(name: "CreateCityInput") {
inputFields {
name
description
type {
...InputTypeRef
}
}
}
}
结果我收到:
{
"data": {
"input": {
"inputFields": [
{
"name": "name",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"inputFields": null
}
}
},
{
"name": "location",
"description": "",
"type": {
"kind": "INPUT_OBJECT",
"name": "LocationInput",
"ofType": null
}
}
]
}
}
}
正如人们所看到的:lat并且lon失踪了。如果我在中设置LocationInput为 required ( location: LocationInput!),CreateCityInput我会收到缺少的latand lon。
我如何查询lat和lon没有LocationInput要求?