An implementation of GraphQL for Go / Golang
Go
Clone or download
chris-ramon Merge pull request #376 from Quasilyte/quasilyte/assignOp
simplify assignments with <op>= syntax
Latest commit 5c1be08 Jul 31, 2018
Permalink
Failed to load latest commit information.
.circleci circleci: adds config Jul 19, 2018
benchutil simplify assignments with <op>= syntax Jul 31, 2018
examples examples: adds crud example Jul 24, 2018
gqlerrors removes extra error suffix Jul 20, 2018
language simplify assignments with <op>= syntax Jul 31, 2018
testutil simplify assignments with <op>= syntax Jul 31, 2018
.gitignore Added method to add runtime types to existing schema. Apr 2, 2017
CONTRIBUTING.md Update CONTRIBUTING.md Sep 28, 2017
LICENSE add initial README and LICENSE Aug 15, 2015
README.md coveralls: update badge Jul 19, 2018
abstract_test.go catch up to june 2018 error spec Jul 19, 2018
definition.go Merge branch 'master' into regexpMust Jul 28, 2018
definition_test.go Adds an AddFieldConfig method to InputObjects Jun 11, 2018
directives.go optimize: simple code style Mar 24, 2018
directives_test.go Remove unused fragment in queries in unit tests Mar 15, 2017
enum_type_test.go Added test for Enum nil pointer handling Jul 27, 2018
executor.go catch up to june 2018 error spec Jul 19, 2018
executor_resolve_test.go empty string fixes Aug 5, 2017
executor_schema_test.go Revert int64 changes to int (to match graphql-js) Dec 2, 2015
executor_test.go removes extra error suffix Jul 20, 2018
graphql.go replace golang.org/x/net/context with stdlib context Jul 16, 2017
graphql_bench_test.go Add benchmarks Jan 6, 2018
graphql_test.go Fix isNullish to not consider an empty string as Null. Aug 5, 2017
introspection.go simplify single case type switches Jul 28, 2018
introspection_test.go empty string fixes Aug 5, 2017
kitchen-sink.graphql first pass at tests for subscriptions Mar 11, 2016
lists_test.go Added tests for nil pointer handling of Union, Interface and List Jul 27, 2018
located.go catch up to june 2018 error spec Jul 19, 2018
mutations_test.go correct misspellings, gofmt May 13, 2016
nonnull_test.go catch up to june 2018 error spec Jul 19, 2018
quoted_or_list_internal_test.go Unit test quotedOrList (suggestion quoting utility) Mar 15, 2017
rules.go simplify assignments with <op>= syntax Jul 31, 2018
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 Check for invalid NonNull in isValidLiteralValue Aug 5, 2017
rules_fields_on_correct_type_test.go Check for typed nils in FieldsOnCorrectTypeRule Aug 5, 2017
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 Improved `KnownArgumentNames` tests for coverage Mar 15, 2017
rules_known_directives_rule_test.go RFC: Directive location: schema definition (#382) Mar 15, 2017
rules_known_fragment_names_test.go GravatarCommit: 3f1f9f5759704ca9ed153c98558236a66af75153 [3f1f9f5] Mar 8, 2016
rules_known_type_names_test.go Unit test quotedOrList (suggestion quoting utility) Mar 15, 2017
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.go rules: adds missing nil checking Aug 5, 2017
rules_overlapping_fields_can_be_merged_test.go Add nil check to parentType in collectFieldASTsAndDefs Aug 5, 2017
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 Fix nil panic in UniqueOperationNamesRule with two anonymous operations Aug 5, 2017
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 Added handling for nil pointers to scalar coercion Jul 26, 2018
scalars_parsevalue_test.go Added handling for nil pointers to scalar coercion Jul 26, 2018
scalars_serialization_test.go scalars: Add Datetime Jul 23, 2017
scalars_test.go Added handling for nil pointers to scalar coercion Jul 26, 2018
schema-kitchen-sink.graphql Separate multiple inherited interfaces with `&` May 16, 2018
schema.go optimise code style Apr 13, 2018
suggested_list_internal_test.go Include possible field, argument, type names when validation fails (#… Mar 15, 2017
type_comparators_internal_test.go Rename `type_comparator` test to mark as internal test. Mar 15, 2017
type_info.go Fix nil checks in DefaultTypeInfoFieldDef Aug 5, 2017
types.go Redundant parentheses Sep 12, 2017
union_interface_test.go Added tests for nil pointer handling of Union, Interface and List Jul 27, 2018
util.go Update util.go Apr 16, 2018
util_test.go fix json tag with multiple value (comma separated) Dec 18, 2017
validation_test.go [RFC] Add explicit context arg to graphql execution May 31, 2016
validator.go optimise code style Apr 13, 2018
validator_test.go Minor refactoring of error messages for unknown fields Mar 15, 2017
values.go Merge branch 'master' into master Jul 17, 2018
values_test.go treat arrays as iterable May 25, 2018
variables_test.go gofmt -s Dec 10, 2016

README.md

graphql CircleCI GoDoc 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://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.

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