- starwars: https://github.com/gqlengine/starwars
- chatbox: https://github.com/gqlengine/chatbox
Get the module:
go get -u github.com/gqlengine/gqlengine
main.go
package main
import (
"net/http"
"github.com/gqlengine/gqlengine"
)
func main() {
engine := gqlengine.NewEngine(gqlengine.Options{
Tracing: true, // enable tracing extensions
})
// register your queries, mutations and subscriptions
engine.NewQuery(mySimpleQuery)
// do NOT forget init the engine
if err := engine.Init(); err != nil {
panic(err)
}
// serve for HTTP
http.HandleFunc("/api/graphql", engine.ServeHTTP)
if err := http.ListenAndServe(":8000", nil); err != nil {
panic(err)
}
}
api.go
package main
type MyInfo struct {
gqlengine.IsGraphQLObject `gqlDesc:"my info"`
SaySomething string
}
func mySimpleQuery() error {
panic("not implemented")
}
use playground
go get -u github.com/gqlengine/playground
update the code
...
import (
"github.com/gorilla/mux"
"github.com/gqlengine/playground"
)
...
func main() {
... // init your gql engine
playground.SetEndpoints("/api/graphql", "/api/graphql/subscriptions")
// recommends to use 'gorilla/mux' to serve the playground web assets
r := mux.NewRouter()
r.HandleFunc("/api/graphql", engine.ServeHTTP)
r.HandleFunc("/api/graphql/subscriptions", engine.ServeWebsocket)
r.PathPrefix("/api/graphql/playground").
Handler(http.StripPrefix("/api/graphql/playground",
http.FileServer(playground.WebBundle)))
println("open playground http://localhost:9996/api/graphql/playground/")
if err := http.ListenAndServe(":9996", r); err != nil {
panic(err)
}
}
open browser, you can get the playground all in box
- Basic features
- Object type reflection
- Interface pre-register
- Union pre-register
- Enum reflection
- Scalar reflection
- Input reflection
- Arguments reflection
- Subscription (Integerates Websocket)
- Multipart Upload (Upload images/files in graphql query)
- Custom ID
- Tracing extensions
- document tags
- operation hijacking