aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/graphql-go/graphql/gqlerrors/sortutil.go
blob: 300a9407987523a17666dc1f5415b1fccaeb4cf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}