Skip to content

Commit 1ce3dcd

Browse files
Add query with variable test
1 parent 199d20b commit 1ce3dcd

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

graphql_test.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
)
1111

1212
type T struct {
13-
Query string
14-
Schema graphql.Schema
15-
Expected interface{}
13+
Query string
14+
Schema graphql.Schema
15+
Expected interface{}
16+
Variables map[string]interface{}
1617
}
1718

1819
var Tests = []T{}
@@ -69,14 +70,35 @@ func init() {
6970
},
7071
},
7172
},
73+
{
74+
Query: `
75+
query HumanByIdQuery($id: String!) {
76+
human(id: $id) {
77+
name
78+
}
79+
}
80+
`,
81+
Schema: testutil.StarWarsSchema,
82+
Expected: &graphql.Result{
83+
Data: map[string]interface{}{
84+
"human": map[string]interface{}{
85+
"name": "Darth Vader",
86+
},
87+
},
88+
},
89+
Variables: map[string]interface{}{
90+
"id": "1001",
91+
},
92+
},
7293
}
7394
}
7495

7596
func TestQuery(t *testing.T) {
7697
for _, test := range Tests {
7798
params := graphql.Params{
78-
Schema: test.Schema,
79-
RequestString: test.Query,
99+
Schema: test.Schema,
100+
RequestString: test.Query,
101+
VariableValues: test.Variables,
80102
}
81103
testGraphql(test, params, t)
82104
}

0 commit comments

Comments
 (0)