Skip to content

Commit

Permalink
directive arguments as slice
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Mar 19, 2017
1 parent d331ac2 commit 30dcc33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
21 changes: 9 additions & 12 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ func (l FieldList) Get(name string) *Field {
}

type Directive struct {
Name string
Desc string
Locs []string
Args map[string]*common.InputValue
ArgOrder []string
Name string
Desc string
Locs []string
Args common.InputValueList
}

func (*Scalar) Kind() string { return "SCALAR" }
Expand Down Expand Up @@ -271,13 +270,13 @@ func resolveDirectives(s *Schema, directives map[string]common.ArgumentList) err
return errors.Errorf("directive %q not found", name)
}
for _, arg := range args {
if _, ok := d.Args[arg.Name]; !ok {
if d.Args.Get(arg.Name) == nil {
return errors.Errorf("invalid argument %q for directive %q", arg.Name, name)
}
}
for argName, arg := range d.Args {
if args.Get(argName).Value == nil {
args = append(args, common.Argument{Name: argName, Value: common.ValueWithLoc{Value: arg.Default}})
for _, arg := range d.Args {
if args.Get(arg.Name).Value == nil {
args = append(args, common.Argument{Name: arg.Name, Value: common.ValueWithLoc{Value: arg.Default}})
}
}
directives[name] = args
Expand Down Expand Up @@ -412,15 +411,13 @@ func parseEnumDecl(l *lexer.Lexer) *Enum {

func parseDirectiveDecl(l *lexer.Lexer) *Directive {
d := &Directive{}
d.Args = make(map[string]*common.InputValue)
l.ConsumeToken('@')
d.Name = l.ConsumeIdent()
if l.Peek() == '(' {
l.ConsumeToken('(')
for l.Peek() != ')' {
v := common.ParseInputValue(l)
d.Args[v.Name] = v
d.ArgOrder = append(d.ArgOrder, v.Name)
d.Args = append(d.Args, v)
}
l.ConsumeToken(')')
}
Expand Down
6 changes: 3 additions & 3 deletions introspection/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ func (r *Directive) Locations() []string {
}

func (r *Directive) Args() []*InputValue {
l := make([]*InputValue, len(r.directive.ArgOrder))
for i, name := range r.directive.ArgOrder {
l[i] = &InputValue{r.directive.Args[name]}
l := make([]*InputValue, len(r.directive.Args))
for i, v := range r.directive.Args {
l[i] = &InputValue{v}
}
return l
}

0 comments on commit 30dcc33

Please sign in to comment.