5

I have the following query:

{
  repository(owner: "org", name: "name") {
    name
    object(expression: "master:package.json") {
      ... on Blob {
        text
      }
    }
  }
}

but as you can see I have to hardcode master in the object expression. I'm wondering if there's a way to instead use the default branch in that query. Is that possible without having to do 2 queries (1 to get the default branch, then another to get the file content)?

Ben
  • 16,124
  • 22
  • 77
  • 122

1 Answers1

3

There was a related question (with bounty too) on that, detailed in this thread... but it is the syntax you are using:

The argument passed to expression on the object field is actually a git revision expression suitable for git rev-parse, so I guess you can have fun with it to do advanced querying.

So any way to specify a revision should do, including HEAD, which would reference the default remote branch. But not the "current branch" though.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    ok but in that example they use `expression: "branch:path/to/file"` what I want to know is what do i use in place of 'branch' so that it uses the default branch? 'master' isn't always the default... – Ben Feb 27 '18 at 22:25
  • 4
    @Ben yes, master is not always the default branch, which is why I suggest in my answer to use HEAD: that should reference the default branch. See https://stackoverflow.com/a/1485590/6309 – VonC Feb 28 '18 at 09:08