Skip to content

Commit

Permalink
refactor: DirectiveArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Mar 12, 2017
1 parent 8f5605a commit 93ddece
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
13 changes: 5 additions & 8 deletions internal/common/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ import (
"github.com/neelance/graphql-go/internal/lexer"
)

type Directive struct {
Name string
Args map[string]interface{}
}
type DirectiveArgs map[string]interface{}

func ParseDirectives(l *lexer.Lexer) map[string]*Directive {
directives := make(map[string]*Directive)
func ParseDirectives(l *lexer.Lexer) map[string]DirectiveArgs {
directives := make(map[string]DirectiveArgs)
for l.Peek() == '@' {
l.ConsumeToken('@')
name := l.ConsumeIdent()
var args map[string]interface{}
var args DirectiveArgs
if l.Peek() == '(' {
args = ParseArguments(l)
}
directives[name] = &Directive{Name: name, Args: args}
directives[name] = args
}
return directives
}
10 changes: 5 additions & 5 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@ type typeAssertExec struct {
typeExec iExec
}

func skipByDirective(r *request, d map[string]*common.Directive) bool {
if skip, ok := d["skip"]; ok {
func skipByDirective(r *request, d map[string]common.DirectiveArgs) bool {
if args, ok := d["skip"]; ok {
p := valuePacker{valueType: boolType}
v, err := p.pack(r, r.resolveVar(skip.Args["if"]))
v, err := p.pack(r, r.resolveVar(args["if"]))
if err != nil {
r.addError(errors.Errorf("%s", err))
}
Expand All @@ -683,9 +683,9 @@ func skipByDirective(r *request, d map[string]*common.Directive) bool {
}
}

if include, ok := d["include"]; ok {
if args, ok := d["include"]; ok {
p := valuePacker{valueType: boolType}
v, err := p.pack(r, r.resolveVar(include.Args["if"]))
v, err := p.pack(r, r.resolveVar(args["if"]))
if err != nil {
r.addError(errors.Errorf("%s", err))
}
Expand Down
6 changes: 3 additions & 3 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ type Field struct {
Alias string
Name string
Arguments map[string]interface{}
Directives map[string]*common.Directive
Directives map[string]common.DirectiveArgs
SelSet *SelectionSet
}

type FragmentSpread struct {
Name string
Directives map[string]*common.Directive
Directives map[string]common.DirectiveArgs
}

type InlineFragment struct {
Fragment
Directives map[string]*common.Directive
Directives map[string]common.DirectiveArgs
}

func (Field) isSelection() {}
Expand Down

0 comments on commit 93ddece

Please sign in to comment.