Skip to content

Commit 93ddece

Browse files
committed
refactor: DirectiveArgs
1 parent 8f5605a commit 93ddece

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

internal/common/directive.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ import (
44
"github.com/neelance/graphql-go/internal/lexer"
55
)
66

7-
type Directive struct {
8-
Name string
9-
Args map[string]interface{}
10-
}
7+
type DirectiveArgs map[string]interface{}
118

12-
func ParseDirectives(l *lexer.Lexer) map[string]*Directive {
13-
directives := make(map[string]*Directive)
9+
func ParseDirectives(l *lexer.Lexer) map[string]DirectiveArgs {
10+
directives := make(map[string]DirectiveArgs)
1411
for l.Peek() == '@' {
1512
l.ConsumeToken('@')
1613
name := l.ConsumeIdent()
17-
var args map[string]interface{}
14+
var args DirectiveArgs
1815
if l.Peek() == '(' {
1916
args = ParseArguments(l)
2017
}
21-
directives[name] = &Directive{Name: name, Args: args}
18+
directives[name] = args
2219
}
2320
return directives
2421
}

internal/exec/exec.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,10 @@ type typeAssertExec struct {
671671
typeExec iExec
672672
}
673673

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

686-
if include, ok := d["include"]; ok {
686+
if args, ok := d["include"]; ok {
687687
p := valuePacker{valueType: boolType}
688-
v, err := p.pack(r, r.resolveVar(include.Args["if"]))
688+
v, err := p.pack(r, r.resolveVar(args["if"]))
689689
if err != nil {
690690
r.addError(errors.Errorf("%s", err))
691691
}

internal/query/query.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ type Field struct {
5151
Alias string
5252
Name string
5353
Arguments map[string]interface{}
54-
Directives map[string]*common.Directive
54+
Directives map[string]common.DirectiveArgs
5555
SelSet *SelectionSet
5656
}
5757

5858
type FragmentSpread struct {
5959
Name string
60-
Directives map[string]*common.Directive
60+
Directives map[string]common.DirectiveArgs
6161
}
6262

6363
type InlineFragment struct {
6464
Fragment
65-
Directives map[string]*common.Directive
65+
Directives map[string]common.DirectiveArgs
6666
}
6767

6868
func (Field) isSelection() {}

0 commit comments

Comments
 (0)