Skip to content

Commit

Permalink
Merge pull request 99designs#321 from 99designs/remove-typemap
Browse files Browse the repository at this point in the history
Remove support for the old json typemap
  • Loading branch information
vektah authored Aug 27, 2018
2 parents 3869689 + b6cf825 commit ab27035
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 45 deletions.
40 changes: 0 additions & 40 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/99designs/gqlgen/codegen"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

func init() {
Expand Down Expand Up @@ -39,7 +38,6 @@ var genCmd = &cobra.Command{
}

// overwrite by commandline options
var emitYamlGuidance bool
if schemaFilename != "" {
config.SchemaFilename = schemaFilename
}
Expand All @@ -55,10 +53,6 @@ var genCmd = &cobra.Command{
if modelPackageName != "" {
config.Model.Package = modelPackageName
}
if typemap != "" {
config.Models = loadModelMap()
emitYamlGuidance = true
}

schemaRaw, err := ioutil.ReadFile(config.SchemaFilename)
if err != nil {
Expand All @@ -72,44 +66,10 @@ var genCmd = &cobra.Command{
os.Exit(1)
}

if emitYamlGuidance {
var b []byte
b, err = yaml.Marshal(config)
if err != nil {
fmt.Fprintln(os.Stderr, "unable to marshal yaml: "+err.Error())
os.Exit(1)
}

fmt.Fprintf(os.Stderr, "DEPRECATION WARNING: we are moving away from the json typemap, instead create a gqlgen.yml with the following content:\n\n%s\n", string(b))
}

err = codegen.Generate(*config)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(2)
}
},
}

func loadModelMap() codegen.TypeMap {
var goTypes map[string]string
b, err := ioutil.ReadFile(typemap)
if err != nil {
fmt.Fprintln(os.Stderr, "unable to open typemap: "+err.Error())
return nil
}

if err = yaml.Unmarshal(b, &goTypes); err != nil {
fmt.Fprintln(os.Stderr, "unable to parse typemap: "+err.Error())
os.Exit(1)
}

typeMap := make(codegen.TypeMap)
for typeName, entityPath := range goTypes {
typeMap[typeName] = codegen.TypeMapEntry{
Model: entityPath,
}
}

return typeMap
}
3 changes: 0 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ func initConfig() *codegen.Config {
if modelPackageName != "" {
config.Model.Package = modelPackageName
}
if typemap != "" {
config.Models = loadModelMap()
}

var buf bytes.Buffer
buf.WriteString(strings.TrimSpace(configComment))
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var verbose bool
var output string
var models string
var schemaFilename string
var typemap string
var packageName string
var modelPackageName string
var serverFilename string
Expand All @@ -29,7 +28,6 @@ func init() {
rootCmd.PersistentFlags().StringVar(&output, "out", "", "the file to write to")
rootCmd.PersistentFlags().StringVar(&models, "models", "", "the file to write the models to")
rootCmd.PersistentFlags().StringVar(&schemaFilename, "schema", "", "the graphql schema to generate types from")
rootCmd.PersistentFlags().StringVar(&typemap, "typemap", "", "a json map going from graphql to golang types")
rootCmd.PersistentFlags().StringVar(&packageName, "package", "", "the package name")
rootCmd.PersistentFlags().StringVar(&modelPackageName, "modelpackage", "", "the package name to use for models")
}
Expand Down

0 comments on commit ab27035

Please sign in to comment.