Skip to content

An implementation of GraphQL for Go / Golang

License

Notifications You must be signed in to change notification settings

globocom/graphql

This branch is 4 commits ahead of, 438 commits behind graphql-go/graphql:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Michel Aquino
May 5, 2017
a1c763d · May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
Jul 11, 2015
Feb 20, 2017
Oct 29, 2015
Aug 15, 2015
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
Mar 15, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
Mar 11, 2016
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
Mar 15, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
Mar 15, 2017
Mar 15, 2017
Mar 15, 2017
Mar 15, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017
May 5, 2017

Repository files navigation

graphql Build Status GoDoc Coverage Status Join the chat at https://gitter.im/chris-ramon/graphql

A work-in-progress implementation of GraphQL for Go.

Documentation

godoc: https://godoc.org/github.com/globocom/graphql

Getting Started

To install the library, run:

go get github.com/globocom/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/globocom/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.

Origin and Current Direction

This project was originally a port of v0.4.3 of graphql-js (excluding the Validator), which was based on the July 2015 GraphQL specification. graphql-go is currently on v0.6.0 of graphql-js which is based on the April 2016 GraphQL specification. However future efforts will be guided directly by the latest formal GraphQL specification (currently: October 2016).

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.

Blog Posts

Roadmap

  • Lexer
  • Parser
  • Schema Parser
  • Printer
  • Schema Printer
  • Visitor
  • Executor
  • Validator
  • Examples
    • Basic Usage
    • React/Relay
  • Alpha Release (v0.1)

About

An implementation of GraphQL for Go / Golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%