0

我正在尝试使用 graphql 获取坐标数组。我正在使用 relay、mongoose 和 graffiti-mongoose 从这些 mongoose 模型中生成 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/utilities):

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 信息?

4

2 回答 2

0

根据您的架构,查询将如下所示

{
  country(id:"57b48b73f6d183802aa06fe8") {
    name
    loc {
      type
      coordinates
    } 
  } 
}
于 2016-08-22T11:18:28.123 回答
0

这似乎是模式创建中的一个可能的错误,我可以使它与这个模型一起工作(参见示例文件夹):https ://github.com/tothandras/graffiti-mongoose/tree/bug/ric_castro_rada

于 2016-08-23T14:35:53.370 回答