by graphql-go

graphql-go /graphql

An implementation of GraphQL for Go / Golang

6.8K Stars 589 Forks Last release: 8 months ago (v0.7.9) MIT License 929 Commits 13 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

graphql CircleCI GoDoc Coverage Status Join the chat at

An implementation of GraphQL in Go. Follows the official reference implementation


Supports: queries, mutations & subscriptions.



Getting Started

To install the library, run:

go get

The following is a simple example which defines a schema with a single

string-type field and a
method which returns the string
. A GraphQL query is performed against this schema with the resulting output printed in JSON format.
package main

import ( "encoding/json" "fmt" "log"



func main() { // Schema fields := graphql.Fields{ "hello": &graphql.Field{ Type: graphql.String, Resolve: func(p graphql.ResolveParams) (interface{}, error) { return "world", nil }, }, } rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} schema, err := graphql.NewSchema(schemaConfig) if err != nil { log.Fatalf("failed to create new schema, error: %v", err) }

// Query
query := `
params := graphql.Params{Schema: schema, RequestString: query}
r := graphql.Do(params)
if len(r.Errors) > 0 {
    log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
rJSON, _ := json.Marshal(r)
fmt.Printf("%s \n", rJSON) // {"data":{"hello":"world"}}


For more complex examples, refer to the examples/ directory and graphql_test.go.

Third Party Libraries

| Name | Author | Description | |:-------------:|:-------------:|:------------:| | graphql-go-handler | Hafiz Ismail | Middleware to handle GraphQL queries through HTTP requests. | | graphql-relay-go | Hafiz Ismail | Lib to construct a graphql-go server supporting react-relay. | | golang-relay-starter-kit | Hafiz Ismail | Barebones starting point for a Relay application with Golang GraphQL server. | | dataloader | Nick Randall | DataLoader implementation in Go. |

Blog Posts

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.