连接子结果的GraphQL参数

时间:2016-10-06 17:19:48

标签: 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
      }
    }
  }
}

我想查询集合,因为,我想将这两个想法联系起来,例如"所有Starfighter类型的船舶都在A New Hope"?

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\"."
  } 
}

1 个答案:

答案 0 :(得分:1)

您要求的参数必须在架构中实现。 SWAPI不会公开一个参数来过滤starshipClass。单击GraphiQL窗口右上角的Docs以浏览提供的架​​构。

如果您要实现自己的架构,那么在解析器的starshipClass上添加过滤器非常容易。