~edwargix/git.sr.ht

d6bb9853d8c8a3e7c6deb015a5ddaa6babe912ea — Drew DeVault 5 years ago 6493312
api/commits: implement commit parents
M graphql/graph/generated/generated.go => graphql/graph/generated/generated.go +3 -2
@@ 1267,6 1267,7 @@ type Tree implements Object {
  id: String!
  shortId: String!
  raw: String!
  # TODO: add globbing
  entries(count: Int = 100, next: String): [TreeEntry!]!

  entry(path: String): TreeEntry


@@ 2806,13 2807,13 @@ func (ec *executionContext) _Commit_parents(ctx context.Context, field graphql.C
		Object:   "Commit",
		Field:    field,
		Args:     nil,
		IsMethod: false,
		IsMethod: true,
	}

	ctx = graphql.WithFieldContext(ctx, fc)
	resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
		ctx = rctx // use context from middleware stack in children
		return obj.Parents, nil
		return obj.Parents(), nil
	})
	if err != nil {
		ec.Error(ctx, err)

M graphql/graph/model/commit.go => graphql/graph/model/commit.go +13 -1
@@ 10,7 10,6 @@ type Commit struct {
	ID        string     `json:"id"`
	ShortID   string     `json:"shortId"`
	Raw       string     `json:"raw"`
	Parents   []*Commit  `json:"parents"`

	commit *object.Commit
	repo   *git.Repository


@@ 46,3 45,16 @@ func (c *Commit) Tree() *Tree {
	tree, _ := obj.(*Tree)
	return tree
}

func (c *Commit) Parents() []*Commit {
	var parents []*Commit
	for _, p := range c.commit.ParentHashes {
		obj, err := LookupObject(c.repo, p)
		if err != nil {
			panic(err)
		}
		parent, _ := obj.(*Commit)
		parents = append(parents, parent)
	}
	return parents
}

M graphql/graph/schema.graphqls => graphql/graph/schema.graphqls +1 -0
@@ 177,6 177,7 @@ type Tree implements Object {
  id: String!
  shortId: String!
  raw: String!
  # TODO: add globbing
  entries(count: Int = 100, next: String): [TreeEntry!]!

  entry(path: String): TreeEntry