gqlparser

package module
v0.0.0-...-9893a3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2018 License: MIT Imports: 4 Imported by: 0

README

gqlparser CircleCI Go Report Card Coverage Status

This repo is still under heavy development. APIs will break, use it at your own peril.

This is a parser for graphql, written to mirror the graphql-js reference implementation as closely as possible.

spec target: 06614fb52871bbaf940f8cac7148db26df00c562 (master 2018-04-29)

This parser aims to replace the one in graph-gophers/internal for use by gqlgen.

Guiding principles:

  • maintainability: It should be easy to stay up to date with the spec
  • well tested: It shouldnt need a graphql server to validate itself. Changes to this repo should be self contained.
  • server agnostic: It should be usable by any of the graphql server implementations, and any graphql client tooling.
  • idiomatic & stable api: It should follow go best practices, especially around forwards compatibility.
  • fast: Where it doesnt impact on the above it should be fast. Avoid unnecessary allocs in hot paths.
  • close to reference: Where it doesnt impact on the above, it should stay close to the graphql/graphql-js reference implementation.

progress

feature readyness
lexer done
query parser done
schema parser done
schema loader done
validator doing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name  string
	Value Value
}

type BlockValue

type BlockValue string

type BooleanValue

type BooleanValue bool

type Definition

type Definition struct {
	Kind        DefinitionKind
	Description string
	Name        string
	Directives  []Directive
	Interfaces  []NamedType           // object and input object
	Fields      []FieldDefinition     // object and input object
	Types       []NamedType           // union
	Values      []EnumValueDefinition // enum
}

Definition is the core type definition object, it includes all of the definable types but does *not* cover schema or directives.

@vektah: Javascript implementation has different types for all of these, but they are more similar than different and don't define any behaviour. I think this style of "some hot" struct works better, at least for go.

Type extensions are also represented by this same struct.

func (*Definition) Field

func (d *Definition) Field(name string) *FieldDefinition

func (*Definition) IsAbstractType

func (d *Definition) IsAbstractType() bool

type DefinitionKind

type DefinitionKind string
const (
	Scalar      DefinitionKind = "SCALAR"
	Object      DefinitionKind = "OBJECT"
	Interface   DefinitionKind = "INTERFACE"
	Union       DefinitionKind = "UNION"
	Enum        DefinitionKind = "ENUM"
	InputObject DefinitionKind = "INPUT_OBJECT"
)

type Directive

type Directive struct {
	Name      string
	Arguments []Argument
}

type DirectiveDefinition

type DirectiveDefinition struct {
	Description string
	Name        string
	Arguments   []FieldDefinition
	Locations   []DirectiveLocation
}

type DirectiveLocation

type DirectiveLocation string
const (
	// Executable
	LocationQuery              DirectiveLocation = `QUERY`
	LocationMutation           DirectiveLocation = `MUTATION`
	LocationSubscription       DirectiveLocation = `SUBSCRIPTION`
	LocationField              DirectiveLocation = `FIELD`
	LocationFragmentDefinition DirectiveLocation = `FRAGMENT_DEFINITION`
	LocationFragmentSpread     DirectiveLocation = `FRAGMENT_SPREAD`
	LocationInlineFragment     DirectiveLocation = `INLINE_FRAGMENT`

	// Type System
	LocationSchema               DirectiveLocation = `SCHEMA`
	LocationScalar               DirectiveLocation = `SCALAR`
	LocationObject               DirectiveLocation = `OBJECT`
	LocationFieldDefinition      DirectiveLocation = `FIELD_DEFINITION`
	LocationArgumentDefinition   DirectiveLocation = `ARGUMENT_DEFINITION`
	LocationIinterface           DirectiveLocation = `INTERFACE`
	LocationUnion                DirectiveLocation = `UNION`
	LocationEnum                 DirectiveLocation = `ENUM`
	LocationEnumValue            DirectiveLocation = `ENUM_VALUE`
	LocationInputObject          DirectiveLocation = `INPUT_OBJECT`
	LocationInputFieldDefinition DirectiveLocation = `INPUT_FIELD_DEFINITION`
)

