Amazon web services 如何在AppSync/Amplify中过滤非标量类型

Amazon web services 如何在AppSync/Amplify中过滤非标量类型,amazon-web-services,amazon-dynamodb,aws-appsync,aws-amplify,amplifyjs,Amazon Web Services,Amazon Dynamodb,Aws Appsync,Aws Amplify,Amplifyjs,我正在使用aws amplify定义我的appsync架构 我有以下简化的模式: type Country @model { id: ID! name: String! code: String! tracks: [Track] @connection(name: "CountryTrack") } type Track @model id: ID! name: String! country: Country! @connection(name: "Country

我正在使用aws amplify定义我的appsync架构

我有以下简化的模式:

type Country @model {
  id: ID!
  name: String!
  code: String!
  tracks: [Track] @connection(name: "CountryTrack")
}

type Track @model
  id: ID!
  name: String!
  country: Country! @connection(name: "CountryTrack")
  lng: Float
  lat: Float
  length: Float
  curves: Int
  website: String
  trackImage: String
  information: String
}
放大为模型生成过滤器输入。但是,它不包括连接类型

我想根据国家筛选曲目

dynamodb表有一个
trackCountryId
,在扫描操作中,我可以简单地根据id进行过滤

但是,这在graphql模式中不起作用。因为FiterInput中不包括
trackCountryId


有人知道如何解决这个问题吗?

Amplify CLI在
Country
类型上创建
listTracks
query+resolver和
tracks
resolver。如果要根据countryId筛选所有曲目,则必须在以下步骤中手动添加,这些步骤基本上是上述生成的查询+解析程序的混合:

->在您的模式中:将其添加到
类型查询中
,然后单击“保存模式”:

->将冲突解决程序附加到刚才添加的查询字段,然后单击“保存冲突解决程序”:

  • 选择TrackTable作为数据源名称

  • 请求映射模板

  • 响应映射模板
->导航到控制台上的“查询”部分,然后运行以下查询:

query {
  listTracksByCountry(countryId: "countryId1") {
    items {
      id
      name
      length
    }
  }
}
您应该能够获得指定countryId的曲目列表。在我的例子中,上述操作的GraphQL输出是:

{
  "data": {
    "listTracksByCountry": {
      "items": [
        {
          "id": "trackId1",
          "name": "track name 1",
          "length": 1.1
        },
        {
          "id": "trackId2",
          "name": "track name 2",
          "length": 1.2
        }
      ]
    }
  }
}
这似乎是一个非常常见的用例,所以如果问题还不存在,请随意创建一个问题,然后我们可以使用Amplify CLI(
Amplify add api
),自动生成这些解析器

#if( !$result )
  #set( $result = $ctx.result )
#end
$util.toJson($result)
query {
  listTracksByCountry(countryId: "countryId1") {
    items {
      id
      name
      length
    }
  }
}
{
  "data": {
    "listTracksByCountry": {
      "items": [
        {
          "id": "trackId1",
          "name": "track name 1",
          "length": 1.1
        },
        {
          "id": "trackId2",
          "name": "track name 2",
          "length": 1.2
        }
      ]
    }
  }
}