Skip to content

Commit

Permalink
Merge pull request #1497 from polytomic/stable-introspection
Browse files Browse the repository at this point in the history
Return introspection document in stable order
  • Loading branch information
mtibben authored Sep 6, 2021
2 parents a0232dd + eb36f04 commit 50c2028
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions graphql/introspection/schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package introspection

import (
"sort"
"strings"

"github.com/vektah/gqlparser/v2/ast"
Expand All @@ -11,12 +12,20 @@ type Schema struct {
}

func (s *Schema) Types() []Type {
types := make([]Type, 0, len(s.schema.Types))
typeIndex := map[string]Type{}
typeNames := make([]string, 0, len(s.schema.Types))
for _, typ := range s.schema.Types {
if strings.HasPrefix(typ.Name, "__") {
continue
}
types = append(types, *WrapTypeFromDef(s.schema, typ))
typeNames = append(typeNames, typ.Name)
typeIndex[typ.Name] = *WrapTypeFromDef(s.schema, typ)
}
sort.Strings(typeNames)

types := make([]Type, len(typeNames))
for i, t := range typeNames {
types[i] = typeIndex[t]
}
return types
}
Expand All @@ -34,10 +43,18 @@ func (s *Schema) SubscriptionType() *Type {
}

func (s *Schema) Directives() []Directive {
res := make([]Directive, 0, len(s.schema.Directives))
dIndex := map[string]Directive{}
dNames := make([]string, 0, len(s.schema.Directives))

for _, d := range s.schema.Directives {
res = append(res, s.directiveFromDef(d))
dNames = append(dNames, d.Name)
dIndex[d.Name] = s.directiveFromDef(d)
}
sort.Strings(dNames)

res := make([]Directive, len(dNames))
for i, d := range dNames {
res[i] = dIndex[d]
}

return res
Expand Down

0 comments on commit 50c2028

Please sign in to comment.