Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ramon authored Jul 23, 2017
2 parents b60caa6 + 96585f9 commit c0ad112
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gqlerrors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gqlerrors

import (
"fmt"
"reflect"

"github.com/graphql-go/graphql/language/ast"
"github.com/graphql-go/graphql/language/location"
Expand Down Expand Up @@ -30,6 +31,9 @@ func NewError(message string, nodes []ast.Node, stack string, source *source.Sou
if source == nil {
for _, node := range nodes {
// get source from first node
if node == nil || reflect.ValueOf(node).IsNil() {
continue
}
if node.GetLoc() != nil {
source = node.GetLoc().Source
}
Expand All @@ -38,6 +42,9 @@ func NewError(message string, nodes []ast.Node, stack string, source *source.Sou
}
if len(positions) == 0 && len(nodes) > 0 {
for _, node := range nodes {
if node == nil || reflect.ValueOf(node).IsNil() {
continue
}
if node.GetLoc() == nil {
continue
}
Expand Down
27 changes: 27 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,30 @@ func TestThreadsContextFromParamsThrough(t *testing.T) {
}

}

func TestNewErrorChecksNilNodes(t *testing.T) {
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"graphql_is": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "", nil
},
},
},
}),
})
if err != nil {
t.Fatalf("unexpected errors: %v", err.Error())
}
query := `{graphql_is:great(sort:ByPopularity)}{stars}`
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: query,
})
if len(result.Errors) == 0 {
t.Fatalf("expected errors, got: %v", result)
}
}

0 comments on commit c0ad112

Please sign in to comment.