type EnumValue

type EnumValue string

type EnumValueDefinition

type EnumValueDefinition struct {
	Description string
	Name        string
	Directives  []Directive
}

type Field

type Field struct {
	Alias        string
	Name         string
	Arguments    []Argument
	Directives   []Directive
	SelectionSet SelectionSet
}

type FieldDefinition

type FieldDefinition struct {
	Description  string
	Name         string
	Arguments    []FieldDefinition // only for objects
	DefaultValue Value             // only for input objects
	Type         Type
	Directives   []Directive
}

type FloatValue

type FloatValue string

type FragmentDefinition

type FragmentDefinition struct {
	Name string
	// Note: fragment variable definitions are experimental and may be changed
	// or removed in the future.
	VariableDefinition []VariableDefinition
	TypeCondition      NamedType
	Directives         []Directive
	SelectionSet       SelectionSet
}

type FragmentSpread

type FragmentSpread struct {
	Name       string
	Directives []Directive
}

type InlineFragment

type InlineFragment struct {
	TypeCondition NamedType
	Directives    []Directive
	SelectionSet  SelectionSet
}

type IntValue

type IntValue string

type ListType

type ListType struct {
	Type Type
}

type ListValue

type ListValue []Value

type NamedType

type NamedType string

func (NamedType) Name

func (n NamedType) Name() string

type NonNullType

type NonNullType struct {
	Type Type
}

type NullValue

type NullValue struct{}

type ObjectField

type ObjectField struct {
	Name  string
	Value Value
}

type ObjectValue

type ObjectValue []ObjectField

type Operation

type Operation string
const (
	Query        Operation = "query"
	Mutation     Operation = "mutation"
	Subscription Operation = "subscription"
)

type OperationDefinition

type OperationDefinition struct {
	Operation           Operation
	Name                string
	VariableDefinitions []VariableDefinition
	Directives          []Directive
	SelectionSet        SelectionSet
}

type OperationTypeDefinition

type OperationTypeDefinition struct {
	Operation Operation
	Type      NamedType
}

type QueryDocument

type QueryDocument struct {
	Operations []OperationDefinition
	Fragments  []FragmentDefinition
}

func ParseQuery

func ParseQuery(source string) (QueryDocument, *errors.Syntax)

func (QueryDocument) GetFragment

func (d QueryDocument) GetFragment(name string) *FragmentDefinition

func (QueryDocument) GetOperation

func (d QueryDocument) GetOperation(name string) *OperationDefinition

type Schema

type Schema struct {
	Query        *Definition
	Mutation     *Definition
	Subscription *Definition

	Types      map[string]*Definition
	Directives map[string]*DirectiveDefinition
	// contains filtered or unexported fields
}

func LoadSchema

func LoadSchema(input string) (*Schema, error)

func (*Schema) GetPossibleTypes

func (s *Schema) GetPossibleTypes(def *Definition) []*Definition

GetPossibleTypes will enumerate all the definitions for a given interface or union

type SchemaDefinition

type SchemaDefinition struct {
	Description    string
	Directives     []Directive
	OperationTypes []OperationTypeDefinition
}

type SchemaDocument

type SchemaDocument struct {
	Schema          []SchemaDefinition
	SchemaExtension []SchemaDefinition
	Directives      []DirectiveDefinition
	Definitions     []Definition
	Extensions      []Definition
}

func ParseSchema

func ParseSchema(source string) (SchemaDocument, *errors.Syntax)

type Selection

type Selection interface {
	// contains filtered or unexported methods
}

type SelectionSet

type SelectionSet []Selection

type StringValue

type StringValue string

type Type

type Type interface {
	// contains filtered or unexported methods
}

type Value

type Value interface {
	// contains filtered or unexported methods
}

type Variable

type Variable string

type VariableDefinition

type VariableDefinition struct {
	Variable     Variable
	Type         Type
	DefaultValue Value
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL