diff options
Diffstat (limited to 'vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go')
-rw-r--r-- | vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go b/vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go new file mode 100644 index 00000000..300a9407 --- /dev/null +++ b/vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go @@ -0,0 +1,30 @@ +package gqlerrors + +import "bytes" + +type FormattedErrors []FormattedError + +func (errs FormattedErrors) Len() int { + return len(errs) +} + +func (errs FormattedErrors) Swap(i, j int) { + errs[i], errs[j] = errs[j], errs[i] +} + +func (errs FormattedErrors) Less(i, j int) bool { + mCompare := bytes.Compare([]byte(errs[i].Message), []byte(errs[j].Message)) + lesserLine := errs[i].Locations[0].Line < errs[j].Locations[0].Line + eqLine := errs[i].Locations[0].Line == errs[j].Locations[0].Line + lesserColumn := errs[i].Locations[0].Column < errs[j].Locations[0].Column + if mCompare < 0 { + return true + } + if mCompare == 0 && lesserLine { + return true + } + if mCompare == 0 && eqLine && lesserColumn { + return true + } + return false +} |