diff options
Diffstat (limited to 'vendor/github.com/graphql-go/graphql/gqlerrors/located.go')
-rw-r--r-- | vendor/github.com/graphql-go/graphql/gqlerrors/located.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/graphql-go/graphql/gqlerrors/located.go b/vendor/github.com/graphql-go/graphql/gqlerrors/located.go new file mode 100644 index 00000000..b02fcd8a --- /dev/null +++ b/vendor/github.com/graphql-go/graphql/gqlerrors/located.go @@ -0,0 +1,39 @@ +package gqlerrors + +import ( + "errors" + "github.com/graphql-go/graphql/language/ast" +) + +// NewLocatedError creates a graphql.Error with location info +// @deprecated 0.4.18 +// Already exists in `graphql.NewLocatedError()` +func NewLocatedError(err interface{}, nodes []ast.Node) *Error { + 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 NewError( + message, + nodes, + stack, + nil, + []int{}, + origError, + ) +} + +func FieldASTsToNodeASTs(fieldASTs []*ast.Field) []ast.Node { + nodes := []ast.Node{} + for _, fieldAST := range fieldASTs { + nodes = append(nodes, fieldAST) + } + return nodes +} |