连接子结果的GraphQL参数



我需要帮助传递参数到集合/连接/数组在GraphQL语法。

我正在学习它,在http://graphql.org/swapi-graphql/上玩SWAPI

我可以将id参数传递给单个类型,像这样:

query getANewHope {
  film(id: "ZmlsbXM6MQ==") {
    id
    title
  }
}

但是我不知道如何查询集合/连接的结果

query starships {
  allStarships(id: "c3RhcnNoaXBzOjI=") { # this doesn't work
    edges {
      node(id: "c3RhcnNoaXBzOjI=") { # ...nor this.
        id
      }
    }
  }
}

我想查询集合,因为我想把这两个想法联系起来,比如"《新希望》中所有的星际战斗机类型的飞船"?

query filmStarships {
  film(id: "ZmlsbXM6MQ==") {
    title
    starshipConnection { #How to limit this?  I can't use (starshipClass: "Starfighter") here...
      edges {
        node { # ...nor here..
          starshipClass # ...nor here.
        }
      }
    }
  }
}


query starships2 {
  starship (id:  "c3RhcnNoaXBzOjI=") { # This doesn't work either
    id # even without an arugment abovce, it says "Unknown argument "id" on field "node" of type "StarshipsEdge"."
  } 
}

您要求的参数必须在模式中实现。SWAPI不通过starshipClass向过滤器公开参数。单击graphhiql窗口右上角的Docs,查看所提供的模式。

如果您正在实现自己的模式,那么在解析器中添加starshipClass过滤器将非常容易。

最新更新