graphql-go / graphql-go/graphql
Panic when passing a variable to a query
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
Basically when doing:
```
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: queryPost.Query,
OperationName: queryPost.OperationName,
VariableValues: queryPost.Variables,
})
```
When the query is:
```
query ResultsQuery($q: String!) {
queryResults(q: $q) {
results {
title
clickableuri
Excerpt
__typename
}
__typename
}
}
```
And the Variables contain a simple
`map[string]interface{}`
`map[q:event]`
It looks like there is a problem with the `String!` type for a variable. I do not understand the whole thing yet but this panics:
rules.go : ~ line 1720
`if ttype, ok := ttype.(*NonNull); ok {`
This generates an error:
```
err: gqlerrors.FormattedError{
Message: "Can only create NonNull of a Nullable Type but got: .",
Locations: []location.SourceLocation{},
}
```
For the type String!
The `ofType` is nil so the rest of the code crashes:
```
&graphql.NonNull{
PrivateName: "",
OfType: nil,
err: gqlerrors.FormattedError{
Message: "Can only create NonNull of a Nullable Type but got: .",
Locations: []location.SourceLocation{},
},
} ```
```
2017/05/19 12:43:46 http: panic serving [::1]:56953: runtime error: invalid memory address or nil pointer dereference
goroutine 97 [running]:
net/http.(*conn).serve.func1(0xc042298180)
C:/Go/src/net/http/server.go:1491 +0x131
panic(0x6e4680, 0xc04200c0a0)
C:/Go/src/runtime/panic.go:458 +0x251
github.com/graphql-go/graphql.isValidLiteralValue(0x87fb60, 0xc042357530, 0x0, 0x0, 0x0, 0xc0424106a0, 0x87fb60, 0x0)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/rules.go:1721 +0x15cd
github.com/graphql-go/graphql.DefaultValuesOfCorrectTypeRule.func1(0x6e57e0, 0xc04226c200, 0x6cd3c0, 0xc042410650, 0x0, 0x0, 0xc04226c440, 0x4, 0x4, 0xc04226c500, ...)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/rules.go:134 +0x151
github.com/graphql-go/graphql/language/visitor.VisitInParallel.func1(0x6e57e0, 0xc04226c200, 0x6cd3c0, 0xc042410650, 0x0, 0x0, 0xc04226c440, 0x4, 0x4, 0xc04226c500, ...)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/language/visitor/visitor.go:753 +0x205
github.com/graphql-go/graphql/language/visitor.VisitWithTypeInfo.func1(0x6e57e0, 0xc04226c200, 0x6cd3c0, 0xc042410650, 0x0, 0x0, 0xc04226c440, 0x4, 0x4, 0xc04226c500, ...)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/language/visitor/visitor.go:802 +0x1ac
github.com/graphql-go/graphql/language/visitor.Visit(0x87d2a0, 0xc0423566c0, 0xc042357440, 0x0, 0x11, 0xc042000800)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/language/visitor/visitor.go:419 +0x29aa
github.com/graphql-go/graphql.VisitUsingRules(0xc0421ec090, 0xc042298300, 0xc0423566c0, 0x896dc0, 0x18, 0x18, 0xc0424101b8, 0xc0424102b0, 0x0)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/validator.go:71 +0x3e0
github.com/graphql-go/graphql.ValidateDocument(0xc0421ec090, 0xc0423566c0, 0x0, 0x18, 0x18, 0x0, 0x0, 0xc04246f940, 0x53bd09)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/validator.go:47 +0x17b
github.com/graphql-go/graphql.Do(0x0, 0x899d20, 0x3, 0x3, 0xc0421fe320, 0x0, 0x0, 0x0, 0x0, 0xc042330000, ...)
C:/Users/erocheleau/Documents/!GoWorkspace/src/github.com/graphql-go/graphql/graphql.go:46 +0x2e0
main.GraphQLPOSTHandler(0x87f220, 0xc0420e80d0, 0xc04213c000)
```
Contributor guide
Assessment
This issue has not been assessed yet.