Skip to content

Fix unmarshalling variables from form data #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func getFromForm(values url.Values) *RequestOptions {
// get variables map
var variables map[string]interface{}
variablesStr := values.Get("variables")
json.Unmarshal([]byte(variablesStr), variables)
json.Unmarshal([]byte(variablesStr), &variables)

return &RequestOptions{
Query: query,
Expand Down
21 changes: 21 additions & 0 deletions request_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ func TestRequestOptions_POST_ContentTypeApplicationJSON(t *testing.T) {
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
}
}

func TestRequestOptions_GET_WithVariablesAsObject(t *testing.T) {
query := url.QueryEscape("query RebelsShipsQuery { rebels { name } }")
variables := url.QueryEscape(`{ "a": 1, "b": "2" }`)
queryString := fmt.Sprintf("query=%s&variables=%s", query, variables)
expected := &RequestOptions{
Query: "query RebelsShipsQuery { rebels { name } }",
Variables: map[string]interface{}{
"a": float64(1),
"b": "2",
},
}

req, _ := http.NewRequest("GET", fmt.Sprintf("/graphql?%v", queryString), nil)
result := NewRequestOptions(req)

if !reflect.DeepEqual(result, expected) {
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
}
}

func TestRequestOptions_POST_ContentTypeApplicationJSON_WithVariablesAsObject(t *testing.T) {
body := `
{
Expand Down