Score
0
Watch 10 Star 32 Fork 8

gqlengine / GQLEngineGoApache-2.0

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
高性能、功能完备的GraphQL Go语言版本服务端框架 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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

Comments ( 3 )

Sign in for post a comment

Go
1
https://gitee.com/gqlengine/gqlengine.git
git@gitee.com:gqlengine/gqlengine.git
gqlengine
gqlengine
GQLEngine
master

Help Search