Skip to content

GQLEngine is the best productive solution for implementing a GraphQL server 🚀

Notifications You must be signed in to change notification settings

gqlengine/gqlengine

Repository files navigation

GQLEngine is the best productive solution for implementing a graphql server for highest formance

examples

Getting started

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:https://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

Features

  • 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

About

GQLEngine is the best productive solution for implementing a GraphQL server 🚀

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages