Add support for GraphQL variables

This commit is contained in:
Vikram Rangnekar
2019-04-19 01:55:03 -04:00
parent 0755ecf6bd
commit 652b31ce38
10 changed files with 223 additions and 152 deletions

View File

@ -14,6 +14,8 @@ var (
type parserType int16
const (
maxNested = 50
parserError parserType = iota
parserEOF
opQuery
@ -50,6 +52,8 @@ func (t parserType) String() string {
v = "node-float"
case nodeBool:
v = "node-bool"
case nodeVar:
v = "node-var"
case nodeObj:
v = "node-obj"
case nodeList:
@ -253,7 +257,7 @@ func (p *Parser) parseFields() ([]*Field, int16, error) {
continue
}
if i > 500 {
if i > maxNested {
return nil, 0, errors.New("too many fields")
}

View File

@ -465,8 +465,10 @@ func (com *Compiler) compileArgID(sel *Select, arg *Arg) error {
ex.Type = ValInt
case nodeFloat:
ex.Type = ValFloat
case nodeVar:
ex.Type = ValVar
default:
fmt.Errorf("expecting an string, int or float")
fmt.Errorf("expecting a string, int, float or variable")
}
sel.Where = ex