Skip to content

Commit e8c319a

Browse files
authored
Append the individual elements of select args, not the slice (#6)
* Append the individual elements of select args, not the slice * Change to current test naming convention
1 parent 5a815b5 commit e8c319a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

query_operation_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,33 @@ func Test_Multiple_Blocks(t *testing.T) {
5454

5555
require.Equal(t, expected, query)
5656
}
57+
58+
func Test_Multiple_Blocks_With_Select(t *testing.T) {
59+
q1 := dql.Query(dql.EqFn("id", "id_a")).
60+
Select(dql.As("id_a", "id"))
61+
62+
q2 := dql.Query(dql.EqFn("id", "id_b")).
63+
Select(dql.As("id_b", "id"))
64+
65+
query, variables, err := dql.QueriesToDQL(q1, q2)
66+
67+
require.NoError(t, err)
68+
69+
require.Equal(t, map[string]string{
70+
"$0": "id_a",
71+
"$1": "id_b",
72+
}, variables)
73+
74+
expected := dql.Minify(`
75+
query Rootquery_Rootquery_1($0:string, $1:string) {
76+
<rootQuery>(func: eq(<id>,$0)) {
77+
id_a AS <id>
78+
}
79+
<rootQuery_1>(func: eq(<id>,$1)) {
80+
id_b AS <id>
81+
}
82+
}
83+
`)
84+
85+
require.Equal(t, expected, query)
86+
}

selection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (fields nodeAttributes) ToDQL() (query string, args []interface{}, err erro
8181
return "", nil, err
8282
}
8383

84-
args = append(args, computedArgs)
84+
args = append(args, computedArgs...)
8585
selectedFields = append(selectedFields, computedDql)
8686
case string:
8787
fieldString := parsePredicates(requestField)

0 commit comments

Comments
 (0)