Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tavern/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) {
return nil, fmt.Errorf("failed to upload default tomes: %w", err)
}

// Initialize Git Tome Importer
git := cfg.NewGitImporter(client)

// Initialize Test Data
if cfg.IsTestDataEnabled() {
createTestData(ctx, client)
Expand Down Expand Up @@ -159,7 +162,7 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) {
client,
"https://www.googleapis.com/oauth2/v3/userinfo",
)},
"/graphql": tavernhttp.Endpoint{Handler: newGraphQLHandler(client)},
"/graphql": tavernhttp.Endpoint{Handler: newGraphQLHandler(client, git)},
"/c2.C2/": tavernhttp.Endpoint{Handler: newGRPCHandler(client)},
"/cdn/": tavernhttp.Endpoint{Handler: cdn.NewDownloadHandler(client)},
"/cdn/upload": tavernhttp.Endpoint{Handler: cdn.NewUploadHandler(client)},
Expand Down Expand Up @@ -226,8 +229,8 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) {
return tSrv, nil
}

func newGraphQLHandler(client *ent.Client) http.Handler {
srv := handler.NewDefaultServer(graphql.NewSchema(client))
func newGraphQLHandler(client *ent.Client, repoImporter graphql.RepoImporter) http.Handler {
srv := handler.NewDefaultServer(graphql.NewSchema(client, repoImporter))
srv.Use(entgql.Transactioner{TxOpener: client})

// GraphQL Logging
Expand Down
7 changes: 7 additions & 0 deletions tavern/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"realm.pub/tavern/internal/ent"
"realm.pub/tavern/tomes"

"entgo.io/ent/dialect/sql"
"github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -111,6 +112,12 @@ func (cfg *Config) Connect(options ...ent.Option) (*ent.Client, error) {
return ent.NewClient(append(options, ent.Driver(drv))...), nil
}

// NewGitImporter configures and returns a new RepoImporter using git.
func (cfg *Config) NewGitImporter(client *ent.Client) *tomes.GitImporter {
var options []tomes.GitImportOption
return tomes.NewGitImporter(client, options...)
}

// IsMetricsEnabled returns true if the /metrics http endpoint has been enabled.
func (cfg *Config) IsMetricsEnabled() bool {
return EnvEnableMetrics.String() != ""
Expand Down
202 changes: 196 additions & 6 deletions tavern/internal/ent/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tavern/internal/ent/ent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading