github.com/r0busta/go-shopify-graphql-model@v0.0.4/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/99designs/gqlgen/api" 8 "github.com/99designs/gqlgen/codegen/config" 9 "github.com/99designs/gqlgen/plugin/modelgen" 10 ) 11 12 // Defining mutation function 13 func mutateHook(b *modelgen.ModelBuild) *modelgen.ModelBuild { 14 for _, model := range b.Models { 15 for _, field := range model.Fields { 16 field.Tag = fmt.Sprintf(`json:"%s,omitempty"`, field.Name) 17 } 18 } 19 20 return b 21 } 22 23 func main() { 24 cfg, err := config.LoadConfigFromDefaultLocations() 25 if err != nil { 26 fmt.Fprintln(os.Stderr, "failed to load config", err.Error()) 27 os.Exit(2) 28 } 29 30 // Attaching the mutation function onto modelgen plugin 31 p := modelgen.Plugin{ 32 MutateHook: mutateHook, 33 } 34 35 err = api.Generate(cfg, 36 api.NoPlugins(), 37 api.AddPlugin(&p), 38 ) 39 if err != nil { 40 fmt.Fprintln(os.Stderr, err.Error()) 41 os.Exit(3) 42 } 43 }