Skip to content

Commit 096f5bc

Browse files
authored
Merge pull request #216 from WindomZ/master
Examples: use '.Get("query")' instead of '["query"][0]'
2 parents 3e619b6 + b2b9069 commit 096f5bc

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

examples/context/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func graphqlHandler(w http.ResponseWriter, r *http.Request) {
4646
}{1, "cool user"}
4747
result := graphql.Do(graphql.Params{
4848
Schema: Schema,
49-
RequestString: r.URL.Query()["query"][0],
49+
RequestString: r.URL.Query().Get("query"),
5050
Context: context.WithValue(context.Background(), "currentUser", user),
5151
})
5252
if len(result.Errors) > 0 {

examples/http/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func main() {
8888
_ = importJSONDataFromFile("data.json", &data)
8989

9090
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
91-
result := executeQuery(r.URL.Query()["query"][0], schema)
91+
result := executeQuery(r.URL.Query().Get("query"), schema)
9292
json.NewEncoder(w).Encode(result)
9393
})
9494

examples/httpdynamic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func main() {
127127
}
128128

129129
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
130-
result := executeQuery(r.URL.Query()["query"][0], schema)
130+
result := executeQuery(r.URL.Query().Get("query"), schema)
131131
json.NewEncoder(w).Encode(result)
132132
})
133133

examples/star-wars/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func main() {
1313
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
14-
query := r.URL.Query()["query"][0]
14+
query := r.URL.Query().Get("query")
1515
result := graphql.Do(graphql.Params{
1616
Schema: testutil.StarWarsSchema,
1717
RequestString: query,

examples/todo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func executeQuery(query string, schema graphql.Schema) *graphql.Result {
207207

208208
func main() {
209209
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
210-
result := executeQuery(r.URL.Query()["query"][0], schema)
210+
result := executeQuery(r.URL.Query().Get("query"), schema)
211211
json.NewEncoder(w).Encode(result)
212212
})
213213
// Serve static files

0 commit comments

Comments
 (0)