builders

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeScalar    fieldType = "Scalar"
	TypeRelation  fieldType = "Relation"
	TypeAggregate fieldType = "Aggregate"
	TypeObject    fieldType = "Object"
)

Variables

This section is empty.

Functions

func AddRelationFilters

func AddRelationFilters(ctx context.Context, s *ast.Schema, obj interface{}) context.Context

func GenerateTableName

func GenerateTableName(n int) string

func GetFilterInput

func GetFilterInput(s *ast.Schema, f *ast.Definition) *ast.Definition

func WithFieldFilterContext

func WithFieldFilterContext(ctx context.Context, rc *FilterFieldContext) context.Context

Types

type AggregateBuilder

type AggregateBuilder interface {
	Aggregate(field Field) (string, []interface{}, error)
}

AggregateBuilder allows Builders to build aggregate queries on _XYZAggregate fields

type AggregatorOperator

type AggregatorOperator func(table exp.AliasedExpression, fields []Field) (goqu.Expression, error)

AggregatorOperator gets called on aggregation methods // TBD //

type Builder

type Builder interface {
	QueryBuilder
	AggregateBuilder
	MutationBuilder
}

type ColumnCaseConverter

type ColumnCaseConverter func(c string) string

ColumnCaseConverter converts columns from ast.Field Name to database field name, by default it converts to snake case but sometimes as a user you want to override this logic / define special abbreviations etc'

type Config

type Config struct {
	Schema *ast.Schema
	Logger log.Logger
	// CustomOperators are user defined operators, can also be used to override existing default operators.
	CustomOperators map[string]Operator

	// TableNameGenerator allows defining how aliases "Table" names are generated in the query, this is mostly used for test
	TableNameGenerator TableNameGenerator

	// ColumnCaseConverter converts columns from ast.Field Name to database field name, by default it converts to snake case
	// but sometimes as a user you want to override this logic / define special abbreviations etc'
	ColumnCaseConverter ColumnCaseConverter
}

Config is the basic level of data passed to a builder when it's created

type DialectDirective

type DialectDirective struct {
	Dialect       string
	ParentDialect string
}

func GetDialectDirective

func GetDialectDirective(schema *ast.Schema, field Field) (*DialectDirective, error)

type Field

type Field struct {
	// Original *ast.Field
	*ast.Field
	// Field sub selection, if field type is TypeScalar, selections will be empty
	Selections Fields
	// FieldType i.e Scalar/Relation/Aggregate/Object etc'
	FieldType fieldType
	// Arguments passed to this field if any.
	Arguments map[string]interface{}
	// TypeDefinition is the ast.Schema Type, this is saved for easier access
	TypeDefinition *ast.Definition
	// Parent field of this field
	Parent *Field
}

Field is a helpful wrapper over *ast.Field adding more custom information when collecting the GraphQL query AST

func CollectFields

func CollectFields(ctx context.Context, schema *ast.Schema) Field

func CollectFromQuery

func CollectFromQuery(field *ast.Field, schema *ast.Schema, opCtx *graphql.OperationContext, args map[string]interface{}) Field

func GetAggregateField

func GetAggregateField(parentField, aggField Field) Field

func NewField

func NewField(parent *Field, field *ast.Field, schema *ast.Schema, args map[string]interface{}) Field

func (Field) ForName

func (f Field) ForName(name string) (Field, error)

func (Field) GetTypeName

func (f Field) GetTypeName() string

func (Field) Relation

func (f Field) Relation() *schema.RelationDirective

Relation directive on field, if it exists

func (Field) Table

func (f Field) Table() *schema.TableDirective

Table directive on field, if it exists

type Fields

type Fields []Field

func (Fields) HasSelection

func (ff Fields) HasSelection(sel string) bool

type FilterContext

type FilterContext string

type FilterFieldContext

type FilterFieldContext struct {
	Filters map[string]interface{}
}

func GetFieldFilterContext

func GetFieldFilterContext(ctx context.Context) *FilterFieldContext

type LogicalOperator

type LogicalOperator string
const (
	LogicalOperatorAND LogicalOperator = "AND"
	LogicalOperatorOR  LogicalOperator = "OR"
	LogicalOperatorNot LogicalOperator = "NOT"
)

type MutationBuilder

type MutationBuilder interface {
	Create(field Field) (string, []interface{}, error)
	Delete(field Field) (string, []interface{}, error)
}

MutationBuilder supports building DELETE/CREATE/UPDATE queries from given GraphQL

type OperationType

type OperationType string
const (
	QueryOperation   OperationType = "query"
	InsertOperation  OperationType = "insert"
	DeleteOperation  OperationType = "delete"
	UpdateOperation  OperationType = "update"
	UnknownOperation OperationType = "unknown"
)

func GetOperationType

func GetOperationType(ctx context.Context) OperationType

type Operator

type Operator func(table exp.AliasedExpression, key string, value interface{}) goqu.Expression

Operator gets called on filters expressions written in graphql. Users can define new operators in the graphql schema, and define operator functions for those operators based on the operator name given. Operators are added by "key" to comparator Input types, and get called with expected value.

type OrderField

type OrderField struct {
	Key  string
	Type OrderingTypes
}

func CollectOrdering

func CollectOrdering(ordering interface{}) ([]OrderField, error)

type OrderingTypes

type OrderingTypes string
const (
	InputFieldName = "inputs"

	OrderingTypesAsc      OrderingTypes = "ASC"
	OrderingTypesDesc     OrderingTypes = "DESC"
	OrderingTypesAscNull  OrderingTypes = "ASC_NULL_FIRST"
	OrderingTypesDescNull OrderingTypes = "DESC_NULL_FIRST"
)

type QueryBuilder

type QueryBuilder interface {
	Query(field Field) (string, []interface{}, error)
}

QueryBuilder supports building a full query from a given GraphQL query

type TableNameGenerator

type TableNameGenerator interface {
	Generate(n int) string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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