我试图用graphql获取一个坐标数组。我使用的继电器,猫鼬,和涂鸦猫鼬产生graphql类型从这些猫鼬模型:Graphql查询数组
// Geometry
const GeometrySchema = new mongoose.Schema({
type: { type: String },
coordinates: [ Number ]
}, { _id: false });
// Country
const CountrySchema = new mongoose.Schema({
code: String,
name: String,
dictionary: [ { _id: false, value: String } ],
language: [ { _id: false, code: String, name: String } ],
loc: { type: { type: String }, geometries: [ GeometrySchema ] },
creationDate: Date,
modifiedDate: Date
});
const Country = mongoose.model('Country', CountrySchema);
这里的产生graphql(graphql /公共事业):
type Country implements Node {
code: String
name: String
dictionary: [CountryDictionary]
language: [CountryLanguage]
loc: [CountryLoc]
creationDate: Date
modifiedDate: Date
_id: ID
id: ID!
}
type CountryConnection {
pageInfo: PageInfo!
edges: [CountryEdge]
count: Float
}
type CountryDictionary {
_id: Generic
value: String
}
input CountryDictionaryInput {
_id: Generic
value: String
}
type CountryEdge {
node: Country
cursor: String!
}
type CountryLanguage {
_id: Generic
code: String
name: String
}
input CountryLanguageInput {
_id: Generic
code: String
name: String
}
type CountryLoc {
type: String
coordinates: [Float]
}
input CountryLocInput {
type: String
coordinates: [Float]
}
使用graphiql我能得到这个国家的名称:
{
country(id:"57b48b73f6d183802aa06fe8"){
name
}
}
我该如何检索loc信息?
你尝试了'{ 国家(ID: “57b48b73f6d183802aa06fe8”){ 名 禄{ 坐标 }} } ' ? –
是的我尝试,我得到这个回应: { “statusCode”:400, “error”:“Bad Request”, “message”:“期望的Iterable,但没有找到一个字段Country.loc。” } – ric
这意味着,问题与服务器端实现有关。检查是否在服务器端正确返回了一组坐标。 –