ast

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFieldDirective

func AddFieldDirective(name string, fn func(f *Field, d *Directive, store *NodeStore, parent Node) errors.GraphqlErrorInterface)

func AddFieldRuntimeDirective added in v0.0.4

func AddFieldRuntimeDirective(name string, fn func(f *Field, d *Directive, store *NodeStore, parent Node) errors.GraphqlErrorInterface)

func AddObjectDirective

func AddObjectDirective(name string, fn func(o *ObjectNode, d *Directive, store *NodeStore) errors.GraphqlErrorInterface)

func BuildRelation

func BuildRelation(field *Field) string

func ExtractValue

func ExtractValue(v Value) (interface{}, error)

func Fields

func Fields(fields map[string]*Field) string

func IsValidLocation

func IsValidLocation(loc Location) bool

func Model

func Model(typeNode *ObjectNode) string

func PrefixModels added in v0.0.2

func PrefixModels(typeName string) string

func ValidateDirectives

func ValidateDirectives(name string, directives []*Directive, store *NodeStore, location Location) errors.GraphqlErrorInterface

Types

type Argument

type Argument struct {
	BaseLocation
	Name         string       `json:"name"`
	Description  *string      `json:"description"`
	Directives   []*Directive `json:"-"`
	Type         *TypeRef     `json:"type"`
	DefaultValue any          `json:"default_value"`
	Value        any          `json:"-"`
	IsVariable   bool         `json:"-"`
	IsReference  bool         `json:"-"`
}

func (*Argument) GetDefaultValue

func (a *Argument) GetDefaultValue() *string

func (*Argument) GetValue added in v0.0.4

func (a *Argument) GetValue() (interface{}, errors.GraphqlErrorInterface)

func (*Argument) Validate

func (a *Argument) Validate(store *NodeStore, args map[string]*Argument, field *Field) errors.GraphqlErrorInterface

type BaseLocation

type BaseLocation struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

func (*BaseLocation) GetLocation

func (l *BaseLocation) GetLocation() *errors.GraphqlLocation

type BaseNode

type BaseNode struct {
	Name          string                    `json:"name"`
	Description   *string                   `json:"description"`
	Fields        map[string]*Field         `json:"fields"`
	InputFields   map[string]*Field         `json:"inputFields"`
	Interfaces    map[string]*InterfaceNode `json:"interfaces"`
	EnumValues    map[string]*EnumValue     `json:"enumValues"`
	PossibleTypes map[string]*ObjectNode    `json:"possibleTypes"`

	Kind       Kind         `json:"kind"`
	Directives []*Directive `json:"-"`
	IsReserved bool         `json:"-"`
}

func (*BaseNode) GetDescription

func (n *BaseNode) GetDescription() string

func (*BaseNode) GetDirectives

func (n *BaseNode) GetDirectives() []*Directive

func (*BaseNode) GetDirectivesByName

func (n *BaseNode) GetDirectivesByName(name string) []*Directive

func (*BaseNode) GetFields

func (n *BaseNode) GetFields() map[string]*Field

func (*BaseNode) GetKind

func (n *BaseNode) GetKind() Kind

func (*BaseNode) GetName

func (n *BaseNode) GetName() string

func (*BaseNode) GetPossibleTypes

func (n *BaseNode) GetPossibleTypes() map[string]*ObjectNode

func (*BaseNode) Validate

func (n *BaseNode) Validate(store *NodeStore) errors.GraphqlErrorInterface

type BooleanValue

type BooleanValue struct{ Value bool }

func (*BooleanValue) IsValue

func (v *BooleanValue) IsValue() bool

type Directive

type Directive struct {
	BaseLocation
	Name       string               `json:"name"`
	Args       map[string]*Argument `json:"args"`
	Definition *DirectiveDefinition `json:"-"`
}

func GetDirective

func GetDirective(name string, directives []*Directive) []*Directive

func (*Directive) GetArg

func (d *Directive) GetArg(name string) *Argument

func (*Directive) Validate

func (d *Directive) Validate(store *NodeStore, location Location) errors.GraphqlErrorInterface

