1

我有这个简单的搜索查询

query test($name: String!) {
  search(query: $name, type: USER, last: 100) {
    edges {
      textMatches {
        fragment
        property
        highlights {
          text
        }
      }
    }
    userCount
  }
}

例如,我想从搜索结果中获取所有用户的登录信息。我该怎么做?结果包含与搜索文本匹配的登录名或显示名。有没有办法为那些因为他们的显示名而只出现在搜索中的人找到登录名?

4

1 回答 1

1

你快到了!在“edges”中,您正在处理一个SearchResultItemEdge数组,其中包含与“textMatches”相同级别的“node”属性。

由于该节点是SearchResultItem,并且可以是 User、Issue、PullRequest 等之一,因此您必须专门将您的节点传播为“用户”才能访问登录。

在资源管理器中尝试此查询:

query test($name: String!) {
  search(query: $name, type: USER, last: 100) {
    edges {
      node {
        __typename
        ...on User {
          login
        }
      }
      textMatches {
        fragment
        property
        highlights {
          text
        }

      }
    }
    userCount
  }
}
于 2018-06-22T16:35:00.077 回答