From 30dcc339f36601cf099e4853093d93b1c63387b1 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Sun, 19 Mar 2017 18:58:17 +0100 Subject: [PATCH] directive arguments as slice --- internal/schema/schema.go | 21 +++++++++------------ introspection/introspection.go | 6 +++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/internal/schema/schema.go b/internal/schema/schema.go index 69460a06ae..4af17208cd 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -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" } @@ -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 @@ -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(')') } diff --git a/introspection/introspection.go b/introspection/introspection.go index f73aa1156a..5c0e27354c 100644 --- a/introspection/introspection.go +++ b/introspection/introspection.go @@ -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 }