我如何为 Apollo Client 指定 GraphQL 查询并获取 属性 出现适当字符串的项目

How I can specify GraphQL query for Apollo Client and get items which property has an occurrence of the appropriate string

我在最后几天之前没有使用 GraphQL。我将 Apollo Client 与 graphql-tag 一起使用。现在我可以使用以下查询从服务器获取城市列表:

query {
    cities(country:countryName, limit:30){
      id
      name
  }    
}

但我只想获取名称 (name 属性) 出现用户键入的字符串的城市。它应该像自动完成一样工作。例如,当用户键入 san 时,我想获取 San Francisco, San Jose, San Juan... 的对象数组。可以在客户端做吗,还是找后台开发?

country 参数应该是一个变量,它将根据组件的属性计算。

query ($country: String) {
  cities(country: $country, limit: 30) {
    id
    name
  }
}

您的输入应该位于组件的父级中,它将通过 country 属性传递值。

查看 this sandbox for an example. You can see the schema and resolvers here