Actors vs. Users


#1

In the below request,

query Reviewers{
  repository(owner: "w3c", name: "web-platform-tests") {
    pullRequest(number:6020) {
      reviewRequests(first:100) {
        edges {
          node {
            reviewer {
              login
            }
          }
        }
      }
      reviews(first:100) {
        edges {
          node {
            author{
              login
            }
          }
        }
      }
      publishedAt
    }
  }
}

The reviewers of reviewRequests are User types, the actors of reviews are Actors. I understand the rational as to why, but that’s really annoying to deal with (I wanted to get at the emails in both cases, it turns out that it’s impossible).

Anyway to fix that to make it more consistant?


#2

Hi @tobie,

While the PullRequestReview.author field returns the Actor interface, that doesn’t mean that it’s impossible to get at the underlying type which implements that interface: the User type. You can do so with an inline fragment.

Does this query allow you to get the information you’re looking for?

query Reviewers {
  repository(owner: "w3c", name: "web-platform-tests") {
    pullRequest(number: 6020) {
      reviewRequests(first: 100) {
        edges {
          node {
            reviewer {
              login
              email
            }
          }
        }
      }
      reviews(first: 100) {
        edges {
          node {
            author {
              ... on User {
                login
                email
              }
            }
          }
        }
      }
      publishedAt
    }
  }
}

#3

OK. This is magic. Do you have a readily accessible pointer to explain how it works?


#4

Well, for the benefit of others with a similar issue, here’s how inline fragments work: http://graphql.org/learn/queries/#inline-fragments


#5

That’s exactly what I was going to post :smile:.

I also just wanted to mention the reason that some of those emails come back empty is because not everyone opts to share their emails. In the case where people don’t, you’ll get back an empty string or null.


#6

I also just wanted to mention the reason that some of those emails come back empty is because not everyone opts to share their emails. In the case where people don’t, you’ll get back an empty string or null.

Yeah. For the benefit of others, here’s a solution to the missing email issue for users that have used OAuth to sign in to your app: https://remysharp.com/2017/04/24/when-github-email-scope-fails.