Documentation
¶
Overview ¶
Package parser provides GraphQL query hashing functions for the latest GraphQL specification: https://spec.graphql.org/October2021/.
Index ¶
- Variables
- func ExpectNoEOF(s []byte) error
- func HasPrefix(s []byte, prefix string) bool
- func IsDigit(b byte) bool
- func IsHexByte(b byte) bool
- func IsIgnorableByte(b byte) bool
- func IsLetter(b byte) bool
- func IsNameStart(b byte) bool
- func IsWhiteSpace(b byte) bool
- func IterateBlockStringLines(s []byte, prefixLen int) iter.Seq[[]byte]
- func ReadArguments(h Hash, s []byte) (arguments, suffix []byte, err error)
- func ReadDefinition(h Hash, s []byte) (suffix []byte, err error)
- func ReadDirectives(h Hash, s []byte) (directives, suffix []byte, err error)
- func ReadDocument(h Hash, s []byte) (err error)
- func ReadFloatAfterInteger(s []byte) (value []byte, suffix []byte, err error)
- func ReadIntValue(s []byte) (value []byte, suffix []byte, err error)
- func ReadName(s []byte) (name, suffix []byte, err error)
- func ReadOperationDefinition(h Hash, s []byte) (suffix []byte, err error)
- func ReadSelectionSet(h Hash, s []byte) (suffix []byte, err error)
- func ReadStringBlockAfterQuotes(s []byte) (value []byte, prefixLen int, suffix []byte, err error)
- func ReadStringLineAfterQuotes(s []byte) (value []byte, suffix []byte, err error)
- func ReadToken(s []byte, token string) (suffix []byte, err error)
- func ReadType(s []byte) (typeDef []byte, nullable, array bool, suffix []byte, err error)
- func ReadVariableDefinitionsAfterParenthesis(h Hash, s []byte) (suffix []byte, err error)
- func SkipIgnorables(s []byte) []byte
- func TrimEmptyLinesSuffix(s []byte) []byte
- type Hash
- type OperationType
- type ValueType
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnexpectedEOF = errors.New("unexpected EOF") ErrUnexpectedToken = errors.New("unexpected token") )
var ( HPrefQuery = []byte{0x1} HPrefMutation = []byte{0x2} HPrefSubscription = []byte{0x3} HPrefFragmentDefinition = []byte{0x4} HPrefVariableDefinition = []byte{0x5} HPrefDirective = []byte{0x6} HPrefField = []byte{0x7} HPrefType = []byte{0x8} HPrefFieldAliasedName = []byte{0xb} // The actual name of the aliased field. HPrefFragmentSpread = []byte{0xc} HPrefInlineFragment = []byte{0xe} HPrefArgument = []byte{0xf} HPrefSelectionSet = []byte{0x11} HPrefSelectionSetEnd = []byte{0x12} HPrefValueInputObject = []byte{0x13} HPrefValueInputObjectField = []byte{0x14} HPrefInputObjectEnd = []byte{0x15} HPrefValueNull = []byte{0x16} HPrefValueTrue = []byte{0x17} HPrefValueFalse = []byte{0x18} HPrefValueInteger = []byte{0x19} HPrefValueFloat = []byte{0x1a} HPrefValueEnum = []byte{0x1b} HPrefValueString = []byte{0x1c} HPrefValueList = []byte{0x1d} HPrefValueListEnd = []byte{0x1e} HPrefValueVariable = []byte{0x1f} )
The hash prefixes are used as magic bytes before writing actual query contents to prevent tokens from collapsing into one if separators aren't written, for example: query fields `{ foo bar }` might collapse into one field `{ foobar }` producing the same hash for those two different queries. 0x9, 0xA and 0xD cannot be used because they're valid bytes within string values (https://spec.graphql.org/June2018/#SourceCharacter).
Functions ¶
func ExpectNoEOF ¶
ExpectNoEOF returns ErrUnexpectedEOF if s is empty, otherwise returns nil.
func HasPrefix ¶
HasPrefix is equivalent to strings.HasPrefix and bytes.HasPrefix except that it works for both string and []byte.
func IsIgnorableByte ¶
IsIgnorableByte returns true if b is ignorable. Reference:
func IsNameStart ¶
IsNameStart returns true if b is NameStart. Reference:
func IsWhiteSpace ¶
IsWhiteSpace returns true if b is a WhiteSpace. Reference:
func IterateBlockStringLines ¶
IterateBlockStringLines iterates over individual lines of a GraphQL block string. Expects s to be the content of the string without the surrounding `"""`.
func ReadArguments ¶
ReadArguments reads Arguments. Reference:
func ReadDefinition ¶
ReadDefinition reads Definition. Reference:
func ReadDirectives ¶
ReadDirectives reads Directives. Reference:
func ReadDocument ¶
ReadDocument reads one or many ExecutableDefinitions
func ReadFloatAfterInteger ¶ added in v1.2.4
ReadFloatAfterInteger reads the part of the FloatValue that comes after the first IntegerPart. Reference:
func ReadIntValue ¶
ReadIntValue reads IntValue. Reference:
func ReadOperationDefinition ¶
ReadOperationDefinition reads OperationDefinition but not the SelectionSet-only version of it. Reference:
func ReadSelectionSet ¶
ReadVariableDefinitions reads VariableDefinitions. Reference:
func ReadStringBlockAfterQuotes ¶
func ReadStringBlockAfterQuotes(s []byte) ( value []byte, prefixLen int, suffix []byte, err error, )
ReadStringBlockAfterQuotes reads a block string StringValue contents after '"""'. Tip: Use ReadStringLineAfterQuotes for single-line strings. Reference:
func ReadStringLineAfterQuotes ¶
ReadStringLineAfterQuotes reads a single-line StringValue contents after '"'. Tip: Use ReadStringBlock for block strings. Reference:
func ReadVariableDefinitionsAfterParenthesis ¶
ReadVariableDefinitionsAfterParenthesis reads VariableDefinitions after '(' and any ignorables. Reference:
func SkipIgnorables ¶
SkipIgnorables skips over any comments, spaces, tabs, line-breaks and carriage-returns it encounters and returns the s suffix. Reference:
func TrimEmptyLinesSuffix ¶
TrimEmptyLinesSuffix removes any trailing empty lines from the s. An empty line is defined as a line that contains only whitespace characters.
Types ¶
type OperationType ¶
type OperationType int8
const ( OperationTypeQuery OperationType OperationTypeMutation OperationTypeSubscription )
func ReadOperationType ¶
func ReadOperationType(h Hash, s []byte) ( operationType OperationType, suffix []byte, err error, )
ReadOperationType reads OperationType. Reference: