graphql README

The project's README from github.com/graphql-go/graphql. As one markdown file: README.md.

graphql CircleCI Go Reference Coverage Status Join the chat at https://gitter.im/graphql-go/graphql

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/graphql-go/graphql

Contribute Back

Friendly reminder links are available in case you would like to contribute back into our commitment with Go and open-source.

Author PayPal Link
Hafiz Ismail Not available yet.
Chris Ramón https://www.paypal.com/donate/?hosted_button_id=WHUQQYEMTRQBJ

Getting Started

To install the library, run:

go get github.com/graphql-go/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/graphql-go/graphql"
)

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 := `
		{
			hello
		}
	`
	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

graphql (graphql-go/graphql)

Searching Database…

10.1K ·GitHub
What is this?An implementation of GraphQL in Go, following the official graphql-js reference implementation, with support for queries, mutations, and subscriptions.
Is this a library I import into my own server, or a standalone GraphQL server?It's a Go library you import into your own application to build and execute GraphQL schemas and resolvers; serving it over HTTP is handled by a separate companion package like graphql-go-handler.
How do I get it running?Install the package, define a schema with fields and a Resolve method, then execute a GraphQL query against that schema and print the JSON result; the examples/ directory and graphqltest.go show fuller examples.
Do I need anything besides the Go toolchain to use it?No, the core library only needs Go itself; if you want HTTP handling, Relay compatibility, or batching you add separate packages like graphql-go-handler, graphql-relay-go, or dataloader.
Does the core package include an HTTP server out of the box?No, graphql-go only builds and executes schemas in memory; exposing it over HTTP, Relay support, and dataloading are left to separate third-party libraries.
Does it support Relay-style pagination out of the box?Not directly in the core package, but the companion graphql-relay-go library helps you construct a graphql-go server that's compatible with react-relay.
What does the dataloader package add to this?It's a separate Go implementation of Facebook's DataLoader pattern, used to batch and cache resolver calls when paired with graphql-go.
Where can I see more complete usage examples?Beyond the basic hello-world snippet in the README, the examples/ directory and graphqltest.go in the repo contain more complex schema and resolver examples.
What are similar projects?echo, gqlgen, chi, node-restify, guzzle, mux, martini, fiber
Creator
graphql-go
Size
3.6 MB
Stars
10.1K
Age
11y
Commits · 90 Days