Skip to content

Commit f103f8e

Browse files
authored
Merge pull request #12 from dgraph-io/jatin/GRAPHQL-1007
Fixes: GRAPHQL-1007 We have allowed to paas @cascade arguments through variables in dgraph. For that we needed input validations check which is added in this library.
2 parents 147d6c6 + d9375ee commit f103f8e

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

gqlparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.Lis
2525
if err != nil {
2626
return nil, gqlerror.List{err}
2727
}
28-
errs := validator.Validate(schema, query)
28+
errs := validator.Validate(schema, query, nil)
2929
if errs != nil {
3030
return nil, errs
3131
}

validator/validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func AddRule(name string, f ruleFunc) {
2222
rules = append(rules, rule{name: name, rule: f})
2323
}
2424

25-
func Validate(schema *Schema, doc *QueryDocument) gqlerror.List {
25+
func Validate(schema *Schema, doc *QueryDocument, variables map[string]interface{}) gqlerror.List {
2626
var errs gqlerror.List
2727

2828
observers := &Events{}
@@ -39,6 +39,6 @@ func Validate(schema *Schema, doc *QueryDocument) gqlerror.List {
3939
})
4040
}
4141

42-
Walk(schema, doc, observers)
42+
Walk(schema, doc, observers, variables)
4343
return errs
4444
}

validator/validator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ extend type Query {
3737
}
3838
}`})
3939
require.Nil(t, err)
40-
require.Nil(t, validator.Validate(s, q))
40+
require.Nil(t, validator.Validate(s, q, nil))
4141
}

validator/vars.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package validator
22

33
import (
44
"errors"
5+
"fmt"
56
"reflect"
67
"strconv"
78
"strings"
89

9-
"fmt"
10-
1110
"github.com/dgraph-io/gqlparser/v2/ast"
1211
"github.com/dgraph-io/gqlparser/v2/gqlerror"
1312
)

validator/walk.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,23 @@ func (o *Events) OnValue(f func(walker *Walker, value *ast.Value)) {
4343
o.value = append(o.value, f)
4444
}
4545

46-
func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events) {
46+
func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events, variables map[string]interface{}) {
4747
w := Walker{
4848
Observers: observers,
4949
Schema: schema,
5050
Document: document,
51+
Variables: variables,
5152
}
5253

5354
w.walk()
5455
}
5556

5657
type Walker struct {
57-
Context context.Context
58-
Observers *Events
59-
Schema *ast.Schema
60-
Document *ast.QueryDocument
61-
58+
Context context.Context
59+
Observers *Events
60+
Schema *ast.Schema
61+
Document *ast.QueryDocument
62+
Variables map[string]interface{}
6263
validatedFragmentSpreads map[string]bool
6364
CurrentOperation *ast.OperationDefinition
6465
}

validator/walk_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestWalker(t *testing.T) {
2525
require.Equal(t, "Query", field.ObjectDefinition.Name)
2626
})
2727

28-
Walk(schema, query, observers)
28+
Walk(schema, query, observers, nil)
2929

3030
require.True(t, called)
3131
}
@@ -46,7 +46,7 @@ func TestWalkInlineFragment(t *testing.T) {
4646
require.Equal(t, "Query", field.ObjectDefinition.Name)
4747
})
4848

49-
Walk(schema, query, observers)
49+
Walk(schema, query, observers, nil)
5050

5151
require.True(t, called)
5252
}

0 commit comments

Comments
 (0)