git-bug/graphql/resolvers/query.go

42 lines
789 B
Go
Raw Normal View History

2018-07-29 19:11:33 +03:00
package resolvers
import (
"context"
2018-08-13 19:32:11 +03:00
2018-07-29 19:11:33 +03:00
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/graphql/graph"
"github.com/MichaelMure/git-bug/graphql/models"
2018-07-29 19:11:33 +03:00
)
var _ graph.QueryResolver = &rootQueryResolver{}
2018-07-29 19:11:33 +03:00
type rootQueryResolver struct {
cache *cache.MultiRepoCache
2018-07-29 19:11:33 +03:00
}
func (r rootQueryResolver) DefaultRepository(ctx context.Context) (*models.Repository, error) {
2018-07-29 19:11:33 +03:00
repo, err := r.cache.DefaultRepo()
if err != nil {
return nil, err
}
return &models.Repository{
Cache: r.cache,
Repo: repo,
2018-07-29 19:11:33 +03:00
}, nil
}
func (r rootQueryResolver) Repository(ctx context.Context, ref string) (*models.Repository, error) {
repo, err := r.cache.ResolveRepo(ref)
2018-07-29 19:11:33 +03:00
if err != nil {
return nil, err
}
return &models.Repository{
Cache: r.cache,
Repo: repo,
2018-07-29 19:11:33 +03:00
}, nil
}