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"
|
2019-03-31 22:44:14 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/graph"
|
2018-07-30 00:48:52 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/models"
|
2018-07-29 19:11:33 +03:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-07-30 00:48:52 +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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-06-23 22:28:01 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|