github.com/mstephano/gqlgen-schemagen@v0.0.0-20230113041936-dd2cd4ea46aa/init-templates/generate.go.gotmpl (about)

     1  package main
     2  
     3  //go:generate go run generate.go
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  
     9  	"github.com/mstephano/gqlgen-schemagen/api"
    10  	"github.com/mstephano/gqlgen-schemagen/codegen/config"
    11  	"github.com/mstephano/gqlgen-schemagen/plugin/schemagen"
    12  )
    13  
    14  // MapDataTypes contains all scalars and defined types from a basic type
    15  var MapDataTypes = map[string]string{
    16  	"string":            "String",
    17  	"int":               "Int",
    18  	"bool":              "Boolean",
    19  	"float64":           "Float",
    20  }
    21  
    22  // MapDataTypeEclusions contains types that should not be in the GraphQL schema
    23  var MapDataTypeEclusions = map[string]string{}
    24  
    25  func main() {
    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  	p := schemagen.New(cfg, "{{.}}.graphqls", MapDataTypes, MapDataTypeEclusions)
    33  	err = api.Generate(cfg, api.AddPlugin(p))
    34  
    35  	if err != nil {
    36  		fmt.Fprintln(os.Stderr, err.Error())
    37  		os.Exit(3)
    38  	}
    39  }