Created
August 11, 2019 17:44
-
-
Save gufranmirza/3dc203e4488952007775081f57de34f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"net/http" | |
"github.com/graphql-go/graphql" | |
) | |
type Album struct { | |
ID string `json:"id,omitempty"` | |
Artist string `json:"artist"` | |
Title string `json:"title"` | |
Year string `json:"year"` | |
Genre string `json:"genre"` | |
Type string `json:"type"` | |
} | |
type Artist struct { | |
ID string `json:"id,omitempty"` | |
Name string `json:"name"` | |
Type string `json:"type"` | |
} | |
type Song struct { | |
ID string `json:"id,omitempty"` | |
Album string `json:"album"` | |
Title string `json:"title"` | |
Duration string `json:"duration"` | |
Type string `json:"type"` | |
} | |
func main() { | |
schema, _ := graphql.NewSchema(graphql.SchemaConfig{}) | |
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) { | |
result := graphql.Do(graphql.Params{ | |
Schema: schema, | |
RequestString: r.URL.Query().Get("query"), | |
}) | |
json.NewEncoder(w).Encode(result) | |
}) | |
http.ListenAndServe(":12345", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment