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

sort introspection results #3

Merged
merged 3 commits into from
Nov 3, 2023
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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
- uses: actions/checkout@v3
- run: go test -v ./...
22 changes: 22 additions & 0 deletions introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package graphql
import (
"fmt"
"reflect"
"slices"
"sort"
"strings"

"github.com/dagger/graphql/language/ast"
"github.com/dagger/graphql/language/printer"
Expand Down Expand Up @@ -426,6 +428,9 @@ func init() {
for _, ttype := range schema.TypeMap() {
results = append(results, ttype)
}
slices.SortFunc(results, func(a, b Type) int {
return strings.Compare(a.Name(), b.Name())
})
return results, nil
}
return []Type{}, nil
Expand Down Expand Up @@ -474,6 +479,10 @@ func init() {
)),
Resolve: func(p ResolveParams) (any, error) {
if schema, ok := p.Source.(Schema); ok {
dirs := schema.Directives()
slices.SortFunc(dirs, func(a, b *Directive) int {
return strings.Compare(a.Name, b.Name)
})
return schema.Directives(), nil
}
return nil, nil
Expand Down Expand Up @@ -559,6 +568,9 @@ func init() {
}
fields = append(fields, field)
}
slices.SortFunc(fields, func(a, b *FieldDefinition) int {
return strings.Compare(a.Name, b.Name)
})
return fields, nil
}
return nil, nil
Expand Down Expand Up @@ -598,6 +610,10 @@ func init() {
includeDeprecated, _ := p.Args["includeDeprecated"].(bool)
if ttype, ok := p.Source.(*Enum); ok {
if includeDeprecated {
vals := ttype.Values()
slices.SortFunc(vals, func(a, b *EnumValueDefinition) int {
return strings.Compare(a.Name, b.Name)
})
return ttype.Values(), nil
}
values := []*EnumValueDefinition{}
Expand All @@ -607,6 +623,9 @@ func init() {
}
values = append(values, value)
}
slices.SortFunc(values, func(a, b *EnumValueDefinition) int {
return strings.Compare(a.Name, b.Name)
})
return values, nil
}
return nil, nil
Expand All @@ -620,6 +639,9 @@ func init() {
for _, field := range ttype.Fields() {
fields = append(fields, field)
}
slices.SortFunc(fields, func(a, b *InputObjectField) int {
return strings.Compare(a.PrivateName, b.PrivateName)
})
return fields, nil
}
return nil, nil
Expand Down