Skip to content

Commit

Permalink
improved example
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 20, 2016
1 parent 22ce46d commit 0f85412
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions example/starwars/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ import (
"github.com/neelance/graphql-go/example/starwars"
)

var schema *graphql.Schema

func init() {
var err error
schema, err = graphql.ParseSchema(starwars.Schema, &starwars.Resolver{})
if err != nil {
panic(err)
}
}

func main() {
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(page)
}))

http.HandleFunc("/query", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
schema, err := graphql.ParseSchema(starwars.Schema, &starwars.Resolver{})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

var params struct {
Query string `json:"query"`
}
Expand Down

0 comments on commit 0f85412

Please sign in to comment.