type DirectiveDefinition

type DirectiveDefinition struct {
	BaseLocation
	Name        string               `json:"name"`
	Description *string              `json:"description"`
	Args        map[string]*Argument `json:"args"`
	Locations   []Location           `json:"locations"`
	Repeatable  bool                 `json:"repeatable"`

	Directives []*Directive `json:"-"`
}

func (*DirectiveDefinition) GetDescription

func (d *DirectiveDefinition) GetDescription() string

func (*DirectiveDefinition) Validate

type EnumNode

type EnumNode struct {
	BaseNode
	BaseLocation
	EnumValues map[string]*EnumValue `json:"enumValues"`
}

func (*EnumNode) Validate

func (e *EnumNode) Validate(store *NodeStore) errors.GraphqlErrorInterface

type EnumValue

type EnumValue struct {
	BaseLocation
	Name              string       `json:"name"`
	Description       *string      `json:"description"`
	Directives        []*Directive `json:"-"`
	Value             int8         `json:"-"`
	IsDeprecated      bool         `json:"isDeprecated"`
	DeprecationReason *string      `json:"deprecationReason"`
}

func (*EnumValue) Validate

func (e *EnumValue) Validate(store *NodeStore) errors.GraphqlErrorInterface

type Field

type Field struct {
	BaseLocation
	Alias             string               `json:"-"`
	Name              string               `json:"name"`
	Description       *string              `json:"description"`
	Args              map[string]*Argument `json:"args"`
	Type              *TypeRef             `json:"type"`
	IsDeprecated      bool                 `json:"isDeprecated"`
	DeprecationReason *string              `json:"deprecationReason"`

	Children   map[string]*Field `json:"-"`
	Directives []*Directive      `json:"-"`
	IsFragment bool              `json:"-"`
	IsUnion    bool              `json:"-"`
	Fragment   *Fragment         `json:"-"`

	DefinitionDirectives []*Directive         `json:"-"`
	DefinitionArgs       map[string]*Argument `json:"-"`
	Relation             *Relation            `json:"-"`
}

func (*Field) ParseFieldDirectives

func (f *Field) ParseFieldDirectives(store *NodeStore, parent Node) errors.GraphqlErrorInterface

func (*Field) Validate

func (f *Field) Validate(store *NodeStore, objectFields map[string]*Field, objectNode Node, location Location, fragments map[string]*Fragment, args map[string]*Argument) errors.GraphqlErrorInterface

type FloatValue

type FloatValue struct{ Value float64 }

func (*FloatValue) IsValue

func (v *FloatValue) IsValue() bool

type Fragment

type Fragment struct {
	BaseLocation
	Name       string            `json:"name"`
	On         string            `json:"on"`
	Object     *ObjectNode       `json:"-"`
	Directives []*Directive      `json:"-"`
	Fields     map[string]*Field `json:"fields"`
}

func (*Fragment) Validate

func (f *Fragment) Validate(store *NodeStore, fragments map[string]*Fragment) errors.GraphqlErrorInterface

type InputObjectNode

type InputObjectNode struct {
	BaseNode
	BaseLocation
	Fields map[string]*Field `json:"inputFields"`
}

func (*InputObjectNode) GetFields

func (i *InputObjectNode) GetFields() map[string]*Field

func (*InputObjectNode) Validate

type IntValue

type IntValue struct{ Value int64 }

func (*IntValue) IsValue

func (v *IntValue) IsValue() bool

type InterfaceNode

type InterfaceNode struct {
	BaseNode
	BaseLocation
	Fields map[string]*Field `json:"fields"`
}

func (*InterfaceNode) GetFields

func (o *InterfaceNode) GetFields() map[string]*Field

func (*InterfaceNode) Validate

type Kind

type Kind string
const (
	KindScalar      Kind = "SCALAR"
	KindObject      Kind = "OBJECT"
	KindInterface   Kind = "INTERFACE"
	KindUnion       Kind = "UNION"
	KindEnum        Kind = "ENUM"
	KindInputObject Kind = "INPUT_OBJECT"
	KindList        Kind = "LIST"
	KindNonNull     Kind = "NON_NULL"
)

