git-bug/api/graphql/resolvers/query.go

49 lines
904 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
"github.com/MichaelMure/git-bug/api/graphql/graph"
"github.com/MichaelMure/git-bug/api/graphql/models"
2018-07-29 19:11:33 +03:00
"github.com/MichaelMure/git-bug/cache"
)
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(_ 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(_ context.Context, ref *string) (*models.Repository, error) {
var repo *cache.RepoCache
var err error
if ref == nil {
repo, err = r.cache.DefaultRepo()
} else {
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
}