Documentation
¶
Index ¶
- Constants
- func GetFilterInput(s *ast.Schema, f *ast.Definition) *ast.Definition
- func WithFieldFilterContext(ctx context.Context, rc *FilterFieldContext) context.Context
- type AggregatorOperator
- type Builder
- type Capabilities
- type ColumnCaseConverter
- type Config
- type Driver
- type Field
- func CollectFields(ctx context.Context, schema *ast.Schema) Field
- func CollectFromQuery(field *ast.Field, schema *ast.Schema, opCtx *graphql.OperationContext, ...) Field
- func GetAggregateField(parentField, aggField Field) Field
- func NewField(parent *Field, field *ast.Field, schema *ast.Schema, ...) Field
- type Fields
- type FilterFieldContext
- type LogicalOperator
- type OperationType
- type Operator
- type OrderField
- type OrderingTypes
- type Query
- type TableNameGenerator
Constants ¶
const ( TypeScalar fieldType = "Scalar" TypeRelation fieldType = "Relation" TypeAggregate fieldType = "Aggregate" TypeObject fieldType = "Object" )
Variables ¶
This section is empty.
Functions ¶
func GetFilterInput ¶
func GetFilterInput(s *ast.Schema, f *ast.Definition) *ast.Definition
func WithFieldFilterContext ¶
func WithFieldFilterContext(ctx context.Context, rc *FilterFieldContext) context.Context
WithFieldFilterContext adds filter context to the context.
Types ¶
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 {
// Query generates a read query from the GraphQL field
Query(field Field) (Query, error)
// Create generates an insert/create mutation query
Create(field Field) (Query, error)
// Update generates an update mutation query
Update(field Field) (Query, error)
// Delete generates a delete mutation query
Delete(field Field) (Query, error)
// Capabilities returns what this database supports
Capabilities() Capabilities
}
Builder generates queries for a specific database dialect. Each database implementation (SQL, MongoDB, Cypher, etc.) implements this interface.
type Capabilities ¶ added in v0.3.1
type Capabilities struct {
// SupportsJoins indicates if the database can perform JOIN operations.
// False for Cassandra, true for SQL databases.
SupportsJoins bool
// SupportsReturning indicates if mutations can return affected rows.
// PostgreSQL supports INSERT...RETURNING, some databases don't.
SupportsReturning bool
// SupportsTransactions indicates if the database supports ACID transactions.
SupportsTransactions bool
// MaxRelationDepth limits nested relation queries.
// -1 = unlimited, 0 = no relations (use DataLoader pattern), N = max depth
MaxRelationDepth int
}
Capabilities declares what features a database supports. This allows the framework to adapt behavior based on database limitations.
type ColumnCaseConverter ¶
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
// Dialect specifies the SQL dialect to use (e.g., "postgres", "mysql", "snowflake").
// Defaults to "postgres" if not specified.
Dialect string
}
Config is the basic level of data passed to a builder when it's created
type Driver ¶ added in v0.3.1
type Driver interface {
// Execute runs the query and scans results into dest
Execute(ctx context.Context, query Query, dest any) error
// Close closes the database connection
Close() error
// Dialect returns the database dialect name (e.g., "postgres", "mongodb")
Dialect() string
}
Driver executes queries against a database connection.
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 CollectFromQuery ¶
func GetAggregateField ¶
func (Field) GetTypeName ¶
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 FilterFieldContext ¶
type FilterFieldContext struct {
Filters map[string]interface{}
}
FilterFieldContext holds filter information for a field.
func GetFieldFilterContext ¶
func GetFieldFilterContext(ctx context.Context) *FilterFieldContext
GetFieldFilterContext retrieves filter context from the context.
type LogicalOperator ¶
type LogicalOperator string
const ( LogicalOperatorAND LogicalOperator = "AND" LogicalOperatorOR LogicalOperator = "OR" LogicalOperatorNot LogicalOperator = "NOT" )
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 Query ¶ added in v0.3.1
type Query interface {
// Native returns the dialect-specific query object.
// For SQL: SQLQuery{sql, args}
// For MongoDB: mongo.Pipeline
// For Cypher: string
Native() any
// String returns a human-readable representation for logging/debugging
String() string
}
Query is the output of a builder - wraps database-specific query objects. Implementations include SQLQuery (string + args), MongoDB Pipeline, Cypher string, etc.