From 11917e08030f13ebbe644916c3f69e2d088aab91 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Thu, 14 Jul 2022 16:33:27 -0400 Subject: [PATCH 1/2] Define field arguments in a deterministic order --- definition.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/definition.go b/definition.go index 6bd9b431..d7dc19c8 100644 --- a/definition.go +++ b/definition.go @@ -5,6 +5,8 @@ import ( "fmt" "reflect" "regexp" + "sort" + "strings" "github.com/graphql-go/graphql/language/ast" ) @@ -588,6 +590,12 @@ func defineFieldMap(ttype Named, fieldMap Fields) (FieldDefinitionMap, error) { } fieldDef.Args = append(fieldDef.Args, fieldArg) } + + // Sort args so that their order is deterministic (alpha-numeric descending) + sort.Slice(fieldDef.Args, func(i, j int) bool { + return strings.Compare(fieldDef.Args[i].Name(), fieldDef.Args[j].Name()) == -1 + }) + resultFieldMap[fieldName] = fieldDef } return resultFieldMap, nil From b2134d216f42393ed5d815f0ea8cc3fa63776584 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Thu, 14 Jul 2022 17:12:08 -0400 Subject: [PATCH 2/2] Yield introspected input fields in deterministic order --- introspection.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/introspection.go b/introspection.go index 51feb42d..5ad73304 100644 --- a/introspection.go +++ b/introspection.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" "sort" + "strings" "github.com/graphql-go/graphql/language/ast" "github.com/graphql-go/graphql/language/printer" @@ -618,6 +619,12 @@ func init() { for _, field := range ttype.Fields() { fields = append(fields, field) } + + // Sort args so that their order is deterministic (alpha-numeric descending) + sort.Slice(fields, func(i, j int) bool { + return strings.Compare(fields[i].Name(), fields[j].Name()) == -1 + }) + return fields, nil } return nil, nil