结合多个Graphql查询

时间:2019-05-21 14:48:58

标签: javascript graphql

这可能已经在其他地方得到了不同的回答,但我仍然在下面的案例中苦苦挣扎。

我要寻找的是将所有字段从一个模式(在我的情况下为names)带到特定位置(即:在features.properties内部)

字段 features.properties.CNTR_ID 将是我的第二个查询的输入参数,理想情况下以:

结尾
names(coutries: [$properties.CNTR_ID]) { }
"properties": {
    "CNTR_ID": "RO",
    "CNTR_NAME": "România",    <- foreign key
    "ISO3_CODE": "ROU"         <- foreign key
  }

two queries into one

这就是我构造 typeDefs 的方式:

    type TranslationCountry {
      CNTR_ID: String!
      CNTR_NAME: String
      ISO3_CODE: String
      NAME_ENGL: String
    }

    union PropertyCountryOrRegion = PropertyCountry | PropertyRegion
    type PropertyCountry {
      CNTR_ID: String!
      ISO3_CODE: String!
      NAME_ENGL: String!
    }
    type PropertyRegion {
      CNTR_CODE: String!
      NUTS_NAME: String!
      LEVL_CODE: String!
      NUTS_ID: String!
    }

    scalar Coordinates
    type Geometry {
      type: String!
      coordinates: Coordinates!
    }
    type Feature {
      id: String!
      geometry: Geometry!
      type: String!
      properties: PropertyCountryOrRegion
    }
    type Region {
      category: String!
      type: String!
      features: [Feature]
      fileName: String!
    }

    type Query {
      regions(countries: [String!]!, level: Int, scale: String, year: String): [Region]
      names(countries: [String!]!): [TranslationCountry]
    }
    schema {
      query: Query
    }

0 个答案:

没有答案