Skip to content

Commit

Permalink
allow single value as implicit list (fixes #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Dec 19, 2016
1 parent 2b513d7 commit 7fafcc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ func TestInput(t *testing.T) {
boolean(value: true)
nullable1: nullable(value: 42)
nullable2: nullable(value: null)
list(value: [{v: 41}, {v: 42}, {v: 43}])
list1: list(value: [{v: 41}, {v: 42}, {v: 43}])
list2: list(value: {v: 42})
}
`,
ExpectedResult: `
Expand All @@ -1383,7 +1384,8 @@ func TestInput(t *testing.T) {
"boolean": true,
"nullable1": 42,
"nullable2": null,
"list": [41, 42, 43]
"list1": [41, 42, 43],
"list2": [42]
}
`,
},
Expand Down
6 changes: 5 additions & 1 deletion internal/exec/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ func (e *listPacker) pack(r *request, value interface{}) (reflect.Value, error)
value = r.vars[string(v)]
}

list := value.([]interface{})
list, ok := value.([]interface{})
if !ok {
list = []interface{}{value}
}

v := reflect.MakeSlice(e.sliceType, len(list), len(list))
for i := range list {
packed, err := e.elem.pack(r, list[i])
Expand Down

0 comments on commit 7fafcc6

Please sign in to comment.