Skip to content

Commit

Permalink
star wars example: pass operation name and variables (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Nov 6, 2016
1 parent 3b7efd5 commit 0dd3874
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions example/starwars/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ func main() {

http.HandleFunc("/query", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var params struct {
Query string `json:"query"`
Query string `json:"query"`
OperationName string `json:"operationName"`
Variables map[string]interface{} `json:"variables"`
}
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

response := schema.Exec(r.Context(), params.Query, "", nil)
response := schema.Exec(r.Context(), params.Query, params.OperationName, params.Variables)
responseJSON, err := json.Marshal(response)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -60,6 +62,7 @@ var page = []byte(`
<div id="graphiql" style="height: 100vh;">Loading...</div>
<script>
function graphQLFetcher(graphQLParams) {
graphQLParams.variables = graphQLParams.variables ? JSON.parse(graphQLParams.variables) : null;
return fetch("/query", {
method: "post",
body: JSON.stringify(graphQLParams),
Expand Down

0 comments on commit 0dd3874

Please sign in to comment.