redrabbit / git.limo

A Git source code management tool powered by Elixir with easy installation & high extensibility.
https://git.limo
MIT License
497 stars 42 forks source link

GraphQL schema for querying Git references and objects with global IDs. #20

Closed redrabbit closed 6 years ago

redrabbit commented 6 years ago

Currently, a Repo provides following reference related fields:

It also provides following function to fetch a single object:

A GitReference can fetch it related GitObject using object/0. The GitObject type being an interface, it can be cast to GitCommit, GitTree, GitBlob. For example:

query LastCommitQuery {
  repo(owner:"redrabbit",name:"gitgud") {
    head {
      shorthand
      object {
        ... on GitCommit {
          message
          author {
            username
          }
        }
      }
    }
  }
}

A very neat feature would be to have the possibility to retrieve GitReference and GitObject using a Relay Global Object Identification Specification:

query SingleCommitQuery {
  node(id: $commitID) {
    ... on GitCommit {
      message
      author {
        username
      }
    }
  }
}

This is already implemented for User and Repo but needs more work to implement for Git types. This issue depends on how the Git storage backend (see #2) is implemented...

redrabbit commented 6 years ago

After experimenting for a while, I'd say that this is not really relevant.

It is feasible to implement node ids for all GitObject types by creating our own global id as follow:

"#{repo_id}:#{String.slice(oid_fmt(obj_oid), 0, 7)}"

resulting in, for example, GitCommit:2:bba34c5 or R2l0Q29tbWl0OjI6YmJhMzRjNQ (Base64).

But I did not find any real use-case here. Having the possibility to fetch a repository by node id and use the Git OID to retrieve the right GitObject is not that cumbersome...