【问题标题】:GraphQL arguments to connection sub results连接子结果的 GraphQL 参数
【发布时间】:2017-02-15 13:24:47
【问题描述】:

我需要帮助以 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\"."
  } 
}

【问题讨论】:

    标签: graphql


    【解决方案1】:

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

    如果您正在实现自己的架构,则可以很容易地在解析器中的 starshipClass 上添加过滤器。

    【讨论】:

      猜你喜欢
      • 2021-04-20
      • 1970-01-01
      • 2019-12-26
      • 2020-06-24
      • 1970-01-01
      • 2020-12-17
      • 2012-09-07
      • 2021-09-25
      • 2018-08-23
      相关资源
      最近更新 更多