func (Kind) String

func (k Kind) String() string

type ListValue

type ListValue struct{ Values []Value }

func (*ListValue) IsValue

func (v *ListValue) IsValue() bool

type Location

type Location string
const (
	LocationQuery                Location = `QUERY`
	LocationMutation             Location = `MUTATION`
	LocationSubscription         Location = `SUBSCRIPTION`
	LocationField                Location = `FIELD`
	LocationFragmentDefinition   Location = `FRAGMENT_DEFINITION`
	LocationFragmentSpread       Location = `FRAGMENT_SPREAD`
	LocationInlineFragment       Location = `INLINE_FRAGMENT`
	LocationSchema               Location = `SCHEMA` // deprecated
	LocationScalar               Location = `SCALAR`
	LocationObject               Location = `OBJECT`
	LocationFieldDefinition      Location = `FIELD_DEFINITION`
	LocationArgumentDefinition   Location = `ARGUMENT_DEFINITION`
	LocationInterface            Location = `INTERFACE`
	LocationUnion                Location = `UNION`
	LocationEnum                 Location = `ENUM`
	LocationEnumValue            Location = `ENUM_VALUE`
	LocationInputObject          Location = `INPUT_OBJECT`
	LocationInputFieldDefinition Location = `INPUT_FIELD_DEFINITION`
	LocationVariableDefinition   Location = `VARIABLE_DEFINITION`
)

type Locationable

type Locationable interface {
	GetLocation() errors.GraphqlLocation
}

type Node

type Node interface {
	// GetName returns the name of the node.
	GetName() string

	// GetKind returns the kind of the node.
	GetKind() Kind

	// GetDescription returns the description of the node, if available.
	// It may return an empty string if no description is provided.
	GetDescription() string

	// GetDirectivesByName returns a slice of directives with the specified name.
	// It may return an empty slice if no directives are found.
	GetDirectivesByName(name string) []*Directive

	// Validate validates the node.
	Validate(store *NodeStore) errors.GraphqlErrorInterface

	// GetDirectives returns the directives of the node.
	GetDirectives() []*Directive
	GetFields() map[string]*Field
	GetPossibleTypes() map[string]*ObjectNode
}

Node represents a GraphQL AST node.

type NodeStore

type NodeStore struct {
	// Scalars is a map of all scalars
	Scalars map[string]*ScalarNode

	// Interfaces is a map of all interfaces
	Interfaces map[string]*InterfaceNode

	// Objects is a map of all objects
	Objects map[string]*ObjectNode

	// Unions is a map of all unions
	Unions map[string]*UnionNode

	// Enums is a map of all enums
	Enums map[string]*EnumNode

	// Inputs is a map of all inputs
	Inputs map[string]*InputObjectNode

	// Directives is a map of all directives
	Directives map[string]*DirectiveDefinition

	// ScalarTypes is a map of all scalar types
	ScalarTypes map[string]ScalarType

	// Names is a map of all names , it can be a type, enum, interface, input, scalar, union, directive, extend
	Names map[string]any

	// Nodes is a map of all nodes
	Nodes map[string]Node
}

func (*NodeStore) AddDirective

func (s *NodeStore) AddDirective(name string, node *DirectiveDefinition)

func (*NodeStore) AddEnum

func (s *NodeStore) AddEnum(name string, node *EnumNode)

func (*NodeStore) AddInput

func (s *NodeStore) AddInput(name string, node *InputObjectNode)

func (*NodeStore) AddInterface

func (s *NodeStore) AddInterface(name string, node *InterfaceNode)

func (*NodeStore) AddObject

func (s *NodeStore) AddObject(name string, node *ObjectNode)

func (*NodeStore) AddScalar

func (s *NodeStore) AddScalar(name string, node *ScalarNode)

func (*NodeStore) AddUnion

func (s *NodeStore) AddUnion(name string, node *UnionNode)

func (*NodeStore) InitStore

func (s *NodeStore) InitStore()

type NullValue

type NullValue struct{}

func (*NullValue) IsValue

