Skip to content

Commit

Permalink
Merge pull request #12 from dgraph-io/jatin/GRAPHQL-1007
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JatinDev543 authored Feb 25, 2021
2 parents 147d6c6 + d9375ee commit f103f8e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gqlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.Lis
if err != nil {
return nil, gqlerror.List{err}
}
errs := validator.Validate(schema, query)
errs := validator.Validate(schema, query, nil)
if errs != nil {
return nil, errs
}
Expand Down
4 changes: 2 additions & 2 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func AddRule(name string, f ruleFunc) {
rules = append(rules, rule{name: name, rule: f})
}

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

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

Walk(schema, doc, observers)
Walk(schema, doc, observers, variables)
return errs
}
2 changes: 1 addition & 1 deletion validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ extend type Query {
}
}`})
require.Nil(t, err)
require.Nil(t, validator.Validate(s, q))
require.Nil(t, validator.Validate(s, q, nil))
}
3 changes: 1 addition & 2 deletions validator/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package validator

import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"

"fmt"

"github.com/dgraph-io/gqlparser/v2/ast"
"github.com/dgraph-io/gqlparser/v2/gqlerror"
)
Expand Down
13 changes: 7 additions & 6 deletions validator/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@ func (o *Events) OnValue(f func(walker *Walker, value *ast.Value)) {
o.value = append(o.value, f)
}

func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events) {
func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events, variables map[string]interface{}) {
w := Walker{
Observers: observers,
Schema: schema,
Document: document,
Variables: variables,
}

w.walk()
}

type Walker struct {
Context context.Context
Observers *Events
Schema *ast.Schema
Document *ast.QueryDocument

Context context.Context
Observers *Events
Schema *ast.Schema
Document *ast.QueryDocument
Variables map[string]interface{}
validatedFragmentSpreads map[string]bool
CurrentOperation *ast.OperationDefinition
}
Expand Down
4 changes: 2 additions & 2 deletions validator/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestWalker(t *testing.T) {
require.Equal(t, "Query", field.ObjectDefinition.Name)
})

Walk(schema, query, observers)
Walk(schema, query, observers, nil)

require.True(t, called)
}
Expand All @@ -46,7 +46,7 @@ func TestWalkInlineFragment(t *testing.T) {
require.Equal(t, "Query", field.ObjectDefinition.Name)
})

Walk(schema, query, observers)
Walk(schema, query, observers, nil)

require.True(t, called)
}

0 comments on commit f103f8e

Please sign in to comment.