Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix template error on generated defaults #146

Merged
merged 5 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Model struct {

type ModelField struct {
*Type
GQLName string
GQLName string
GoVarName string
GoFKName string
GoFKType string
Expand Down
12 changes: 11 additions & 1 deletion codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"text/template"
"unicode"
"sort"
)

func Run(name string, tpldata interface{}) (*bytes.Buffer, error) {
Expand Down Expand Up @@ -111,10 +112,19 @@ func dump(val interface{}) string {
case map[string]interface{}:
buf := bytes.Buffer{}
buf.WriteString("map[string]interface{}{")
for key, data := range val {
var keys []string
for key := range val {
keys = append(keys, key)
}
sort.Strings(keys)

for _, key := range keys {
data := val[key]

buf.WriteString(strconv.Quote(key))
buf.WriteString(":")
buf.WriteString(dump(data))
buf.WriteString(",")
}
buf.WriteString("}")
return buf.String()
Expand Down
4 changes: 2 additions & 2 deletions example/scalars/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/scalars/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Query {
user(id: ID!): User
search(input: SearchArgs = {location: "37,144"}): [User!]!
search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]!
}

type User {
Expand Down