Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GraphQL查询中剔除空数组_Graphql - Fatal编程技术网

在GraphQL查询中剔除空数组

在GraphQL查询中剔除空数组,graphql,Graphql,以下是GraphQL查询的要点,用于查询各种体育赛事 query Sports { sports { name events { name } } } 我们可能会得到这样的回报: Rugby Six Nations Rugby Union Football World Cup Europe League ... 在这种情况下,任何一项运动都有可能有一系列空的项目。我是否可以在查询中添加一些内容,要求任何数组至少有1个元素?或者,如果

以下是GraphQL查询的要点,用于查询各种体育赛事

query Sports {
  sports {
    name
    events {
      name
    }
  }
}
我们可能会得到这样的回报:

Rugby
  Six Nations
  Rugby Union
Football
  World Cup
  Europe League
...

在这种情况下,任何一项运动都有可能有一系列空的项目。我是否可以在查询中添加一些内容,要求任何数组至少有1个元素?或者,如果我想防止出现这种情况,是否需要在客户端实现过滤?

除了请求特定字段之外,GraphQL没有任何过滤或减少查询结果的内置方法。在为端点创建模式时,必须实现任何过滤、排序等


您必须查阅正在使用的端点()的文档,以确定是否有任何参数可以传递到
sports
字段,以防止服务器返回没有事件的运动。

在GraphCM中,我们可以使用关键字“where”。 我不知道这个功能是否在标准API中可用

query Sports {
   sports(where: {events_some: {}}) {
      name
      events {
         name
      }
   }
}

请在你的答案中添加一些解释,以便其他人可以从中学习