Get the (textual) value of a file in a GitHub repo via GraphQL

  • $branchAndFilePath should be formatted as ${branchName}:${filePath without the leading '/'}

Note that the text field will be null if the file is a binary blog (such as an image).

If you need to read the binary content, email []( you add a base64-encoded binary content field to the GitHubBlob type on OneGraph?) and we can stitch in the corresponding REST endpoint

query GetFileTextContentsQuery($repoName: String!, $repoOwner: String!, $branchAndFilePath: String = "") { gitHub { repository(name: $repoName, owner: $repoOwner) { object_: object(expression: $branchAndFilePath) { ... on GitHubBlob { sha: oid # alias this to `sha`, as that's a bit more familiar byteSize isBinary # Note the text content will be null if # `isBinary` is true text } } } } }
Types used in this example

No description


The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.


The query root of GitHub's GraphQL interface.


A repository contains the content for a project.


Represents a Git object.


Represents a Git blob.


A Git object ID.


The Int scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.


The Boolean scalar type represents true or false.