List commits of files doesn't return data


#1

Hey guys, I’m looking to pull in author data of commits (e.g. contributors) to specific files.

It doesn’t return an error, only an empty object.

What am I doing wrong?

{
  organization(login: "facebook") {
    name
    url
    repository(name: "react") {
      object(expression: "master:LICENSE") {
        ... on Commit {
          history(first: 10) {
            edges {
              node {
                oid
                messageHeadline
                author {
                  name
                }
                authoredDate
              }
            }
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "organization": {
      "name": "Facebook",
      "url": "https://github.com/facebook",
      "repository": {
        "object": {}
      }
    }
  }
}

#2

Hi @ymschaap!

You’re using the spread operator (... on Commit) from object, which returns a GitObject interface. In this case, the concrete type it’s returning is a Blob and not a Commit, which is why you’re not showing any results.

For this particular query, the Blob object doesn’t get you what you want (if you wanted the contents of the file, it would work great!). I believe this query will fetch you the information you’re looking for:

{
  repository(owner: "facebook", name: "react") {
    defaultBranchRef {
      target {
        __typename
        ... on Commit {
          history(first: 100, path: "LICENSE") {
            nodes {
              oid
              messageHeadline
              author {
                name
              }
              authoredDate
            }
          }
        }
      }
    }
  }
}

Let me know!


#3

Thank you. That works.
Still trying to wrap my head around all the different terminology of the graph api.