-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from vektah/generate-enums
Generate enums
- Loading branch information
Showing
12 changed files
with
247 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package codegen | ||
|
||
type Enum struct { | ||
*NamedType | ||
|
||
Values []EnumValue | ||
} | ||
|
||
type EnumValue struct { | ||
Name string | ||
Description string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package codegen | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
|
||
"github.com/vektah/gqlgen/neelance/schema" | ||
) | ||
|
||
func buildEnums(types NamedTypes, s *schema.Schema) []Enum { | ||
var enums []Enum | ||
|
||
for _, typ := range s.Types { | ||
if strings.HasPrefix(typ.TypeName(), "__") { | ||
continue | ||
} | ||
if e, ok := typ.(*schema.Enum); ok { | ||
var values []EnumValue | ||
for _, v := range e.Values { | ||
values = append(values, EnumValue{v.Name, v.Desc}) | ||
} | ||
|
||
enum := Enum{ | ||
NamedType: types[e.TypeName()], | ||
Values: values, | ||
} | ||
enum.GoType = ucFirst(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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.