API From users repos to fork owner

API v3.
I noticed with
https://api.github.com/users/$user/repos
I am getting a list of that user repos.
Some of them are fork : true
Those who are true, do they reveal where they got forked from?
Currently I am making a second query to
https://api.github.com/repos/$user/$repo
Then I get a parent and source element pointing to the fork owner
Am I missing something?
Is it possible to obtain the fork owner just by querying the user repos?

:wave: @matjung: Great questions! Please see my replies in-line below.

The response returned for listing the public repositories for a specified user will not include where the repository was forked from. As you’ve found, one way of determining the parent is making another request to fetch that repository, which includes a parent field with the information you’re looking for.

You can use the GraphQL API to obtain a specific user’s repositories and listing out specific fields. The Repository object has an isFork field indicating if the repository is a fork as well as a parent field which offers an interface for querying the parent information if one exists.

Here’s an example query that you can run in our GraphQL Explorer:

query {
  user(login: "matjung") {
    repositories(first: 5) {
      edges {
        node {
          name
          isFork
          parent {
            name
          }
        }
      }
    }
  }
}
Result set
{
  "data": {
    "user": {
      "repositories": {
        "edges": [
          {
            "node": {
              "name": "createavatar",
              "isFork": false,
              "parent": null
            }
          },
          {
            "node": {
              "name": "web-nodejs-sample",
              "isFork": true,
              "parent": {
                "name": "web-nodejs-sample"
              }
            }
          },
          {
            "node": {
              "name": "covid",
              "isFork": false,
              "parent": null
            }
          },
          {
            "node": {
              "name": "covid_19",
              "isFork": true,
              "parent": {
                "name": "covid_19"
              }
            }
          },
          {
            "node": {
              "name": "pymqi",
              "isFork": true,
              "parent": {
                "name": "pymqi"
              }
            }
          }
        ]
      }
    }
  }
}

If you’re new to GraphQL, our team published a series of guides for getting started that might be of interest. Does this help? :thought_balloon:

1 Like

Hi @francisfuzz
GraphQL and rest-api v3 is not the same thing.
Do you see a chance to extend the rest-api with the name of the Fork Owner?

Do you see a chance to extend the rest-api with the name of the Fork Owner?

@matjung: While I can’t speak to upcoming changes on existing features, I suggest checking out the GitHub Roadmap for upcoming features and changes.