How to check if all repos have a specific file contained therein

Hello,

I’m still new to GraphQL and I’m hoping that someone can help me.

I have created the following code to check if a file exists in all repositories I have access to.

query ($fname: String!) {
  viewer {
    login
    repositories(first: 10, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER], ownerAffiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        ... on Repository {
          object(expression: $fname) {
            ... on Blob {
              byteSize
            }
          }
        }
      }
    }
  }
}

If the OBJECT returns a byteSize value then the file exists. if the OBJECT is null then the file does not exist.

The $Fname variables has, for example, a value of “master:README.md”. The file I am looking for is README.md which is fine. But it requires me to hardcode the branch name, and with changing branch names these days not all my repos have a “master” branch.

I have created the following code to find the default branch on all my repos:

{
  viewer {
    login
    repositories(first: 10, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER], ownerAffiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        ... on Repository {
          defaultBranchRef {
            name
          }
        }
      }
    }
  }
}

But now I’m trying to combine the two pieces of code so that the query will return a byteSize value if the filename exists on the default branch or null if it does not. And try as I might I’m not getting anywhere.

Does anyone know if this is possible ? Is it possible to combine the code so it works? Or if you have an alternate solution I would be vert grateful.

Can you just ask about HEAD instead of worrying about master/main?