An implementation of GraphQL for Go / Golang
Go
Latest commit 22050ee Dec 10, 2016 @chris-ramon chris-ramon committed on GitHub Merge pull request #176 from graphql-go/gofmt-s
gofmt -s
Permalink
Failed to load latest commit information.
examples Fix further `go lint ./...` warnings Apr 17, 2016
gqlerrors Fixes tests that was broken with enhancements made to the `lexer` wit… Jun 12, 2016
language gofmt -s Dec 10, 2016
testutil Improve lexer performance by using a byte array as source Jun 12, 2016
.gitignore initial commit Jul 11, 2015
.travis.yml Add 1.7 and tip to build matrix for Go Nov 13, 2016
CONTRIBUTING.md Update CONTRIBUTING.md Oct 29, 2015
LICENSE add initial README and LICENSE Aug 15, 2015
README.md README: add Documentation section Sep 28, 2016
abstract_test.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
definition.go Fix ObjectConfig duplicate json tag. Nov 13, 2016
definition_test.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
directives.go [RFC] Directives in schema language May 30, 2016
directives_test.go Tests for `NewDirectives()` for better coverage May 31, 2016
enum_type_test.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
executor.go executor: add graphql tag Nov 30, 2016
executor_resolve_test.go Add tests for default resolve function. May 31, 2016
executor_schema_test.go Revert int64 changes to int (to match graphql-js) Dec 2, 2015
executor_test.go executor: add graphql tag Nov 30, 2016
graphql.go Improve lexer performance by using a byte array as source Jun 12, 2016
graphql_test.go correct misspellings, gofmt May 13, 2016
introspection.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
introspection_test.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
kitchen-sink.graphql first pass at tests for subscriptions Mar 11, 2016
lists_test.go Merge branch 'cleaning' of https://github.com/kmulvey/graphql into so… May 31, 2016
located.go Ported changes for `gqlerrors` Mar 7, 2016
mutations_test.go correct misspellings, gofmt May 13, 2016
nonnull_test.go correct misspellings, gofmt May 13, 2016
rules.go gofmt -s Dec 10, 2016
rules_arguments_of_correct_type_test.go Fix the error message for unknown field Apr 5, 2016
rules_default_values_of_correct_type_test.go Make input objects and lists return better errors Apr 4, 2016
rules_fields_on_correct_type_test.go [validator] Add suggested types to incorrect field message Apr 11, 2016
rules_fragments_on_composite_types_test.go Fix validators to be aware of type-condition-less inline frags Apr 11, 2016
rules_known_argument_names_test.go Minor `gofmt` Nov 18, 2015
rules_known_directives_rule_test.go [RFC] Proposed change to directive location introspection May 30, 2016
rules_known_fragment_names_test.go GravatarCommit: 3f1f9f5759704ca9ed153c98558236a66af75153 [3f1f9f5] Mar 8, 2016
rules_known_type_names_test.go Fix false-positive validation error for unknown type Apr 11, 2016
rules_lone_anonymous_operation_rule_test.go first pass at tests for subscriptions Mar 11, 2016
rules_no_fragment_cycles_test.go [Validation] perf improvements for fragment cycle detection Apr 11, 2016
rules_no_undefined_variables_test.go [Validation] Parallelize validation rules. Mar 10, 2016
rules_no_unused_fragments_test.go Added missing rule tests Nov 18, 2015
rules_no_unused_variables_test.go Improve validation error for unused variable Apr 12, 2016
rules_overlapping_fields_can_be_merged_test.go RFC: Return type overlap validation May 31, 2016
rules_possible_fragment_spreads_test.go Added missing rule tests Nov 18, 2015
rules_provided_non_null_arguments_test.go Added missing rule tests Nov 18, 2015
rules_scalar_leafs_test.go Added missing rule tests Nov 18, 2015
rules_unique_argument_names_test.go Fix test for unique arg names Apr 12, 2016
rules_unique_fragment_names_test.go Minor `gofmt` Nov 18, 2015
rules_unique_input_field_names_test.go Commit: Mar 8, 2016
rules_unique_operation_names_test.go first pass at tests for subscriptions Mar 11, 2016
rules_unique_variable_names_test.go Validate: Unique variable names Apr 6, 2016
rules_variables_are_input_types_test.go Moved tests in `rules` folder out to root Nov 18, 2015
rules_variables_in_allowed_position_test.go Fix typo in unit test, closes #269 Apr 12, 2016
scalars.go Updated `graphql.Float` coercion May 31, 2016
scalars_serialization_test.go Updated `graphql.Float` coercion May 31, 2016
schema-kitchen-sink.graphql [RFC] Add Schema Definition to IDL. May 30, 2016
schema.go Add GraphQLSchema types field May 31, 2016
type_comparators_test.go Add tests for type comparators May 31, 2016
type_info.go [RFC] Add Schema Definition to IDL. May 30, 2016
types.go Updated import paths to `github.com/graphql-go/graphql` Nov 5, 2015
union_interface_test.go [RFC] Add explicit context arg to graphql execution May 31, 2016
validation_test.go [RFC] Add explicit context arg to graphql execution May 31, 2016
validator.go gofmt -s Dec 10, 2016
validator_test.go Improve lexer performance by using a byte array as source Jun 12, 2016
values.go Fix `golint` warnings Apr 15, 2016
variables_test.go gofmt -s Dec 10, 2016

README.md

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/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.

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 is currently several versions behind graphql-js, however future efforts will be guided directly by the latest formal GraphQL specification (currently: October 2015).

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 (see: PR-#21)
    • React/Relay
  • Alpha Release (v0.1)