graphql-go / graphql-go/graphql
panic when query syntax error
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
system: Ubuntu 16.04.01 TLS x64 / golang 1.7.3
The first example in README.md
```go
query := `
{
hello
}
`
```
if I change the query, as
```go
query := `
{
hello
}
{
hello
}
`
```
it should be report syntax error, but it throw panic
```
» go run hello.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x4fd855]
goroutine 1 [running]:
panic(0x56ac00, 0xc42000a180)
/usr/local/src/go/src/runtime/panic.go:500 +0x1a1
github.com/graphql-go/graphql/language/ast.(*Name).GetLoc(0x0, 0x0)
/go/src/github.com/graphql-go/graphql/language/ast/name.go:30 +0x5
github.com/graphql-go/graphql/gqlerrors.NewError(0xc4200a0ae0, 0x29, 0xc420013ae0, 0x2, 0x2, 0xc4200a0ae0, 0x29, 0x0, 0x669c60, 0x0, ...)
/go/src/github.com/graphql-go/graphql/gqlerrors/error.go:33 +0x60a
github.com/graphql-go/graphql.newValidationError(0xc4200a0ae0, 0x29, 0xc420013ae0, 0x2, 0x2, 0xc420013ae0)
/go/src/github.com/graphql-go/graphql/rules.go:55 +0xc1
github.com/graphql-go/graphql.reportError(0xc42005fd40, 0xc4200a0ae0, 0x29, 0xc420013ae0, 0x2, 0x2, 0x29, 0x16db889315c, 0x0, 0x0)
/go/src/github.com/graphql-go/graphql/rules.go:59 +0x57
github.com/graphql-go/graphql.UniqueOperationNamesRule.func1(0x57e500, 0xc420020a10, 0x55dae0, 0xc4200b6298, 0x0, 0x0, 0xc42001a600, 0x2, 0x8, 0xc4200b62d0, ...)
/go/src/github.com/graphql-go/graphql/rules.go:1938 +0x22d
github.com/graphql-go/graphql/language/visitor.VisitInParallel.func1(0x57e500, 0xc420020a10, 0x55dae0, 0xc4200b6298, 0x0, 0x0, 0xc42001a600, 0x2, 0x8, 0xc4200b62d0, ...)
/go/src/github.com/graphql-go/graphql/language/visitor/visitor.go:734 +0x1fe
github.com/graphql-go/graphql/language/visitor.VisitWithTypeInfo.func1(0x57e500, 0xc420020a10, 0x55dae0, 0xc4200b6298, 0x0, 0x0, 0xc42001a600, 0x2, 0x8, 0xc4200b62d0, ...)
/go/src/github.com/graphql-go/graphql/language/visitor/visitor.go:783 +0x1a5
github.com/graphql-go/graphql/language/visitor.Visit(0x63ac40, 0xc420017920, 0xc4200a0660, 0x0, 0x11, 0xc42008c200)
/go/src/github.com/graphql-go/graphql/language/visitor/visitor.go:400 +0x289c
github.com/graphql-go/graphql.VisitUsingRules(0xc42001c1b0, 0xc42001a400, 0xc420017920, 0x64d100, 0x18, 0x18, 0xa, 0xc420012f00, 0x0)
/go/src/github.com/graphql-go/graphql/validator.go:71 +0x3d9
github.com/graphql-go/graphql.ValidateDocument(0xc42001c1b0, 0xc420017920, 0x0, 0x18, 0x18, 0x0, 0x669c60, 0x0, 0xc420012bc0)
/go/src/github.com/graphql-go/graphql/validator.go:47 +0x174
github.com/graphql-go/graphql.Do(0xc420017680, 0xc42000ad10, 0x2, 0x2, 0xc420088820, 0x0, 0x0, 0xc420017800, 0x0, 0x59e78a, ...)
/go/src/github.com/graphql-go/graphql/graphql.go:46 +0x2d9
main.main()
/tmp/hello.go:38 +0x32b
exit status 2
```
full file `/tmp/hello.go`
```
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/graphql-go/graphql"
)
func main() {
// Schema
fields := graphql.Fields{
"hello": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "world", nil
},
},
}
rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("failed to create new schema, error: %v", err)
}
// Query
query := `
{
hello
}
{
hello
}
`
params := graphql.Params{Schema: schema, RequestString: query}
r := graphql.Do(params)
if len(r.Errors) > 0 {
log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
}
rJSON, _ := json.Marshal(r)
fmt.Printf("%s \n", rJSON) // {“data”:{“hello”:”world”}}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.