graph

package
v0.0.0-...-f7ac3c2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DOT      = '.'
	COMMA    = ','
	PLUS     = '+'
	HYPHEN   = '-'
	EXCLAM   = '!'
	USCORE   = '_'
	LPAREN   = '('
	SQUOTE   = '\''
	DQUOTE   = '"'
	RPAREN   = ')'
	LCURLY   = '{'
	RCURLY   = '}'
	ESCAPE   = '\\'
	ASTERISK = '*'
)

Variables

This section is empty.

Functions

func SplitFieldsQ

func SplitFieldsQ(inline string) []string

InlineFieldsQ split given values into set of Field(s)Q selection.

Types

type Args

type Args map[string]any

Args of the query

func (Args) Clone

func (vs Args) Clone() Args

func (Args) Get

func (vs Args) Get(param string) any

func (Args) Has

func (vs Args) Has(param string) (ok bool)

func (Args) Page

func (vs Args) Page() uint32

func (*Args) Set

func (vs *Args) Set(param string, value any) error

func (Args) Size

func (vs Args) Size() int32

func (Args) Sort

func (vs Args) Sort() []string

func (Args) ValueOf

func (vs Args) ValueOf(param string, typeOf Input) (value any, err error)

type Argument

type Argument struct {
	// Name of the Argument
	Name string `json:"name"`
	// Type of the Argument
	Type Input `json:"typeOf"`
	// OPTIONAL. Default Value
	Value any `json:"value,omitempty"`
}

Input Argument descriptor

func (*Argument) IsValid

func (e *Argument) IsValid() bool

IsValid Argument descriptor for use

func (*Argument) Optional

func (e *Argument) Optional() bool

Optional -if- has default value

func (*Argument) Required

func (e *Argument) Required() bool

Required -if- has no default value

type Bool

type Bool struct{}

func (Bool) GoString

func (c Bool) GoString() string

func (Bool) InputValue

func (c Bool) InputValue(src any) (set any, err error)

type FieldEncoding

type FieldEncoding func(syntax *FieldExpansion)

FieldEncoding as an expansion option

func DefaultFields

func DefaultFields(q ...string) FieldEncoding

DefaultFields FieldEncoding Option. If no ?fields= were specified, this set of `q` will be used.

func NoArgs

func NoArgs() FieldEncoding

NoArgs FieldEncoding Option. Disallow field[.arg(input)]* component(s)

func NoNested

func NoNested() FieldEncoding

NoQuery FieldEncoding Option. Does NOT expose .query(),.. component(s)

func Sorting

func Sorting() FieldEncoding

Sorting FieldEncoding Option. Cause to validate ?sort= fields spec

type FieldExpansion

type FieldExpansion struct {
	// Invalidate field.query(args) expansion
	NoArgs bool
	// Invalidate field{nested,..} expansion
	NoNested bool
	// Default fields set if none specified
	// Used to reassign Metadata.Default set.
	Default []string
	// Sorting fields specification mode ?
	//
	// sort   ::= spec *( "," spec )
	// spec   ::= [ ORDER ] name / nest
	// nest   ::= name "{" nest / sort "}"
	// name   ::= ALPHA / DIGIT / USCORE ; field name
	//
	// ALPHA    = %x41-5A / %x61-7A  ; "A"-"Z" / "a"-"z"
	// DIGIT    = %x30-39            ; "0"-"9"
	// USCORE   = %x5F ; underscore  ; "_"
	//
	// Examples:
	//
	// ?sort=+id,names{!common_name,id}
	// ?sort=id&sort=names{-common_name,id}; affected as above
	//
	// Invalid:
	// ?sort=+id,!names{-common_name,id}; illegal "!"; (nested only) fields MAY be sorted
	//
	// If false - regular GET fields specification mode is used.
	Sorting bool
}

FieldExpansion syntax options.

func NewFieldExpansion

func NewFieldExpansion(options ...FieldEncoding) (syntax FieldExpansion)

type FieldsQ

type FieldsQ []*Query

Fields[Q]uery represents a set of query{ fields }.

func ParseFields

func ParseFields(s string, decode ...FieldEncoding) (fields FieldsQ, err error)

ParseFields decodes ?fields=name[.query([args..]),..][{nested,..}][,..] string specification.

func ParseFieldsQuery

func ParseFieldsQuery(vs []string, decode ...FieldEncoding) (fields FieldsQ, err error)

ParseFieldsQuery acts like ParseFields method, but decodes ?fields=[&fields=] query specification.

func (*FieldsQ) Add

func (vs *FieldsQ) Add(out Query) bool

func (FieldsQ) Clone

func (vs FieldsQ) Clone() FieldsQ

func (FieldsQ) Encode

func (fs FieldsQ) Encode(syntax ...FieldEncoding) (text []byte, err error)

func (FieldsQ) Fields

func (req FieldsQ) Fields() []string

Fields returns set of FieldQ.Name

func (FieldsQ) Get

func (vs FieldsQ) Get(name string) *Query

<nil>: NOT FOUND

func (FieldsQ) Has

func (vs FieldsQ) Has(name string) bool

func (FieldsQ) Index

func (req FieldsQ) Index(name string) int

-1: NOT FOUND

