Can I take repository from Github GraphQl Api by ID

Hi,

I want to take details about the repository by using repository ID.
Is it possible?
If yes, how to do that?
I don’t know, in which way I must prepare the query for that.

Thanks for help.

Hi @hajczek, welcome to the community! Yes, you can absolutely do that, try the query below. Here’s an example using this repository:

The GitHub API exposes the node_id when fetching a repository:

In this case, the node_id is MDEwOlJlcG9zaXRvcnkxODEyMDQwMDI .

Using our GraphQL API Explorer, you can run this query to fetch that repository by its node_id :

query { 
    node(id: "MDEwOlJlcG9zaXRvcnkxODEyMDQwMDI"){
    ... on Repository {
      id
      nameWithOwner
    }
  }
}

I hope this helps!
AG

Hi @andreagriffiths11,

Thank you so much for this query, is what I want but not exactly.

I have the app where I want to search for details about the repository using the repository id, but dynamically declared. It means that I have this ‘id’ in some variable and I want to put this variable inside query, something like that:

query { 
    node(id: $id){
    ... on Repository {
      id
      nameWithOwner
    }
  }
}

with declared variable $id.

But when I try to do this in Explorer, I have this message: "Variable $id is used by but not declared"

How can I do this, maybe you know?

Thanks for help.

Thanks for help again!

I found the solution of my problem :slight_smile:

Here is my query, which works well:

query repository($id:  ID!){ 
    node(id: $id){
    ... on Repository {
      id
      nameWithOwner
    }
  }
} 

Have a nice evening!!!

1 Like

Awesome :clap: thanks for coming back to share your solution.

1 Like