2018-07-29 19:11:33 +03:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2020-06-21 23:12:04 +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"
|
|
|
|
)
|
|
|
|
|
2019-03-31 22:44:14 +03:00
|
|
|
var _ graph.QueryResolver = &rootQueryResolver{}
|
|
|
|
|
2018-07-29 19:11:33 +03:00
|
|
|
type rootQueryResolver struct {
|
2018-09-02 16:45:14 +03:00
|
|
|
cache *cache.MultiRepoCache
|
2018-07-29 19:11:33 +03:00
|
|
|
}
|
|
|
|
|
2020-02-03 23:03:48 +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
|
|
|
|
}
|
|
|
|
|
2018-07-30 00:48:52 +03:00
|
|
|
return &models.Repository{
|
|
|
|
Cache: r.cache,
|
|
|
|
Repo: repo,
|
2018-07-29 19:11:33 +03:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-02-05 03:06:53 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-30 00:48:52 +03:00
|
|
|
return &models.Repository{
|
|
|
|
Cache: r.cache,
|
|
|
|
Repo: repo,
|
2018-07-29 19:11:33 +03:00
|
|
|
}, nil
|
|
|
|
}
|