-
Notifications
You must be signed in to change notification settings - Fork 842
/
located.go
51 lines (44 loc) · 1.05 KB
/
located.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package graphql
import (
"errors"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/language/ast"
)
func NewLocatedError(err interface{}, nodes []ast.Node) *gqlerrors.Error {
return newLocatedError(err, nodes, nil)
}
func NewLocatedErrorWithPath(err interface{}, nodes []ast.Node, path []interface{}) *gqlerrors.Error {
return newLocatedError(err, nodes, path)
}
func newLocatedError(err interface{}, nodes []ast.Node, path []interface{}) *gqlerrors.Error {
if err, ok := err.(*gqlerrors.Error); ok {
return err
}
var origError error
message := "An unknown error occurred."
if err, ok := err.(error); ok {
message = err.Error()
origError = err
}
if err, ok := err.(string); ok {
message = err
origError = errors.New(err)
}
stack := message
return gqlerrors.NewErrorWithPath(
message,
nodes,
stack,
nil,
[]int{},
path,
origError,
)
}
func FieldASTsToNodeASTs(fieldASTs []*ast.Field) []ast.Node {
nodes := []ast.Node{}
for _, fieldAST := range fieldASTs {
nodes = append(nodes, fieldAST)
}
return nodes
}