Documentation ¶
Overview ¶
Package gqlscan provides functions for fast and allocation-free lexical scanning and validation of GraphQL queries according to the GraphQL specification of October 2021 (https://spec.graphql.org/October2021/).
The provided functions don't perform semantic analysis such as making sure that declared variables are used or that values match their declared types, etc. as this is outside the scope of lexical analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
Error is a GraphQL lexical scan error.
func Scan ¶
Scan calls fn for every token it scans in str. If fn returns true then an error with code ErrCallbackFn is returned. If the returned error code == 0 then there was no error during the scan, this can also be checked using err.IsErr().
WARNING: *Iterator passed to fn should never be aliased and used after Scan returns because it's returned to the pool and may be acquired by another call to Scan!
func ScanAll ¶
ScanAll calls fn for every token it scans in str. If the returned error code == 0 then there was no error during the scan, this can also be checked using err.IsErr().
WARNING: *Iterator passed to fn should never be aliased and used after ScanAll returns because it's returned to the pool and may be acquired by another call to ScanAll!
type ErrorCode ¶
type ErrorCode int
ErrorCode defines the type of an error.
const ( ErrCallbackFn ErrorCode ErrUnexpToken ErrUnexpEOF ErrIllegalFragName ErrInvalNum ErrInvalType )
type Expect ¶
type Expect int
Expect defines an expectation
const ( ExpectVal Expect ExpectValEnum ExpectDefaultVarVal ExpectDef ExpectOprName ExpectSelSet ExpectArgName ExpectEscapedSequence ExpectEscapedUnicodeSequence ExpectEndOfString ExpectEndOfBlockString ExpectColumnAfterArg ExpectFieldNameOrAlias ExpectFieldName ExpectSel ExpectDir ExpectDirName ExpectVar ExpectVarName ExpectVarRefName ExpectVarType ExpectColumnAfterVar ExpectObjFieldName ExpectColObjFieldName ExpectFragTypeCond ExpectFragKeywordOn ExpectFragName ExpectFrag ExpectSpreadName ExpectFragInlined ExpectAfterFieldName ExpectAfterSelection ExpectAfterValueInner ExpectAfterValueOuter ExpectAfterArgList ExpectAfterDefKeyword ExpectAfterVarType ExpectAfterVarTypeName )
Expectations
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is a GraphQL iterator for lexical analysis.
WARNING: An iterator instance shall never be aliased and/or used after Scan or ScanAll returns because it's returned to a global pool!
func (*Iterator) IndexTail ¶
IndexTail returns the current tail index. Returns -1 if the current token doesn't reflect a dynamic value.
func (*Iterator) LevelSelect ¶
LevelSelect returns the current selector level.
func (*Iterator) ScanInterpreted ¶
ScanInterpreted calls fn writing the interpreted part of the value to buffer as long as fn doesn't return true and the scan didn't reach the end of the interpreted value.
func (*Iterator) Value ¶
Value returns the raw value of the current token. For TokenStrBlock it's the raw uninterpreted body of the string, use ScanInterpreted for the interpreted value of the block string.
WARNING: The returned byte slice refers to the same underlying memory as the byte slice passed to Scan and ScanAll as str parameter, copy it or use with caution!
type Token ¶
type Token int
Token defines the type of a token.
const ( TokenDefQry Token TokenDefMut TokenDefSub TokenDefFrag TokenOprName TokenDirName TokenVarList TokenVarListEnd TokenArgList TokenArgListEnd TokenSet TokenSetEnd TokenFragTypeCond TokenFragName TokenFragInline TokenNamedSpread TokenFieldAlias TokenField TokenArgName TokenEnumVal TokenArr TokenArrEnd TokenStr TokenStrBlock TokenInt TokenFloat TokenTrue TokenFalse TokenNull TokenVarName TokenVarTypeName TokenVarTypeArr TokenVarTypeArrEnd TokenVarTypeNotNull TokenVarRef TokenObj TokenObjEnd TokenObjField )
Token types