如何按无边的子代过滤GraphQL结果?
我刚开始研究GraphQL,我想知道是否有一种方法可以过滤没有任何节点的结果。下面是一个相对简单的查询示例:如何按无边的子代过滤GraphQL结果?,graphql,Graphql,我刚开始研究GraphQL,我想知道是否有一种方法可以过滤没有任何节点的结果。下面是一个相对简单的查询示例: query { organization(login:"GitHub") { repositories(first: 20) { edges { node { name pullRequests(first: 5, states: OPEN){ edges {
query {
organization(login:"GitHub") {
repositories(first: 20) {
edges {
node {
name
pullRequests(first: 5, states: OPEN){
edges {
node {
title
author{
login
}
updatedAt
}
}
}
}
}
}
}
}
下面是查询返回的结果的子集:
{
"data": {
"organization": {
"repositories": {
"edges": [
{
"node": {
"name": "gitignore",
"pullRequests": {
"edges": [
{
"node": {
"title": "Create new CodeComposerStudio.gitignore",
"author": {
"login": "wolf99"
},
"updatedAt": "2017-07-26T20:31:53Z"
}
},
{
"node": {
"title": "Create PVS.gitignore",
"author": {
"login": "cesaramh"
},
"updatedAt": "2017-05-01T19:42:07Z"
}
},
{
"node": {
"title": "gitignore for Magic Software Enterprises product xpa ",
"author": {
"login": "tommes"
},
"updatedAt": "2017-05-01T19:41:53Z"
}
},
{
"node": {
"title": "Create PSoC.gitignore",
"author": {
"login": "dbrwn"
},
"updatedAt": "2017-05-01T19:41:39Z"
}
},
{
"node": {
"title": "add ThinkPHP gitignore file",
"author": {
"login": "swumao"
},
"updatedAt": "2017-05-01T19:40:53Z"
}
}
]
}
}
},
{
"node": {
"name": "dmca",
"pullRequests": {
"edges": []
}
}
}
]
}
}
}
}
因此,我想知道是否有一种方法可以修改我的查询,使其不会返回名为
dmca
的节点,因为根据GitHub存储库,
文档不允许这种过滤,因此在pullRequests上没有边
first: Int
Returns the first n elements from the list.
after: String
Returns the elements in the list that come after the specified cursor.
last: Int
Returns the last n elements from the list.
before: String
Returns the elements in the list that come before the specified cursor.
privacy: RepositoryPrivacy
If non-null, filters repositories according to privacy
orderBy: RepositoryOrder
Ordering options for repositories returned from the connection
affiliations: [RepositoryAffiliation]
Affiliation options for repositories returned from the connection
isLocked: Boolean
If non-null, filters repositories according to whether they have been locked
isFork: Boolean
If non-null, filters repositories according to whether they are forks of another repository
所以我认为这是不可能的。如果您使用的是githubs graphql api,那么似乎没有办法过滤这些边,
但是如果您正在实现graphql服务器,那么就有可能知道边缘节点是什么,从而在边缘解析器中对其进行过滤是的,您可能是对的。这显然不是可以直接完成的事情;但我想知道GraphQL本身是否有独立于已发布模式的机制。我看到GraphQL中有@include(if:Boolean)
和@skip(if:Boolean)
指令,但我不确定这是否可以用来实现我的目标。include和skip只是根据客户端参数筛选查询的一部分,而不是根据返回的数据/:因此在这种情况下对您没有帮助