Skip to content

graphql-go/graphql

Folders and files

NameName
Last commit message
Last commit date
Dec 2, 2018
Jul 31, 2018
Jul 20, 2023
Dec 9, 2018
Oct 25, 2023
May 19, 2020
Apr 2, 2017
Oct 16, 2018
Aug 15, 2015
Jan 30, 2021
Dec 9, 2018
Feb 25, 2023
Jun 12, 2022
Mar 24, 2018
Dec 9, 2018
Jul 27, 2018
Dec 22, 2020
Aug 5, 2017
Nov 25, 2015
Mar 9, 2019
Apr 2, 2019
Jan 29, 2020
May 17, 2020
Jun 25, 2020
Jan 6, 2018
Jun 20, 2019
Nov 2, 2019
Nov 2, 2019
Mar 11, 2016
Dec 9, 2018
Jul 19, 2018
May 13, 2016
Dec 9, 2018
Mar 15, 2017
Apr 3, 2019
Jul 31, 2018
Apr 5, 2016
Aug 5, 2017
Aug 5, 2017
Apr 11, 2016
Oct 22, 2019
Mar 15, 2017
Mar 8, 2016
Mar 15, 2017
Mar 11, 2016
Apr 11, 2016
Mar 10, 2016
Nov 18, 2015
Apr 12, 2016
Oct 22, 2019
Oct 22, 2019
Nov 18, 2015
Nov 18, 2015
Nov 18, 2015
Apr 12, 2016
Nov 18, 2015
Mar 8, 2016
Aug 5, 2017
Apr 6, 2016
Nov 18, 2015
Apr 12, 2016
Oct 28, 2019
Nov 16, 2018
Jul 23, 2017
Jul 26, 2018
Jun 4, 2019
May 16, 2018
Nov 27, 2023
May 19, 2020
May 19, 2020
Mar 15, 2017
Mar 15, 2017
Sep 11, 2018
Apr 2, 2019
Aug 1, 2018
Aug 21, 2019
Aug 21, 2019
May 31, 2016
Apr 13, 2018
Dec 9, 2018
Aug 1, 2018
May 25, 2018
Dec 9, 2018

Repository files navigation

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

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