This article has been imported from coding4.gaiama.org and is not necessarily up to date!

Github GraphQL to recursively list all files in the directory

Last updated: 
Published: 

Thanks to this amazing SO (StackOverflow) answer to the question "Github GraphQL to recursively list all files in the directory" I finally got my query working 😃

The query works only using the gatsby-source-graphql plugin.
If you want to use it outside Gatsby remove the GitHub_ prefixes so it becomes GitObjectID, Tree and Blob, haven't tested it elsewhere though.

query ($branch: GitHub_GitObjectID) {
  github {
    viewer {
      repository(name: "Coding4GaiAma") {
        name
        object(expression: "master:", oid: $branch) {
          ... on GitHub_Tree {
            entries {
              name
              object {
                ... on GitHub_Blob {
                  text
                }
              }
            }
          }
        }
        issues(first: 10, filterBy: { states: OPEN }) {
          nodes {
            title
            url
            bodyText
          }
        }
      }
    }
  }
}
Can Rau
Can Rau

Doing web-development since around 2000, building my digital garden with a mix of back-to-the-roots-use-the-platform and modern edge-rendered-client-side-magic tech 📻🚀

Living and working in the tropical rainforest of Perú 🐒