Skip to content

Instantly share code, notes, and snippets.

@gufranmirza
Created August 11, 2019 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gufranmirza/3dc203e4488952007775081f57de34f5 to your computer and use it in GitHub Desktop.
Save gufranmirza/3dc203e4488952007775081f57de34f5 to your computer and use it in GitHub Desktop.
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