Possible to query for a single release?


#1

I’m wondering if it’s possible to query for a single release in a repository? I’m currently using this but it gets all releases (well, the first 100):

query($owner: String!, $name: String!, $after: String) {
  repository(owner:$owner, name:$name) {
    releases(first: 100, after: $after) {
      edges {
        node {
          name
          tag {
            name
          }
          releaseAssets(first: 100) {
            edges {
              node {
                name
                downloadCount
              }
            }
          }
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

TIA!
Andy


#2

Hi @ncdc!

I think there is a way that we can accomplish this, but it depends on what you’re looking for!

If you modify your query slightly to include the Node ID for the release asset, you can use it to query for a single one later on, like this:

query($owner: String!, $name: String!, $after: String) {
  repository(owner:$owner, name:$name) {
    releases(first: 100, after: $after) {
      edges {
        node {
          name
          tag {
            name
          }
          releaseAssets(first: 100) {
            edges {
              node {
                id
                name
                downloadCount
              }
            }
          }
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

Doing this on a repository of mine that is public:

{
  "owner": "nickvanw",
  "name": "dg1670a_exporter"
}

Gets us a number of ReleaseAssets:

{
  "data": {
    "repository": {
      "releases": {
        "edges": [
          {
            "node": {
              "name": "Initial Release",
              "tag": {
                "name": "v0.1.0"
              },
              "releaseAssets": {
                "edges": [
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjU=",
                      "name": "dg1670a_exporter-linux-arm-7",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjY=",
                      "name": "dg1670a_exporter-linux-386",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjc=",
                      "name": "dg1670a_exporter-linux-arm64",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjg=",
                      "name": "dg1670a_exporter-windows-4.0-amd64.exe",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjk=",
                      "name": "dg1670a_exporter-windows-4.0-386.exe",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzE=",
                      "name": "dg1670a_exporter-linux-mips64",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzI=",
                      "name": "dg1670a_exporter-linux-arm-6",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzM=",
                      "name": "dg1670a_exporter-darwin-10.6-amd64",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzQ=",
                      "name": "dg1670a_exporter-linux-arm-5",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzU=",
                      "name": "dg1670a_exporter-linux-amd64",
                      "downloadCount": 0
                    }
                  },
                  {
                    "node": {
                      "id": "MDEyOlJlbGVhc2VBc3NldDUyNzMxMzg=",
                      "name": "dg1670a_exporter-darwin-10.6-386",
                      "downloadCount": 0
                    }
                  }
                ]
              }
            }
          }
        ],
        "pageInfo": {
          "endCursor": "Y3Vyc29yOnYyOpHOAIB3ew==",
          "hasNextPage": false
        }
      }
    }
  }
}

Grabbing the ID from the first one, we can do this:

{
  node(id: "MDEyOlJlbGVhc2VBc3NldDUyNzMxMjU=") {
    ...on ReleaseAsset {
      id
      name
      downloadUrl
    }
  }
}

It’s also possible to use multiple Nodes in a single query, by changing the query to nodes(...

If this isn’t what you’re looking for, or doesn’t make sense, let me know!


#3

Thanks! What I am hoping to do is write a single query that is “for a repo & release tag, show me all its releaseAssets”. For example, I want owner=heptio, repo=ark release=v0.6.0. Is something like this possible?


#4

Got it!

I don’t believe that’s possible right now - if I have the use case correct, you’re looking for the equivalent of this REST route: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name to be able to look up a release by a specific tag? In your example, that’d be https://api.github.com/repos/heptio/ark/releases/tags/v0.6.0

I think this is totally reasonable - likely what the schema would look like would be a filter on the releases connection to add in a list of one-or-more tags to filter by. Does that seem reasonable? If so, I think I can implement it pretty quickly and get this back to you soon.


#5

Yes, this is exactly what I’m looking for. Thanks!


#6

Hey @ncdc!

Good news! I’ve got a PR open and approved to implement this, which will look like

query {
  repository(owner:"heptio", name:"ark") {
    release(tagName:"v0.6.0") {
      releaseAssets(first: 100) {
        nodes {
          name
          size
        }
      }
    }
  }
}

Given its 6PM on a Friday here, I’m going to hold off deploying until next week - I’ll update this thread when it’s out in the wild!


#7

Great news! This has been shipped!

query {
  repository(owner:"heptio", name:"ark") {
    release(tagName:"v0.6.0") {
      releaseAssets(first: 100) {
        nodes {
          name
          size
        }
      }
    }
  }
}

Now returns

{
  "data": {
    "repository": {
      "release": {
        "releaseAssets": {
          "nodes": [
            {
              "name": "ark-v0.6.0-darwin-amd64.tar.gz",
              "size": 13181242
            },
            {
              "name": "ark-v0.6.0-linux-amd64.tar.gz",
              "size": 13269557
            },
            {
              "name": "ark-v0.6.0-linux-arm.tar.gz",
              "size": 12096816
            },
            {
              "name": "ark-v0.6.0-linux-arm64.tar.gz",
              "size": 12115460
            },
            {
              "name": "ark-v0.6.0-windows-amd64.tar.gz",
              "size": 13228678
            },
            {
              "name": "CHECKSUM",
              "size": 481
            }
          ]
        }
      }
    }
  }
}

Let me know if there’s anything missing here, or if you think this doesn’t solve what you need!


Is there a way to download binary contents of assets through GraphQL?
#8

This works perfectly. Thanks for the quick turnaround!