diff --git a/codegen/model.go b/codegen/model.go index 3b31f46d75..164a04d5b5 100644 --- a/codegen/model.go +++ b/codegen/model.go @@ -8,7 +8,7 @@ type Model struct { type ModelField struct { *Type - GQLName string + GQLName string GoVarName string GoFKName string GoFKType string diff --git a/codegen/templates/templates.go b/codegen/templates/templates.go index fa3a7507e3..5a17ec98b7 100644 --- a/codegen/templates/templates.go +++ b/codegen/templates/templates.go @@ -9,6 +9,7 @@ import ( "strings" "text/template" "unicode" + "sort" ) func Run(name string, tpldata interface{}) (*bytes.Buffer, error) { @@ -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() diff --git a/example/scalars/generated.go b/example/scalars/generated.go index e176b3e04d..5df780fa2a 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -203,7 +203,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col return graphql.Null } } else { - var tmp interface{} = map[string]interface{}{"location": "37,144"} + var tmp interface{} = map[string]interface{}{"isBanned": false, "location": "37,144"} var err error arg0, err = UnmarshalSearchArgs(tmp) if err != nil { @@ -1236,7 +1236,7 @@ func (ec *executionContext) introspectType(name string) *introspection.Type { var parsedSchema = schema.MustParse(`type Query { user(id: ID!): User - search(input: SearchArgs = {location: "37,144"}): [User!]! + search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! } type User { diff --git a/example/scalars/schema.graphql b/example/scalars/schema.graphql index 48463421e2..032e3f3a99 100644 --- a/example/scalars/schema.graphql +++ b/example/scalars/schema.graphql @@ -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 {