How to get any useful out of a search?


#1

I’m trying the following snippet over at https://graphql-explorer.githubapp.com/ (I looked at the example on https://developer.github.com/early-access/graphql/)

query { 
  search(type: ISSUE, query: "Starkast", first: 30) {
    edges {
      org:node {
        name
      }
    }
  }
}

The query isn’t valid, running it says:

“message”: “Selections can’t be made directly on unions (see selections on SearchResultItem)”

The tooltip I get hovering name says:

Cannot query field “name” on type “SearchResultItem”. Did you mean to use an inline fragment on “RepositoryInfo”, “Repository”, “User”, or “Organization”?

I’m lost, I’ve searched the docs, but I don’t know what to do. Google “site:developer.github.com selections” has no results.


#2

Search returns a union type, that means it could be an issue, a repository, an organization etc. They don’t all have the same fields, so GraphQL requires you to specify which type you want to make a selection on. In your case, you get issues back, so try the following query:

query { 
  search(type: ISSUE, query: "Starkast", first: 30) {
    edges {
      node {
        ... on Issue {
          title
        }
      }
    }
  }
}

#3

Can’t we search for commits by giving the commit hashes in graphAPI