Skip to content
An implementation of GraphQL for Go / Golang
Go
Branch: master
Clone or download
chris-ramon Merge pull request #523 from asaf/dateTimeUnserializationTimeInstanceFix
Support unserialization of time.Time instance
Latest commit 2e2b648 Nov 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Use Go Modules. Dec 2, 2018
benchutil simplify assignments with <op>= syntax Jul 31, 2018
examples Update CRUD example Sep 21, 2019
gqlerrors consolidates original error to allow custom format error Dec 9, 2018
language language/lexer: code clean-up Mar 10, 2019
testutil consolidates original error to allow custom format error Dec 9, 2018
.gitignore Added method to add runtime types to existing schema. Apr 2, 2017
CONTRIBUTING.md Fix Gitter badge in CONTRIBUTING.md. Oct 16, 2018
LICENSE add initial README and LICENSE Aug 15, 2015
README.md coveralls: update badge Jul 19, 2018
abstract_test.go consolidates original error to allow custom format error Dec 9, 2018
definition.go Ensure that introspection types don't race during initialization. (#469) Apr 3, 2019
definition_test.go Adds an AddFieldConfig method to InputObjects Jun 11, 2018
directives.go optimize: simple code style Mar 24, 2018
directives_test.go consolidates original error to allow custom format error Dec 9, 2018
enum_type_test.go Added test for Enum nil pointer handling Jul 27, 2018
executor.go Fix data race in Execute (#459) Apr 2, 2019
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 Merge branch 'master' into issue-439 Mar 9, 2019
extensions.go Fix data race in Execute (#459) Apr 2, 2019
extensions_test.go Fix unreachable code issue Mar 12, 2019
go.mod Use Go Modules. Dec 2, 2018
graphql.go Update extensions with panic catching and context propagation Mar 7, 2019
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 Fix Playground marking fields as @deprecated when they're not Nov 2, 2019
introspection_test.go Fix Playground marking fields as @deprecated when they're not Nov 2, 2019
kitchen-sink.graphql first pass at tests for subscriptions Mar 11, 2016
lists_test.go consolidates original error to allow custom format error Dec 9, 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 consolidates original error to allow custom format error Dec 9, 2018
quoted_or_list_internal_test.go Unit test quotedOrList (suggestion quoting utility) Mar 15, 2017
race_test.go Ensure that introspection types don't race during initialization. (#469) Apr 3, 2019
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 Support unserialization of time.Time instance Oct 28, 2019
scalars_parse_test.go fix DateTime literal parsing Nov 16, 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 Add extensions to schema Feb 21, 2019
suggested_list_internal_test.go Include possible field, argument, type names when validation fails (#355 Mar 15, 2017
type_comparators_internal_test.go Rename `type_comparator` test to mark as internal test. Mar 15, 2017
type_info.go replace fallthrough statements with case clause lists Sep 11, 2018
types.go Fix data race in Execute (#459) Apr 2, 2019
union_interface_test.go Handle list of nil Aug 1, 2018
util.go replace fallthrough statements with case clause lists Sep 11, 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 consolidates original error to allow custom format error Dec 9, 2018
values.go Handle list of nil Aug 1, 2018
values_test.go treat arrays as iterable May 25, 2018
variables_test.go consolidates original error to allow custom format error Dec 9, 2018

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

You can’t perform that action at this time.