Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Latest commit

History

1,079 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

graphql Go packageGo Reference

An implementation of GraphQL in Go. Follows the official reference implementation graphql-js.

Supports: queries, mutations & subscriptions.

Documentation

godoc: https://pkg.go.dev/github.com/tailor-inc/graphql

Getting Started

To install the library, run:

go get github.com/tailor-inc/graphql

The following is a simple example which defines a schema with a single hello string-type field and a Resolve method which returns the string world. A GraphQL query is performed against this schema with the resulting output printed in JSON format.

package main
import (
"encoding/json""fmt""log""github.com/tailor-inc/graphql"
)
funcmain() {
// Schemafields:= 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)
iferr!=nil {
log.Fatalf("failed to create new schema, error: %v", err)
}
// Queryquery:=` { hello }	`params:= graphql.Params{Schema: schema, RequestString: query}
r:=graphql.Do(params)
iflen(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

NameAuthorDescription
graphql-go-handlerHafiz IsmailMiddleware to handle GraphQL queries through HTTP requests.
graphql-relay-goHafiz IsmailLib to construct a graphql-go server supporting react-relay.
golang-relay-starter-kitHafiz IsmailBarebones starting point for a Relay application with Golang GraphQL server.
dataloaderNick RandallDataLoader implementation in Go.

Blog Posts

About

An old snapshot of the repository. Will be archived and deleted

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages