Categorygithub.com/bigdrum/graphql
modulepackage
0.4.18
Repository: https://github.com/bigdrum/graphql.git
Documentation: pkg.go.dev

# README

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.

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

NameAuthorDescription
graphql-go-handlerHafiz IsmailMiddleware to handle GraphQL queries through HTTP requests.
graphql-relay-goHafiz IsmailLib to construct a graphql-go server supporting react-relay.
golang-relay-starter-kitHafiz IsmailBarebones 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)

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

ArgumentsOfCorrectTypeRule Argument values of correct type A GraphQL document is only valid if all field argument literal values are of the type expected by their position.
No description provided by the author
DefaultTypeInfoFieldDef Not exactly the same as the executor's definition of FieldDef, in this statically evaluated environment we do not always have an Object type, and need to handle Interface and Union types.
DefaultValuesOfCorrectTypeRule Variable default values of correct type A GraphQL document is only valid if all variable default values are of the type expected by their definition.
No description provided by the author
No description provided by the author
No description provided by the author
FieldsOnCorrectTypeRule Fields on correct type A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as __typenamme.
FragmentsOnCompositeTypesRule Fragments on composite type Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.
GetNamed returns the Named type of the given GraphQL type.
GetNullable returns the Nullable type of the given GraphQL type.
IsCompositeType determines if given type is a GraphQLComposite type.
IsInputType determines if given type is a GraphQLInputType.
IsLeafType determines if given type is a leaf value.
IsOutputType determines if given type is a GraphQLOutputType.
KnownArgumentNamesRule Known argument names A GraphQL field is only valid if all supplied arguments are defined by that field.
KnownDirectivesRule Known directives A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned.
KnownFragmentNamesRule Known fragment names A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.
KnownTypeNamesRule Known type names A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.
LoneAnonymousOperationRule Lone anonymous operation A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewScalar creates a new GraphQLScalar.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NoFragmentCyclesRule No fragment cycles.
NoUndefinedVariablesRule No undefined variables A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.
NoUnusedFragmentsRule No unused fragments A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.
NoUnusedVariablesRule No unused variables A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.
OverlappingFieldsCanBeMergedRule Overlapping fields can be merged A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.
PossibleFragmentSpreadsRule Possible fragment spread A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.
ProvidedNonNullArgumentsRule Provided required arguments A field or directive is only valid if all required (non-null) field arguments have been provided.
ScalarLeafsRule Scalar leafs A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.
No description provided by the author
No description provided by the author
UniqueArgumentNamesRule Unique argument names A GraphQL field or directive is only valid if all supplied arguments are uniquely named.
UniqueFragmentNamesRule Unique fragment names A GraphQL document is only valid if all defined fragments have unique names.
UniqueInputFieldNamesRule Unique input field names A GraphQL input object value is only valid if all supplied fields are uniquely named.
UniqueOperationNamesRule Unique operation names A GraphQL document is only valid if all defined operations have unique names.
UniqueVariableNamesRule Unique variable names A GraphQL operation is only valid if all its variables are uniquely named.
No description provided by the author
No description provided by the author
VariablesAreInputTypesRule Variables are input types A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).
VariablesInAllowedPositionRule Variables passed to field arguments conform to type.
VisitUsingRules This uses a specialized visitor which runs multiple visitors in parallel, while maintaining the visitor skip and break API.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Boolean is the GraphQL boolean type definition.
Float is the GraphQL float type definition.
ID is the GraphQL id type definition.
IncludeDirective is used to conditionally include fields or fragments.
Int is the GraphQL Integer type definition.
No description provided by the author
No description provided by the author
SkipDirective Used to conditionally skip (exclude) fields or fragments.
SpecifiedRules set includes all validation rules defined by the GraphQL spec.
String is the GraphQL string type definition.
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Directive structs are used by the GraphQL runtime as a way of modifying execution behavior.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
InputObject Type Definition An input object defines a structured collection of fields which may be supplied to a field argument.
No description provided by the author
No description provided by the author
No description provided by the author
Interface Type Definition When a field can return one of a heterogeneous set of types, a Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.
No description provided by the author
List Modifier A list is a kind of type marker, a wrapping type which points to another type.
NonNull Modifier A non-null is a kind of type marker, a wrapping type which points to another type.
Object Type Definition Almost all of the GraphQL types you define will be object Object types have a name, but most importantly describe their fields.
No description provided by the author
No description provided by the author
No description provided by the author
ResolveParams Params for FieldResolveFn() TODO: clean up GQLFRParams fields.
No description provided by the author
Scalar Type Definition The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of functions used to parse input from ast or variables and to ensure validity.
ScalarConfig options for creating a new GraphQLScalar.
Schema DefinitionA Schema is created by supplying the root types of each type of operation,query, mutation (optional) and subscription (optional).
No description provided by the author
No description provided by the author
No description provided by the author
Union Type Definition When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Abstract interface for types that may describe the parent context of a selection set.
Composite interface for types that may describe the parent context of a selection set.
No description provided by the author
Input interface for types that may be used as input types for arguments and directives.
Named interface for types that do not include modifiers like List or NonNull.
Nullable interface for types that can accept null as a value.
Output interface for types that may be used as output types as the result of fields.
Type interface for all of the possible kinds of GraphQL types.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ParseLiteralFn is a function type for parsing the literal value of a GraphQLScalar type.
ParseValueFn is a function type for parsing the value of a GraphQLScalar type.
No description provided by the author
SerializeFn is a function type for serializing a GraphQLScalar type value.
No description provided by the author
No description provided by the author