How to get info about specific user or repo?


#1

Right now examples on http://githubengineering.com/the-github-graphql-api/ show how to select user and repo for viewer how can I pick different user, I’ve tried using search:

{
  search (query: "torvalds", type: USER, first: 1) {    
    edges {
      node {
        
      }
    }
  }
}

but autocomplete for node show only __typename which return string “User”.


#2

It’s a little counterintuitive because type: USER is declared as a search argument, but search can technically return a number of different types (User, Issue, etc.). There’s no way for a GraphQL schema to say "because the argument type is set to USER, this will always be a User. So we have to add a type fragment:

query {
  search(query: "torvalds", type: USER, first: 1) {    
    edges {
      node {
        ... on User {
          login
          # other fields
        } 
      }
    }
  }
}

Give that a shot!


#3

It’s working, thanks.


#4

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.