gqlparse

package
v0.0.0-...-ecc870c Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package gqlparse provides a GraphQL parser that validates queries, ignores irrelevant operations inlines fragments and references variable values.

Index

Constants

View Source
const TokenTypeValIndexOffset = 100

TokenTypeValIndexOffset defines the offset that needs to be subtracted from Token.ID in order to get the index of the value when Token.ID is > 99

Variables

This section is empty.

Functions

func WriteTypeDesignation

func WriteTypeDesignation(w io.Writer, definition []Token)

WriteTypeDesignation stringifies a type designation to w expecting definition to be valid.

func WriteValue

func WriteValue(w io.Writer, definition []Token)

WriteValue stringifies a value to w expecting definition to be valid.

Types

type ErrorFragLimitExceeded

type ErrorFragLimitExceeded struct {
	Limit int
}

func (*ErrorFragLimitExceeded) Error

func (e *ErrorFragLimitExceeded) Error() string

type ErrorFragRecurse

type ErrorFragRecurse struct {
	Path [][]byte
}

func (*ErrorFragRecurse) Error

func (e *ErrorFragRecurse) Error() string

type ErrorFragUndefined

type ErrorFragUndefined struct {
	FragmentName []byte
}

func (*ErrorFragUndefined) Error

func (e *ErrorFragUndefined) Error() string

type ErrorFragUnused

type ErrorFragUnused struct {
	FragmentName []byte
}

func (*ErrorFragUnused) Error

func (e *ErrorFragUnused) Error() string

type ErrorOprAnonNonExcl

type ErrorOprAnonNonExcl struct {
}

func (*ErrorOprAnonNonExcl) Error

func (e *ErrorOprAnonNonExcl) Error() string

type ErrorOprNotFound

type ErrorOprNotFound struct {
	OperationName []byte
}

func (*ErrorOprNotFound) Error

func (e *ErrorOprNotFound) Error() string

type ErrorRedecFrag

type ErrorRedecFrag struct {
	FragmentName []byte
}

func (*ErrorRedecFrag) Error

func (e *ErrorRedecFrag) Error() string

type ErrorRedecOpr

type ErrorRedecOpr struct {
	OperationName []byte
}

func (*ErrorRedecOpr) Error

func (e *ErrorRedecOpr) Error() string

type ErrorRedeclVar

type ErrorRedeclVar struct {
	VariableName []byte
}

func (*ErrorRedeclVar) Error

func (e *ErrorRedeclVar) Error() string

type ErrorSyntax

type ErrorSyntax struct {
	ScanErr gqlscan.Error
}

func (*ErrorSyntax) Error

func (e *ErrorSyntax) Error() string

type ErrorUnexpValType

type ErrorUnexpValType struct {
	Buffer               []Token
	BufferJSON           []byte
	TypeExpected         indexRange
	DefaultValueReceived indexRange
	JSONValueReceived    indexRange
}

func (*ErrorUnexpValType) Error

func (e *ErrorUnexpValType) Error() string

type ErrorVarJSONNotObj

type ErrorVarJSONNotObj struct {
	Received gjson.Result
}

func (*ErrorVarJSONNotObj) Error

func (e *ErrorVarJSONNotObj) Error() string

type ErrorVarJSONSyntax

type ErrorVarJSONSyntax struct{}

func (*ErrorVarJSONSyntax) Error

func (e *ErrorVarJSONSyntax) Error() string

type ErrorVarUndeclared

type ErrorVarUndeclared struct {
	VariableName []byte
}

func (*ErrorVarUndeclared) Error

func (e *ErrorVarUndeclared) Error() string

type ErrorVarUndefined

type ErrorVarUndefined struct {
	VariableName []byte
}

func (*ErrorVarUndefined) Error

func (e *ErrorVarUndefined) Error() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser() *Parser

NewParser creates a new parser instance. It's adviced to create only one parser per goroutine as calling (*Parser).Parse will reset it.

func (*Parser) Parse

func (r *Parser) Parse(
	src, operationName, varsJSON []byte,
	onSuccess func(
		varValues [][]Token,
		operation []Token,
		selectionSet []Token,
	),
	onError func(err error),
)

Parse calls onSuccess in case of success where operation only contains the relevant set of tokens. onError is called in case of an error.

WARNING: Data (including errors) provided to callbacks must not be aliased and used after Parse returns!

type Token

type Token struct {
	// IDs below 100 are reserved gqlscan type identifiers.
	// IDs above 99 are variable value indexes.
	ID    gqlscan.Token
	Value []byte
}

func MakeVariableIndexToken

func MakeVariableIndexToken(index int, name string) Token

MakeVariableIndexToken creates a variable index token.

func (Token) VariableIndex

func (t Token) VariableIndex() (index int)

VariableIndex returns the index of the varible value if its a variable index token, otherwise returns -1.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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