- Introduction to GraphQL
- Using Global Node IDs received from REST API calls to fetch objects in GraphQL directly
- Forming calls with GraphQL
- Playground aka Explorer to learn and experiment with GitHub GraphQL: https://docs.github.com/en/graphql/overview/explorer
- Query: https://docs.github.com/en/graphql/reference/queries#repository
- Objects are identified by arguments. Objects have fields: https://docs.github.com/en/graphql/reference/objects#repository
- How to request GraphQL endpoint: https://docs.github.com/en/graphql/guides/forming-calls-with-graphql
- Octokit GraphQL client: use this for JS instead of own fetch()-based code, as it follows GitHub best practices
- GitHub doesn't allow unauthenticated GraphQL requests. However the authenticated rate-limit is generous at 5000 points/hour. Hearsay: even raw.githubusercontents.com, though apparently unlimited, limits after 5k requests/hour. However, points/hour <= requests/hour.
- Question: Are GraphQL queries, because they are not mutative, i.e. are read-only, served from the edge?
-
- ... more at https://docs.github.com/en/graphql
Let the branches be BRANCH-A and BRANCH-B, of repository REPO, owned by OWNER. To avoid conflict, lets alias BRANCHB as ALIAS. Put your own values in place of the uppercase strings.
query {
repository(owner:"OWNER", name:"REPO", followRenames:true) {
ref(qualifiedName:"refs/heads/BRANCH-A"){
target{
oid
}
}
ALIAS: ref(qualifiedName:"refs/heads/BRANCH-B"){
target{
oid
}
}
}
}
✨ This demonstrated a major advantage of GraphQL over REST API. Multiple queries, such as resolving both BRANCH-A and BRANCH-B, could be done using the same request.
Assuming TAG tags a blob, instead of a commit or tree.
query {
repository(owner:"OWNER", name:"REPO", followRenames:true) {
ref(qualifiedName:"refs/tags/TAG"){
target{
...on Blob {
text
}
}
}
}
}
query {
repository(owner:"OWNER", name:"REPO", followRenames:true) {
ref(qualifiedName:"refs/heads/main"){
target{
...on Commit {
file(path: "README.md"){
object {
...on Blob {
text
}
}
}
}
}
}
}
}