Skip to content

Commit

Permalink
Merge pull request #821 from 99designs/fix-init
Browse files Browse the repository at this point in the history
Fix config loading during gqlgen init
  • Loading branch information
vektah authored Aug 8, 2019
2 parents 2599f56 + 5fafe79 commit 12893fa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,26 @@ var initCmd = cli.Command{
},
Action: func(ctx *cli.Context) {
initSchema(ctx.String("schema"))
config := initConfig(ctx)
initConfig(ctx)

GenerateGraphServer(config, ctx.String("server"))
GenerateGraphServer(ctx.String("server"))
},
}

func GenerateGraphServer(cfg *config.Config, serverFilename string) {
err := api.Generate(cfg, api.AddPlugin(servergen.New(serverFilename)))
func GenerateGraphServer(serverFilename string) {
cfg, err := config.LoadConfigFromDefaultLocations()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
err = api.Generate(cfg, api.AddPlugin(servergen.New(serverFilename)))
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}

fmt.Fprintf(os.Stdout, "Exec \"go run ./%s\" to start GraphQL server\n", serverFilename)
}

func initConfig(ctx *cli.Context) *config.Config {
func initConfig(ctx *cli.Context) {
var cfg *config.Config
var err error
configFilename := ctx.String("config")
Expand Down Expand Up @@ -126,8 +130,6 @@ func initConfig(ctx *cli.Context) *config.Config {
fmt.Fprintln(os.Stderr, "unable to write cfg file: "+err.Error())
os.Exit(1)
}

return cfg
}

func initSchema(schemaFilename string) {
Expand Down

0 comments on commit 12893fa

Please sign in to comment.