git.sr.ht/~sircmpwn/gqlgen@v0.0.0-20200522192042-c84d29a1c940/testdata/gqlgen.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "io/ioutil" 7 "log" 8 "os" 9 "time" 10 11 "git.sr.ht/~sircmpwn/gqlgen/graphql" 12 13 "git.sr.ht/~sircmpwn/gqlgen/api" 14 "git.sr.ht/~sircmpwn/gqlgen/codegen/config" 15 "git.sr.ht/~sircmpwn/gqlgen/plugin/stubgen" 16 ) 17 18 func main() { 19 stub := flag.String("stub", "", "name of stub file to generate") 20 flag.Parse() 21 22 log.SetOutput(ioutil.Discard) 23 24 start := graphql.Now() 25 26 cfg, err := config.LoadConfigFromDefaultLocations() 27 if err != nil { 28 fmt.Fprintln(os.Stderr, "failed to load config", err.Error()) 29 os.Exit(2) 30 } 31 32 var options []api.Option 33 if *stub != "" { 34 options = append(options, api.AddPlugin(stubgen.New(*stub, "Stub"))) 35 } 36 37 err = api.Generate(cfg, options...) 38 if err != nil { 39 fmt.Fprintln(os.Stderr, err.Error()) 40 os.Exit(3) 41 } 42 43 fmt.Printf("Generated %s in %4.2fs\n", cfg.Exec.ImportPath(), time.Since(start).Seconds()) 44 }