func (FieldsQ) MarshalText

func (fs FieldsQ) MarshalText() ([]byte, error)

func (*FieldsQ) Parse

func (fs *FieldsQ) Parse(s string, decode ...FieldEncoding) error

func (*FieldsQ) ParseQuery

func (fs *FieldsQ) ParseQuery(vs []string, decode ...FieldEncoding) error

func (FieldsQ) String

func (fs FieldsQ) String() string

type Input

type Input interface {
	// String type name
	GoString() string
	// Decode input data source value
	InputValue(src any) (any, error)
}

Input Type interface

type InputArgs

type InputArgs map[string]Argument

InputArgs maps argument name to it's input type

func (InputArgs) Add

func (vs InputArgs) Add(reg Argument) (err error)

[option]: control [isDefault]: means option.Value(nil) returns default value [isMandatory]: means this option MUST be always [re]assigned with it's default value func (list *OptionList) Add(option Option, isDefault, isMandatory bool) error {

func (InputArgs) Args

func (vs InputArgs) Args() []string

func (InputArgs) Get

func (vs InputArgs) Get(name string) *Argument

func (InputArgs) Has

func (vs InputArgs) Has(name string) bool

func (InputArgs) Len

func (vs InputArgs) Len() int

func (InputArgs) Parse

func (vs InputArgs) Parse(req *Query) error

Parse req.Query options

type InputPage

type InputPage uint32

Input type of the list (page:uint32)

func (InputPage) GoString

func (c InputPage) GoString() string

func (InputPage) InputValue

func (c InputPage) InputValue(src any) (set any, err error)

Value always return uint32 value; Default: 1.

type InputSize

type InputSize struct {
	Minimum, Maximum, Default int32
}

Input type of the list (size:int32)

func (InputSize) GoString

func (c InputSize) GoString() string

func (InputSize) InputValue

func (c InputSize) InputValue(src any) (set any, err error)

Value returns `set` value of $int32; Zero(0) - stands for default value; Negative(-1) - no limit; fetch all; Positive(+1) - regular value;

type InputSort

type InputSort []string

Input type of the list (sort:$[-!+]field[{nested,..}],..)

func (InputSort) GoString

func (c InputSort) GoString() string

func (InputSort) InputValue

func (c InputSort) InputValue(src any) (set any, err error)

type Metadata

type Metadata struct {
	// Name of the Object
	Name string `json:"name"`
	// Type of the Output data
	Type string `json:"typeOf"`
	// OPTIONAL. Input Arguments supported
	Args InputArgs `json:"input,omitempty"`
	// OPTIONAL. Output Fields of the Object Type
	Fields []*Metadata `json:"fields,omitempty"`
	// OPTIONAL. Default set of output Fields; expansion of ('*')
	Default []string `json:"output,omitempty"`
	// Resolve Output data or an error.
	Resolve OutputFunc `json:"-"`
}

GraphQL Metadata about an Object.

func (*Metadata) FieldQ

func (md *Metadata) FieldQ(req *Query, syntax ...FieldEncoding) error

GetQuery validates and normalize given `req` FieldQ of this Metadata configuration.

func (*Metadata) FieldsQ

func (md *Metadata) FieldsQ(req *FieldsQ, syntax ...FieldEncoding) error

FieldsQ presets ( validate & normalize & defaults ) given FieldsQ `req` according to this `md` Metadata.Fields and optional `syntax` options configuration.

func (*Metadata) GetField

func (md *Metadata) GetField(name string) *Metadata

FieldsQ validates and normalize given `fs` query fields

func (*Metadata) ParseFields

func (md *Metadata) ParseFields(vs []string, decode ...FieldEncoding) (fields FieldsQ, err error)

ParseFields decodes ?fields=[&fields=] query value(s) spec. Validate & normalize expansion due to `md`.Fields configuration.

type NotNull

type NotNull struct {
	TypeOf Input
}

func (NotNull) GoString

func (c NotNull) GoString() string

func (NotNull) InputValue

func (c NotNull) InputValue(src any) (any, error)

type OutputFunc

type OutputFunc func(output *ResolveArgs) (data any, err error)

OutputFunc must resolve Node-* related data for output

type Query

type Query struct {
	// REQUIRED. Name of the Query Object for output.
	Name string
	// OPTIONAL. Input arguments of the Query.
	Args
	// OPTIONAL. Nested Fields of the Query Object.
	Fields FieldsQ
}

Field[Q]uery

func ParseFieldQ

func ParseFieldQ(s string) (Query, error)

ParseFieldQ parse single field

func (*Query) Clone

func (req *Query) Clone() *Query

func (*Query) Encode

func (fd *Query) Encode(syntax ...FieldEncoding) (text []byte, err error)

func (*Query) MarshalText

func (req *Query) MarshalText() ([]byte, error)

func (*Query) String

func (req *Query) String() string

type ResolveArgs

type ResolveArgs struct {
	// Node to output
	Node any
	// Query of the Node
	*Query
	// Context bindings
	context.Context
}

ResolveArgs Context

type String

type String string

String Input Type

func (String) GoString

func (String) GoString() string

func (String) InputValue

func (c String) InputValue(src any) (set any, err error)

Jump to

Keyboard shortcuts

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