Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

With GraphQL, how to list releases based on tag names?

Solved! Go to Solution.

I'm trying to do the equivalent of requesting data from these two v3 endpoints:

"https://api.github.com/repos/" + repo + "/git/refs/tags
"https://api.github.com/repos/" + repo + "/releases/tags/" + tag

For some reason, Github does not list all releases when trying to query /releases, that's why I list first all tags.

 

Now, in GraphQL, is there any way to list all releases based on tag name?

 

I'm stuck with this query, but of course, it's broken:

{
  rateLimit {
    cost
    remaining
  }
  repository(owner: "NickeManarin", name: "ScreenToGif") {
    refs(refPrefix: "refs/tags/", last: 100) {
      edges {
        node {
          ... on Ref {
            name
            target {
              ... on Tag {
                name
                repository{
                 ... on Repository{
                  release(tagName: "2.1"){
                    name
                  }
                }
                }
              }
            }
          }
        }
      }
    }
  }
  repository(owner: "NickeManarin", name: "ScreenToGif") {
    release(tagName: "2.1") {
      name
    }
  }
}

 

1 Reply
Highlighted
Solution
Copilot Lvl 2
Message 2 of 2

Re: With GraphQL, how to list releases based on tag names?

I was able to get what I want with this:

 

query {
    rateLimit {
        cost
        remaining
     }
     repository(owner: "NickeManarin", name: "ScreenToGif") {
         refs(refPrefix: "refs/tags/", last: 100) {
             nodes {
                 repository {
                     releases(last: 100, orderBy: { field: CREATED_AT, direction: DESC}) {
                         nodes {
                             name
                             createdAt
                             url
                             releaseAssets(last: 2) {
                                 nodes {
                                     name
                                     downloadCount
                                     downloadUrl
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }

I'm just not sure if it's the best way of doing it.

 

----------------------------

 

While testing it, I found out that I can simply call it like this:

(Not sure why the v3 API was returning only a few releases)

 

 

query { 
rateLimit {
cost
remaining
}
repository(owner: "NickeManarin", name: "ScreenToGif") {
releases(last: 100, orderBy: { field: CREATED_AT, direction: DESC}) {
nodes {
name
createdAt
url
releaseAssets(last: 2) {
nodes {
name
downloadCount
downloadUrl
}
}
}
}
}
}