diff options
author | Michael Muré <batolettre@gmail.com> | 2018-08-14 14:48:41 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-08-14 14:48:41 +0200 |
commit | 5c568a362b73cf163b06bc7371982f9a7ceaaf29 (patch) | |
tree | 755b61f969913b5290f3d56f4cfba4070b8155bc /vendor/github.com/vektah/gqlgen/codegen/enum_build.go | |
parent | ef0d8fa108fbdef24997a84a3c6ecbf21cbc0a9e (diff) | |
download | git-bug-5c568a362b73cf163b06bc7371982f9a7ceaaf29.tar.gz |
gqlgen: add a small program to go:generate the code
Diffstat (limited to 'vendor/github.com/vektah/gqlgen/codegen/enum_build.go')
-rw-r--r-- | vendor/github.com/vektah/gqlgen/codegen/enum_build.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/vektah/gqlgen/codegen/enum_build.go b/vendor/github.com/vektah/gqlgen/codegen/enum_build.go new file mode 100644 index 00000000..f2e6f63c --- /dev/null +++ b/vendor/github.com/vektah/gqlgen/codegen/enum_build.go @@ -0,0 +1,39 @@ +package codegen + +import ( + "sort" + "strings" + + "github.com/vektah/gqlgen/codegen/templates" + "github.com/vektah/gqlgen/neelance/schema" +) + +func (cfg *Config) buildEnums(types NamedTypes) []Enum { + var enums []Enum + + for _, typ := range cfg.schema.Types { + namedType := types[typ.TypeName()] + e, isEnum := typ.(*schema.Enum) + if !isEnum || strings.HasPrefix(typ.TypeName(), "__") || namedType.IsUserDefined { + continue + } + + var values []EnumValue + for _, v := range e.Values { + values = append(values, EnumValue{v.Name, v.Desc}) + } + + enum := Enum{ + NamedType: namedType, + Values: values, + } + enum.GoType = templates.ToCamel(enum.GQLType) + enums = append(enums, enum) + } + + sort.Slice(enums, func(i, j int) bool { + return strings.Compare(enums[i].GQLType, enums[j].GQLType) == -1 + }) + + return enums +} |