func (v *NullValue) IsValue() bool

type ObjectNode

type ObjectNode struct {
	BaseNode
	BaseLocation
	Fields         map[string]*Field `json:"fields"`
	InterfaceNames []string          `json:"-"`
	IsModel        bool              `json:"-"`

	Table string `json:"-"`
}

func (*ObjectNode) GetFields

func (o *ObjectNode) GetFields() map[string]*Field

func (*ObjectNode) ParseObjectDirectives

func (o *ObjectNode) ParseObjectDirectives(store *NodeStore) errors.GraphqlErrorInterface

func (*ObjectNode) Validate

func (o *ObjectNode) Validate(store *NodeStore) errors.GraphqlErrorInterface

type ObjectValue

type ObjectValue struct{ Values map[string]Value }

func (*ObjectValue) IsValue

func (v *ObjectValue) IsValue() bool

type Relation

type Relation struct {
	RelationType RelationType `json:"relationType"`
	Name         string       `json:"name"`
	ForeignKey   string       `json:"foreignKey"`
	Reference    string       `json:"reference"`
	MorphType    string       `json:"morphType"`
	MorphKey     string       `json:"morphKey"`
}

type RelationType

type RelationType string
const (
	RelationTypeBelongsTo     RelationType = "RelationTypeBelongsTo"
	RelationTypeHasMany       RelationType = "RelationTypeHasMany"
	RelationTypeHasOne        RelationType = "RelationTypeHasOne"
	RelationTypeMorphTo       RelationType = "RelationTypeMorphTo"
	RelationTypeMorphMany     RelationType = "RelationTypeMorphMany"
	RelationTypeBelongsToMany RelationType = "RelationTypeBelongsToMany"
)

type ScalarNode

type ScalarNode struct {
	BaseNode
	BaseLocation
	ScalarType ScalarType `json:"-"`
}

func (*ScalarNode) Validate

func (s *ScalarNode) Validate(store *NodeStore) errors.GraphqlErrorInterface

type ScalarType

type ScalarType interface {
	ParseValue(v interface{}, location *errors.GraphqlLocation) (interface{}, errors.GraphqlErrorInterface)
	Serialize(v interface{}, location *errors.GraphqlLocation) (interface{}, errors.GraphqlErrorInterface)
	ParseLiteral(v interface{}, location *errors.GraphqlLocation) (interface{}, errors.GraphqlErrorInterface)
	GoType() string
}

type StringValue

type StringValue struct{ Value string }

func (*StringValue) IsValue

func (v *StringValue) IsValue() bool

type TypeRef

type TypeRef struct {
	BaseLocation
	Kind     Kind     `json:"kind"`
	Name     string   `json:"name"`
	OfType   *TypeRef `json:"ofType"`
	TypeNode Node     `json:"-"`
}

func (*TypeRef) GetGoName

func (t *TypeRef) GetGoName() string

func (*TypeRef) GetGoType

func (t *TypeRef) GetGoType(NonNull bool) string

func (*TypeRef) GetRealType

func (t *TypeRef) GetRealType() *TypeRef

func (*TypeRef) IsEnum added in v0.0.4

func (t *TypeRef) IsEnum() bool

func (*TypeRef) IsList added in v0.0.2

func (t *TypeRef) IsList() bool

func (*TypeRef) IsObject added in v0.0.2

func (t *TypeRef) IsObject() bool

func (*TypeRef) IsScalar added in v0.0.2

func (t *TypeRef) IsScalar() bool

func (*TypeRef) Validate

func (t *TypeRef) Validate(store *NodeStore) errors.GraphqlErrorInterface

func (*TypeRef) ValidateValue

func (t *TypeRef) ValidateValue(v interface{}, isVariable bool) errors.GraphqlErrorInterface

type UnionNode

type UnionNode struct {
	BaseNode
	BaseLocation
	TypeNames map[string]string `json:"-"`
}

func (*UnionNode) Validate

func (u *UnionNode) Validate(store *NodeStore) errors.GraphqlErrorInterface

type Value

type Value interface{ IsValue() bool }

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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