...

Source file src/github.com/99designs/gqlgen/testdata/gqlgen.go

Documentation: github.com/99designs/gqlgen/testdata

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"io"
     7  	"log"
     8  	"os"
     9  	"time"
    10  
    11  	"github.com/99designs/gqlgen/api"
    12  	"github.com/99designs/gqlgen/codegen/config"
    13  	"github.com/99designs/gqlgen/graphql"
    14  	"github.com/99designs/gqlgen/plugin/stubgen"
    15  )
    16  
    17  func main() {
    18  	stub := flag.String("stub", "", "name of stub file to generate")
    19  	cfgPath := flag.String("config", "", "path to config file (use default if omitted)")
    20  	flag.Parse()
    21  
    22  	log.SetOutput(io.Discard)
    23  
    24  	start := graphql.Now()
    25  
    26  	var cfg *config.Config
    27  	var err error
    28  	if cfgPath != nil && *cfgPath != "" {
    29  		cfg, err = config.LoadConfig(*cfgPath)
    30  	} else {
    31  		cfg, err = config.LoadConfigFromDefaultLocations()
    32  	}
    33  	if err != nil {
    34  		fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
    35  		os.Exit(2)
    36  	}
    37  
    38  	var options []api.Option
    39  	if *stub != "" {
    40  		options = append(options, api.AddPlugin(stubgen.New(*stub, "Stub")))
    41  	}
    42  
    43  	err = api.Generate(cfg, options...)
    44  	if err != nil {
    45  		fmt.Fprintln(os.Stderr, err.Error())
    46  		os.Exit(3)
    47  	}
    48  
    49  	fmt.Printf("Generated %s in %4.2fs\n", cfg.Exec.ImportPath(), time.Since(start).Seconds())
    50  }
    51  

View as plain text