GraphQL Framework

This commit is contained in:
2021-02-02 15:34:10 -05:00
parent ecf981495e
commit 7e6454c593
28 changed files with 10764 additions and 616 deletions

View File

@@ -7,6 +7,10 @@ import (
log "github.com/sirupsen/logrus"
"reichard.io/imagini/cmd/server"
"reichard.io/imagini/plugin"
"github.com/99designs/gqlgen/api"
"github.com/99designs/gqlgen/codegen/config"
)
type UTCFormatter struct {
@@ -21,7 +25,6 @@ func (u UTCFormatter) Format(e *log.Entry) ([]byte, error) {
func main() {
log.SetFormatter(UTCFormatter{&log.TextFormatter{FullTimestamp: true}})
log.Info("Starting Imagini")
app := &cli.App{
Name: "Imagini",
Usage: "A self hosted photo library.",
@@ -32,6 +35,11 @@ func main() {
Usage: "Start Imagini web server.",
Action: cmdServer,
},
{
Name: "generate",
Usage: "generate graphql schema",
Action: cmdGenerate,
},
},
}
err := app.Run(os.Args)
@@ -41,6 +49,7 @@ func main() {
}
func cmdServer(ctx *cli.Context) error {
log.Info("Starting Imagini Server")
server := server.NewServer()
server.StartServer()
@@ -53,3 +62,24 @@ func cmdServer(ctx *cli.Context) error {
return nil
}
func cmdGenerate(ctx *cli.Context) error {
log.Info("Generating Imagini Models")
gqlgenConf, err := config.LoadConfigFromDefaultLocations()
if err != nil {
log.Panic("Failed to load config", err.Error())
os.Exit(2)
}
log.Info("Generating Schema...")
err = api.Generate(gqlgenConf,
api.AddPlugin(plugin.New()),
)
log.Info("Schema Generation Done")
if err != nil {
log.Panic(err.Error())
os.Exit(3)
}
os.Exit(0)
return nil
}