Documentation
¶
Index ¶
- Constants
- Variables
- func AddExtensions(origin *ast.SchemaDocument, extension *ast.SchemaDocument) (*ast.Schema, error)
- func AggregatedObjectDef(defs Definitions, def *ast.Definition) *ast.Definition
- func AggregatedQueryDef(field *ast.Field) *ast.FieldDefinition
- func Compile(source *ast.SchemaDocument, opt Options) (*ast.Schema, error)
- func CompileExtension(schema *ast.Schema, extension *ast.SchemaDocument, opt Options) (*ast.Schema, *ast.SchemaDocument, []string, error)
- func CompiledPosName(name string) *ast.Position
- func DataObjectType(def *ast.Definition) string
- func DirectiveArgChildValues(d *ast.Directive, name string, vars map[string]any) []string
- func DirectiveArgValue(d *ast.Directive, name string, vars map[string]any) string
- func ErrorPosf(pos *ast.Position, format string, args ...interface{}) *gqlerror.Error
- func ExtractFieldsFromSQL(sql string) []string
- func FlatQuery(queries []QueryRequest) map[string]QueryRequest
- func HasSystemDirective(def ast.DirectiveList) bool
- func IsAggregateQuery(field *ast.Field) bool
- func IsAggregateQueryDefinition(def *ast.FieldDefinition) bool
- func IsBucketAggregateQuery(field *ast.Field) bool
- func IsBucketAggregateQueryDefinition(def *ast.FieldDefinition) bool
- func IsDataObject(def *ast.Definition) bool
- func IsDataObjectFieldDefinition(def *ast.FieldDefinition) bool
- func IsDeleteQuery(field *ast.Field) bool
- func IsDeleteQueryDefinition(def *ast.FieldDefinition) bool
- func IsEqualTypes(a, b *ast.Type) bool
- func IsExtraField(def *ast.FieldDefinition) bool
- func IsFunction(field *ast.FieldDefinition) bool
- func IsFunctionCall(field *ast.FieldDefinition) bool
- func IsFunctionCallQuery(field *ast.Field) bool
- func IsFunctionCallSubquery(field *ast.Field) bool
- func IsFunctionCallSubqueryDefinition(def *ast.FieldDefinition) bool
- func IsH3Query(field *ast.Field) bool
- func IsHyperTable(def *ast.Definition) bool
- func IsInsertQuery(field *ast.Field) bool
- func IsInsertQueryDefinition(def *ast.FieldDefinition) bool
- func IsJSONType(typeName string) bool
- func IsJoinSubquery(field *ast.Field) bool
- func IsJoinSubqueryDefinition(def *ast.FieldDefinition) bool
- func IsNoJoinPushdown(field *ast.Field) bool
- func IsNoJoinPushdownDefinition(def *ast.FieldDefinition) bool
- func IsReferencesSubquery(field *ast.FieldDefinition) bool
- func IsScalarAggregationType(typeName string) bool
- func IsScalarType(typeName string) bool
- func IsSelectOneQuery(field *ast.Field) bool
- func IsSelectOneQueryDefinition(def *ast.FieldDefinition) bool
- func IsSelectQuery(field *ast.Field) bool
- func IsSelectQueryDefinition(field *ast.FieldDefinition) bool
- func IsSubQuery(field *ast.FieldDefinition) bool
- func IsSystemType(def *ast.Definition) bool
- func IsTableFuncJoin(field *ast.FieldDefinition) bool
- func IsTableFuncJoinSubquery(field *ast.Field) bool
- func IsTableFuncJoinSubqueryDefinition(def *ast.FieldDefinition) bool
- func IsTimescaleKey(def *ast.FieldDefinition) bool
- func IsUpdateQuery(field *ast.Field) bool
- func IsUpdateQueryDefinition(def *ast.FieldDefinition) bool
- func MergeSchema(schemas ...*ast.Schema) (*ast.SchemaDocument, error)
- func ModuleTypeName(module string, objectType ModuleObjectType) string
- func NewFunction(module, name, sql string, t *ast.Type, isTable, jsonCast bool, ...) *ast.FieldDefinition
- func ObjectModule(def *ast.Definition) string
- func ObjectMutationDefinition(defs Definitions, def *ast.Definition, mutationType ObjectMutationType) (string, *ast.FieldDefinition)
- func ObjectQueryDefinition(defs Definitions, def *ast.Definition, queryType ObjectQueryType) (string, *ast.FieldDefinition)
- func ObjectSQL(def *ast.Definition) string
- func ParseArgumentValue(defs Definitions, arg *ast.ArgumentDefinition, value *ast.Value, ...) (any, error)
- func ParseDataAsInputObject(defs Definitions, inputType *ast.Type, data any, checkRequired bool) (any, error)
- func QueryRequestInfo(ss ast.SelectionSet) ([]QueryRequest, QueryType)
- func RemoveFieldsDuplicates(fields []string) []string
- func SpecifiedByURL(def *ast.Definition) string
- func TransformBaseFieldType(field *ast.FieldDefinition) string
- type Definitions
- type DefinitionsSource
- type Deprecated
- type Field
- func (f *Field) Definition() *ast.FieldDefinition
- func (f *Field) FieldSourceName(prefix string, ident bool) string
- func (f *Field) GeometrySRID() string
- func (f *Field) IsCalcField() bool
- func (f *Field) IsGeometry() bool
- func (f *Field) IsNotDBField() bool
- func (f *Field) IsReferencesSubquery() bool
- func (f *Field) IsRequired() bool
- func (f *Field) IsTransformed() bool
- func (f *Field) SQL(prefix string) string
- func (f *Field) SequenceName() string
- func (f *Field) TransformSQL(sql string) string
- func (f *Field) UsingFields() []string
- type FieldQueryArgument
- type FieldQueryArguments
- type Function
- type FunctionCall
- func (f *FunctionCall) ArgumentMap() map[string]string
- func (f *FunctionCall) ArgumentValues(defs Definitions, vars map[string]any) (FieldQueryArguments, error)
- func (f *FunctionCall) FunctionInfo(defs Definitions) (*Function, error)
- func (f *FunctionCall) JoinConditionsTemplate() string
- func (f *FunctionCall) ReferencesFields() []string
- func (f *FunctionCall) SourceFields() ([]string, error)
- type Join
- type ModuleObjectType
- type ModuleRoot
- type Mutation
- func (m *Mutation) DBFieldName(name string) string
- func (m *Mutation) DefaultSequencesValues() map[string]string
- func (m *Mutation) FieldDefinition(name string) *ast.FieldDefinition
- func (m *Mutation) Fields() []*Field
- func (m *Mutation) M2MReferencesFields() []string
- func (m *Mutation) ReferencesFields() []string
- func (m Mutation) ReferencesFieldsReferences(name string) []string
- func (m Mutation) ReferencesFieldsSource(name string) []string
- func (m *Mutation) ReferencesMutation(name string) *Mutation
- func (m *Mutation) SelectByPKQuery(query *ast.Field) *ast.Field
- type Object
- func (info *Object) ApplyArguments(defs Definitions, args map[string]any, builder sqlBuilder) (err error)
- func (info *Object) Definition() *ast.Definition
- func (info *Object) FieldForName(name string) *Field
- func (info *Object) HasArguments() bool
- func (info *Object) InputFilterName() string
- func (info *Object) InputInsertDataName() string
- func (info *Object) M2MReferencesQueryInfo(defs Definitions, name string) *References
- func (info *Object) ReferencesQueryInfo(defs Definitions, name string) *References
- func (info *Object) ReferencesQueryInfoByName(defs Definitions, name string) *References
- func (info *Object) SQL(ctx context.Context, prefix string) string
- func (info *Object) SoftDeleteCondition(prefix string) string
- func (info *Object) SoftDeleteSet(prefix string) string
- type ObjectMutationType
- type ObjectQueryType
- type Options
- type QueryRequest
- type QueryType
- type References
- func (info *References) FromM2MJoinConditions(defs Definitions, m2mAlias, rightAlias string, isDBLeft, isDBRight bool) (string, error)
- func (info *References) JoinConditions(defs Definitions, leftAlias, rightAlias string, isDBLeft, isDBRight bool) (string, error)
- func (info *References) ReferencesFields() []string
- func (info *References) ReferencesObjectDef(defs Definitions) *ast.Definition
- func (info *References) SourceFields() []string
- func (info *References) ToM2MJoinConditions(defs Definitions, leftAlias, m2mAlias string, isDBLeft, isDBRight bool) (string, error)
- type ScalarType
- type Unique
Constants ¶
View Source
const ( AggregateKeyFieldName = "key" AggregateFieldName = "aggregations" AggRowsCountFieldName = "_rows_count" AggregationSuffix = "_aggregation" BucketAggregationSuffix = "_bucket_aggregation" )
View Source
const ( FieldMeasurementDirectiveName = "measurement" FieldMeasurementFuncArgName = "measurement_func" )
View Source
const ( OperationResultTypeName = "OperationResult" ObjectQueryByPKSuffix = "_by_pk" )
View Source
const ( TableDataObject = "table" ViewDataObject = "view" )
View Source
const ( JoinSourceFieldPrefix = "source" JoinRefFieldPrefix = "dest" )
View Source
const ( MetadataSchemaQuery = "__schema" MetadataTypeQuery = "__type" MetadataTypeNameQuery = "__typename" JQTransformQueryName = "jq" )
View Source
const ( JSONTypeName = "JSON" TimestampTypeName = "Timestamp" H3CellTypeName = "H3Cell" GeometryTypeName = "Geometry" GeometryAggregationTypeName = "GeometryAggregation" GeometryMeasurementExtraFieldName = "Measurement" TimestampExtractExtraFieldName = "Extract" )
View Source
const ( Table = "table" View = "view" )
View Source
const DeprecatedDirectiveName = "deprecated"
View Source
const (
JoinDirectiveName = "join"
)
Variables ¶
View Source
var FieldJSONTypes = map[string]string{
"String": "string",
"Int": "number",
"BigInt": "number",
"Float": "number",
"Boolean": "bool",
"Date": "timestamp",
"Timestamp": "timestamp",
"Time": "timestamp",
"StringAggregation": "string",
"IntAggregation": "number",
"BigIntAggregation": "number",
"FloatAggregation": "number",
"BooleanAggregation": "bool",
"DateAggregation": "timestamp",
"TimestampAggregation": "timestamp",
"TimeAggregation": "timestamp",
"H3Cell": "h3string",
"StringSubAggregation": "",
"IntSubAggregation": "",
"BigIntSubAggregation": "",
"FloatSubAggregation": "",
"BooleanSubAggregation": "",
"DateSubAggregation": "",
"TimestampSubAggregation": "",
"TimeSubAggregation": "",
"JSONSubAggregation": "",
"GeometrySubAggregation": "",
}
View Source
var MeasurementAggregations = map[string]string{
"MIN": "min",
"MAX": "max",
"SUM": "sum",
"AVG": "avg",
"ANY": "any",
}
View Source
var ScalarTypes = map[string]ScalarType{ "String": { Name: "String", Description: "String type", JSONType: "string", JSONToStructType: "VARCHAR", JSONNativeType: "VARCHAR", FilterInput: "StringFilter", ListFilterInput: "StringListFilter", ParseArray: func(value any) (any, error) { return types.ParseScalarArray[string](value) }, AggType: "StringAggregation", MeasurementAggs: "StringMeasurementAggregation", OpenAPISchema: openapi3.NewStringSchema(), }, "Int": { Name: "Int", Description: "Int type", JSONType: "number", JSONToStructType: "INTEGER", JSONNativeType: "INTEGER", FilterInput: "IntFilter", ListFilterInput: "IntListFilter", ParseValue: func(value any) (any, error) { switch v := value.(type) { case int: return int64(v), nil case int32: return int64(v), nil case int64: return v, nil case float64: return int64(v), nil } return nil, fmt.Errorf("unexpected type %T for BigInt", value) }, ParseArray: func(value any) (any, error) { if value == nil { return nil, nil } vv, ok := value.([]any) if !ok { return nil, fmt.Errorf("expected array of BigInt values, got %T", value) } if len(vv) == 0 { return []int64{}, nil } if _, ok := vv[0].(float64); !ok { return types.ParseScalarArray[int64](vv) } dd, err := types.ParseScalarArray[float64](value) if err != nil { return nil, err } out := make([]int64, len(dd)) for i, v := range dd { out[i] = int64(v) } return out, nil }, AggType: "IntAggregation", MeasurementAggs: "IntMeasurementAggregation", OpenAPISchema: openapi3.NewInt32Schema(), }, "BigInt": { Name: "BigInt", Description: "BigInt type", JSONType: "number", JSONToStructType: "BIGINT", JSONNativeType: "BIGINT", FilterInput: "BigIntFilter", ListFilterInput: "BigIntListFilter", ParseValue: func(value any) (any, error) { switch v := value.(type) { case int: return int64(v), nil case int32: return int64(v), nil case int64: return v, nil case float64: return int64(v), nil } return nil, fmt.Errorf("unexpected type %T for BigInt", value) }, ParseArray: func(value any) (any, error) { if value == nil { return nil, nil } vv, ok := value.([]any) if !ok { return nil, fmt.Errorf("expected array of BigInt values, got %T", value) } if len(vv) == 0 { return []int64{}, nil } if _, ok := vv[0].(float64); !ok { return types.ParseScalarArray[int64](vv) } dd, err := types.ParseScalarArray[float64](value) if err != nil { return nil, err } out := make([]int64, len(dd)) for i, v := range dd { out[i] = int64(v) } return out, nil }, AggType: "BigIntAggregation", MeasurementAggs: "BigIntMeasurementAggregation", OpenAPISchema: openapi3.NewInt64Schema(), }, "Float": { Name: "Float", Description: "Float type", JSONType: "number", JSONToStructType: "FLOAT", JSONNativeType: "FLOAT", FilterInput: "FloatFilter", ListFilterInput: "FloatListFilter", ParseValue: func(value any) (any, error) { switch v := value.(type) { case int: return float64(v), nil case int32: return float64(v), nil case int64: return float64(v), nil case float64: return v, nil } return nil, fmt.Errorf("unexpected type %T for Float", value) }, ParseArray: func(value any) (any, error) { return types.ParseScalarArray[float64](value) }, AggType: "FloatAggregation", MeasurementAggs: "FloatMeasurementAggregation", OpenAPISchema: openapi3.NewFloat64Schema(), }, "Boolean": { Name: "Boolean", Description: "Boolean type", JSONType: "bool", JSONToStructType: "BOOLEAN", JSONNativeType: "BOOLEAN", FilterInput: "BooleanFilter", ParseArray: func(value any) (any, error) { return types.ParseScalarArray[bool](value) }, AggType: "BooleanAggregation", MeasurementAggs: "BooleanMeasurementAggregation", OpenAPISchema: openapi3.NewBoolSchema(), }, "Date": { Name: "Date", Description: "Date type", Arguments: ast.ArgumentDefinitionList{ { Name: "bucket", Description: "Truncate ti the specified part of the timestamp. " + "Possible values: 'year', 'month', 'day'.", Type: ast.NamedType("TimeBucket", compiledPos()), Position: compiledPos(), }, }, ExtraField: func(field *ast.FieldDefinition) *ast.FieldDefinition { fieldName := "_" + field.Name + "_part" if strings.HasPrefix(field.Name, "_") { fieldName = strings.TrimPrefix(field.Name, "_") } sql := "[" + field.Name + "]" return &ast.FieldDefinition{ Name: fieldName, Description: field.Description + " (extracted part)", Arguments: ast.ArgumentDefinitionList{ { Name: "extract", Description: "Extracts the specified part of the date", Type: ast.NonNullNamedType("TimeExtract", compiledPos()), Position: compiledPos(), }, { Name: "extract_divide", Description: "Divides the extracted value", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, }, Directives: ast.DirectiveList{ base.SqlFieldDirective(sql), base.ExtraFieldDirective(TimestampExtractExtraFieldName, TimestampTypeName), }, Type: ast.NamedType("BigInt", compiledPos()), Position: compiledPos(), } }, JSONType: "timestamp", JSONToStructType: "DATE", JSONNativeType: "VARCHAR", FilterInput: "DateFilter", ListFilterInput: "DateListFilter", ParseValue: func(value any) (any, error) { return types.ParseTimeValue(value) }, ParseArray: func(value any) (any, error) { return types.ParseScalarArray[time.Time](value) }, AggType: "DateAggregation", MeasurementAggs: "DateMeasurementAggregation", OpenAPISchema: openapi3.NewStringSchema().WithFormat("date"), }, "Timestamp": { Name: "Timestamp", Description: "Timestamp type", Arguments: ast.ArgumentDefinitionList{ { Name: "bucket", Description: "Truncate ti the specified part of the timestamp. " + "Possible values: 'year', 'month', 'day', 'hour', 'minute', 'second'.", Type: ast.NamedType("TimeBucket", compiledPos()), Position: compiledPos(), }, { Name: "bucket_interval", Description: "Extracts the specified part of the timestamp", Type: ast.NamedType("Interval", compiledPos()), Position: compiledPos(), }, }, ExtraField: func(field *ast.FieldDefinition) *ast.FieldDefinition { fieldName := "_" + field.Name + "_part" if strings.HasPrefix(field.Name, "_") { fieldName = strings.TrimPrefix(field.Name, "_") } sql := "[" + field.Name + "]" return &ast.FieldDefinition{ Name: fieldName, Description: field.Description + " (extracted part)", Arguments: ast.ArgumentDefinitionList{ { Name: "extract", Description: "Extracts the specified part of the timestamp", Type: ast.NonNullNamedType("TimeExtract", compiledPos()), Position: compiledPos(), }, { Name: "extract_divide", Description: "Divides the extracted value", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, }, Directives: ast.DirectiveList{ base.SqlFieldDirective(sql), base.ExtraFieldDirective(TimestampExtractExtraFieldName, TimestampTypeName), }, Type: ast.NamedType("BigInt", compiledPos()), Position: compiledPos(), } }, JSONToStructType: "TIMESTAMP", JSONNativeType: "VARCHAR", JSONType: "timestamp", FilterInput: "TimestampFilter", ListFilterInput: "TimestampListFilter", ParseValue: func(value any) (any, error) { return types.ParseTimeValue(value) }, ParseArray: func(value any) (any, error) { return types.ParseScalarArray[time.Time](value) }, AggType: "TimestampAggregation", MeasurementAggs: "TimestampMeasurementAggregation", OpenAPISchema: openapi3.NewStringSchema().WithFormat("date-time"), }, "Time": { Name: "Time", Description: "Time type", JSONType: "timestamp", JSONToStructType: "TIME", JSONNativeType: "VARCHAR", FilterInput: "TimeFilter", ListFilterInput: "TimeListFilter", ParseValue: func(value any) (any, error) { return types.ParseTimeValue(value) }, ParseArray: func(value any) (any, error) { return types.ParseScalarArray[time.Time](value) }, AggType: "TimeAggregation", MeasurementAggs: "TimeMeasurementAggregation", OpenAPISchema: openapi3.NewStringSchema().WithFormat("time"), }, "Interval": { Name: "Interval", Description: "Interval type (duration)", JSONType: "string", JSONToStructType: "INTERVAL", JSONNativeType: "VARCHAR", FilterInput: "IntervalFilter", ListFilterInput: "IntervalListFilter", ParseValue: func(value any) (any, error) { return types.ParseIntervalValue(value) }, ParseArray: func(value any) (any, error) { vv, err := types.ParseScalarArray[string](value) if err != nil { return nil, err } out := make([]time.Duration, len(vv)) for i, v := range vv { r, err := types.ParseIntervalValue(v) if err != nil { return nil, err } out[i] = r } return out, nil }, OpenAPISchema: openapi3.NewStringSchema().WithFormat("interval"), }, "JSON": { Name: "JSON", Description: "JSON type", Arguments: ast.ArgumentDefinitionList{ { Name: "struct", Description: "Provides json structure to extract partial data from json field." + "Structure: {field: \"type\", field2: [\"type2\"], field3: [{field4: \"type4\"}]}.", Type: ast.NamedType("JSON", compiledPos()), Position: compiledPos(), }, }, JSONToStructType: "JSON", JSONNativeType: "JSON", FilterInput: "JSONFilter", ParseValue: func(value any) (any, error) { return types.ParseJsonValue(value) }, AggType: "JSONAggregation", OpenAPISchema: openapi3.NewObjectSchema(), }, "IntRange": { Name: "IntRange", Description: "IntRange type", JSONToStructType: "VARCHAR", JSONNativeType: "VARCHAR", FilterInput: "IntRangeFilter", ListFilterInput: "IntRangeListFilter", ParseValue: func(value any) (any, error) { return types.ParseRangeValue(types.RangeTypeInt32, value) }, ParseArray: func(value any) (any, error) { vv, err := types.ParseScalarArray[string](value) if err != nil { return nil, err } out := make([]types.Int32Range, len(vv)) for i, v := range vv { r, err := types.ParseRangeValue(types.RangeTypeInt32, v) if err != nil { return nil, err } out[i] = r.(types.Int32Range) } return out, nil }, OpenAPISchema: openapi3.NewStringSchema().WithFormat("int-range"), }, "BigIntRange": { Name: "Int8Range", Description: "Int8Range type", JSONToStructType: "VARCHAR", JSONNativeType: "VARCHAR", FilterInput: "BigIntRangeFilter", ListFilterInput: "BigIntRangeListFilter", ParseValue: func(value any) (any, error) { return types.ParseRangeValue(types.RangeTypeInt64, value) }, ParseArray: func(value any) (any, error) { vv, err := types.ParseScalarArray[string](value) if err != nil { return nil, err } out := make([]types.Int64Range, len(vv)) for i, v := range vv { r, err := types.ParseRangeValue(types.RangeTypeInt64, v) if err != nil { return nil, err } out[i] = r.(types.Int64Range) } return out, nil }, OpenAPISchema: openapi3.NewStringSchema().WithFormat("int-range"), }, "TimestampRange": { Name: "TimestampRange", Description: "TimestampRange type", JSONToStructType: "VARCHAR", JSONNativeType: "VARCHAR", FilterInput: "TimestampRangeFilter", ListFilterInput: "TimestampRangeListFilter", ParseValue: func(value any) (any, error) { return types.ParseRangeValue(types.RangeTypeTimestamp, value) }, ParseArray: func(value any) (any, error) { vv, err := types.ParseScalarArray[string](value) if err != nil { return nil, err } out := make([]types.TimeRange, len(vv)) for i, v := range vv { r, err := types.ParseRangeValue(types.RangeTypeTimestamp, v) if err != nil { return nil, err } out[i] = r.(types.TimeRange) } return out, nil }, OpenAPISchema: openapi3.NewStringSchema().WithFormat("timestamp-range"), }, "Geometry": { Name: "Geometry", Description: "Geometry type", Arguments: ast.ArgumentDefinitionList{ { Name: "transforms", Description: "Provides function to transform geometry", Type: ast.ListType(ast.NonNullNamedType("GeometryTransform", compiledPos()), compiledPos()), Position: compiledPos(), }, { Name: "from", Description: "Converts geometry from the specified SRID", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, { Name: "to", Description: "Converts geometry to the specified SRID", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, { Name: "buffer", Description: "Expands the geometry by the specified distance", Type: ast.NamedType("Float", compiledPos()), Position: compiledPos(), }, { Name: "simplify_factor", Description: "Simplifies the geometry by the specified factor", Type: ast.NamedType("Float", compiledPos()), }, }, ExtraField: func(field *ast.FieldDefinition) *ast.FieldDefinition { fieldName := "_" + field.Name + "_measurement" if strings.HasPrefix(field.Name, "_") { fieldName = strings.TrimPrefix(field.Name, "_") } sql := "[" + field.Name + "]" return &ast.FieldDefinition{ Name: fieldName, Description: field.Description + " (geometry measurement)", Arguments: ast.ArgumentDefinitionList{ { Name: "type", Description: "Measurement type", Type: ast.NonNullNamedType("GeometryMeasurementTypes", compiledPos()), Position: compiledPos(), }, { Name: "transform", Description: "Reproject geometry (parameters from and to is required)", Type: ast.NamedType("Boolean", compiledPos()), Position: compiledPos(), }, { Name: "from", Description: "Converts geometry from the specified SRID", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, { Name: "to", Description: "Converts geometry to the specified SRID", Type: ast.NamedType("Int", compiledPos()), Position: compiledPos(), }, }, Directives: ast.DirectiveList{ base.SqlFieldDirective(sql), base.ExtraFieldDirective(GeometryMeasurementExtraFieldName, GeometryTypeName), }, Type: ast.NamedType("Float", compiledPos()), Position: compiledPos(), } }, JSONToStructType: "JSON", JSONNativeType: "VARCHAR", FilterInput: "GeometryFilter", ParseValue: func(value any) (any, error) { return types.ParseGeometryValue(value) }, AggType: "GeometryAggregation", ToOutputTypeSQL: func(sql string, raw bool) string { if raw { return fmt.Sprintf("ST_AsWKB(%s)", sql) } return fmt.Sprintf("ST_AsGeoJSON(%s)", sql) }, ToStructFieldSQL: func(sql string) string { return fmt.Sprintf("ST_AsGeoJSON(%s)", sql) }, OpenAPISchema: openapi3.NewObjectSchema().WithProperty("type", openapi3.NewStringSchema().WithEnum([]string{"Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", "GeometryCollection"})), }, "H3Cell": { Name: "H3Cell", Description: "H3Cell type", JSONType: "h3string", JSONToStructType: "VARCHAR", JSONNativeType: "VARCHAR", ParseValue: func(value any) (any, error) { return types.ParseH3Cell(value) }, ParseArray: func(value any) (any, error) { vv, ok := value.([]any) if !ok { return nil, fmt.Errorf("expected array of H3 cells, got %T", value) } out := make([]any, len(vv)) var err error for i, v := range vv { if v == nil { continue } out[i], err = types.ParseH3Cell(v) if err != nil { return nil, fmt.Errorf("invalid H3 cell value at index %d: %w", i, err) } } return out, nil }, ToOutputTypeSQL: func(sql string, raw bool) string { return "h3_h3_to_string(" + sql + ")" }, ToStructFieldSQL: func(sql string) string { return "h3_h3_to_string(" + sql + ")" }, OpenAPISchema: openapi3.NewStringSchema().WithFormat("h3string"), }, }
Functions ¶
func AddExtensions ¶
func AddExtensions(origin *ast.SchemaDocument, extension *ast.SchemaDocument) (*ast.Schema, error)
graphql extensions can contains new types and fields it can't add new directives to the existing types fields can have only additional join/function_call/table_function_call_join directives
func AggregatedObjectDef ¶
func AggregatedObjectDef(defs Definitions, def *ast.Definition) *ast.Definition
func AggregatedQueryDef ¶
func AggregatedQueryDef(field *ast.Field) *ast.FieldDefinition
func CompileExtension ¶ added in v0.1.12
func CompileExtension(schema *ast.Schema, extension *ast.SchemaDocument, opt Options) (*ast.Schema, *ast.SchemaDocument, []string, error)
CompileExtension validates the given extension schema document against the base schema. It checks for duplicate definitions, directive usage, and type compatibility. It returns the validated extension schema document, a list of depended catalogs, and an error if any validation fails.
func CompiledPosName ¶
func DataObjectType ¶
func DataObjectType(def *ast.Definition) string
func DirectiveArgChildValues ¶
func DirectiveArgValue ¶
func ExtractFieldsFromSQL ¶
func FlatQuery ¶ added in v0.1.18
func FlatQuery(queries []QueryRequest) map[string]QueryRequest
func HasSystemDirective ¶ added in v0.1.16
func HasSystemDirective(def ast.DirectiveList) bool
func IsAggregateQuery ¶
func IsAggregateQueryDefinition ¶ added in v0.1.18
func IsAggregateQueryDefinition(def *ast.FieldDefinition) bool
func IsBucketAggregateQuery ¶
func IsBucketAggregateQueryDefinition ¶ added in v0.1.18
func IsBucketAggregateQueryDefinition(def *ast.FieldDefinition) bool
func IsDataObject ¶
func IsDataObject(def *ast.Definition) bool
func IsDataObjectFieldDefinition ¶ added in v0.1.18
func IsDataObjectFieldDefinition(def *ast.FieldDefinition) bool
func IsDeleteQuery ¶
func IsDeleteQueryDefinition ¶ added in v0.1.18
func IsDeleteQueryDefinition(def *ast.FieldDefinition) bool
func IsEqualTypes ¶
func IsExtraField ¶
func IsExtraField(def *ast.FieldDefinition) bool
func IsFunction ¶
func IsFunction(field *ast.FieldDefinition) bool
func IsFunctionCall ¶
func IsFunctionCall(field *ast.FieldDefinition) bool
func IsFunctionCallQuery ¶
func IsFunctionCallSubquery ¶
func IsFunctionCallSubqueryDefinition ¶ added in v0.1.18
func IsFunctionCallSubqueryDefinition(def *ast.FieldDefinition) bool
func IsHyperTable ¶
func IsHyperTable(def *ast.Definition) bool
func IsInsertQuery ¶
func IsInsertQueryDefinition ¶ added in v0.1.18
func IsInsertQueryDefinition(def *ast.FieldDefinition) bool
func IsJSONType ¶
func IsJoinSubquery ¶
func IsJoinSubqueryDefinition ¶ added in v0.1.18
func IsJoinSubqueryDefinition(def *ast.FieldDefinition) bool
func IsNoJoinPushdown ¶ added in v0.1.20
func IsNoJoinPushdownDefinition ¶ added in v0.1.20
func IsNoJoinPushdownDefinition(def *ast.FieldDefinition) bool
func IsReferencesSubquery ¶
func IsReferencesSubquery(field *ast.FieldDefinition) bool
func IsScalarAggregationType ¶
func IsScalarType ¶
func IsSelectOneQuery ¶
func IsSelectOneQueryDefinition ¶ added in v0.1.18
func IsSelectOneQueryDefinition(def *ast.FieldDefinition) bool
func IsSelectQuery ¶
func IsSelectQueryDefinition ¶ added in v0.1.18
func IsSelectQueryDefinition(field *ast.FieldDefinition) bool
func IsSubQuery ¶
func IsSubQuery(field *ast.FieldDefinition) bool
func IsSystemType ¶
func IsSystemType(def *ast.Definition) bool
func IsTableFuncJoin ¶
func IsTableFuncJoin(field *ast.FieldDefinition) bool
func IsTableFuncJoinSubquery ¶
func IsTableFuncJoinSubqueryDefinition ¶ added in v0.1.18
func IsTableFuncJoinSubqueryDefinition(def *ast.FieldDefinition) bool
func IsTimescaleKey ¶
func IsTimescaleKey(def *ast.FieldDefinition) bool
func IsUpdateQuery ¶
func IsUpdateQueryDefinition ¶ added in v0.1.18
func IsUpdateQueryDefinition(def *ast.FieldDefinition) bool
func MergeSchema ¶
func MergeSchema(schemas ...*ast.Schema) (*ast.SchemaDocument, error)
MergeSchema merges the given schemas to one common schema. Not system type names should be unique, except module query/mutation root objects.
func ModuleTypeName ¶ added in v0.1.20
func ModuleTypeName(module string, objectType ModuleObjectType) string
func NewFunction ¶
func NewFunction(module, name, sql string, t *ast.Type, isTable, jsonCast bool, args ast.ArgumentDefinitionList, pos *ast.Position) *ast.FieldDefinition
func ObjectModule ¶ added in v0.1.20
func ObjectModule(def *ast.Definition) string
func ObjectMutationDefinition ¶ added in v0.1.18
func ObjectMutationDefinition(defs Definitions, def *ast.Definition, mutationType ObjectMutationType) (string, *ast.FieldDefinition)
func ObjectQueryDefinition ¶ added in v0.1.18
func ObjectQueryDefinition(defs Definitions, def *ast.Definition, queryType ObjectQueryType) (string, *ast.FieldDefinition)
func ObjectSQL ¶
func ObjectSQL(def *ast.Definition) string
func ParseArgumentValue ¶
func ParseArgumentValue(defs Definitions, arg *ast.ArgumentDefinition, value *ast.Value, vars map[string]any, checkRequired bool) (any, error)
func ParseDataAsInputObject ¶
func QueryRequestInfo ¶
func QueryRequestInfo(ss ast.SelectionSet) ([]QueryRequest, QueryType)
func RemoveFieldsDuplicates ¶
func SpecifiedByURL ¶
func SpecifiedByURL(def *ast.Definition) string
func TransformBaseFieldType ¶
func TransformBaseFieldType(field *ast.FieldDefinition) string
Types ¶
type Definitions ¶
type Definitions interface {
ForName(name string) *ast.Definition
}
type DefinitionsSource ¶
type DefinitionsSource interface { Definitions DirectiveForName(name string) *ast.DirectiveDefinition }
func SchemaDefs ¶
func SchemaDefs(schema *ast.Schema) DefinitionsSource
type Deprecated ¶
func EnumDeprecatedInfo ¶
func EnumDeprecatedInfo(def *ast.EnumValueDefinition) Deprecated
func FieldDeprecatedInfo ¶
func FieldDeprecatedInfo(def *ast.FieldDefinition) Deprecated
type Field ¶
type Field struct { Name string // contains filtered or unexported fields }
func (*Field) Definition ¶
func (f *Field) Definition() *ast.FieldDefinition
func (*Field) GeometrySRID ¶
func (*Field) IsCalcField ¶
func (*Field) IsGeometry ¶
func (*Field) IsNotDBField ¶
func (*Field) IsReferencesSubquery ¶
func (*Field) IsRequired ¶
func (*Field) IsTransformed ¶
func (*Field) SequenceName ¶
func (*Field) TransformSQL ¶
func (*Field) UsingFields ¶
extract using fields from sql query
type FieldQueryArguments ¶
type FieldQueryArguments []FieldQueryArgument
func ArgumentValues ¶
func ArgumentValues(defs Definitions, field *ast.Field, vars map[string]any, checkRequired bool) (FieldQueryArguments, error)
func (FieldQueryArguments) ForName ¶
func (a FieldQueryArguments) ForName(name string) *FieldQueryArgument
type Function ¶
type Function struct { Module string Catalog string Name string ReturnsTable bool JsonCast bool SkipNullArg bool // contains filtered or unexported fields }
func FunctionInfo ¶
func FunctionInfo(field *ast.FieldDefinition) (*Function, error)
func (*Function) ArgumentByName ¶
func (f *Function) ArgumentByName(name string) *ast.ArgumentDefinition
type FunctionCall ¶
type FunctionCall struct { IsTableFuncJoin bool // contains filtered or unexported fields }
func FunctionCallInfo ¶
func FunctionCallInfo(field *ast.Field) *FunctionCall
func (*FunctionCall) ArgumentMap ¶
func (f *FunctionCall) ArgumentMap() map[string]string
func (*FunctionCall) ArgumentValues ¶
func (f *FunctionCall) ArgumentValues(defs Definitions, vars map[string]any) (FieldQueryArguments, error)
func (*FunctionCall) FunctionInfo ¶
func (f *FunctionCall) FunctionInfo(defs Definitions) (*Function, error)
func (*FunctionCall) JoinConditionsTemplate ¶
func (f *FunctionCall) JoinConditionsTemplate() string
func (*FunctionCall) ReferencesFields ¶
func (f *FunctionCall) ReferencesFields() []string
func (*FunctionCall) SourceFields ¶
func (f *FunctionCall) SourceFields() ([]string, error)
type Join ¶
type Join struct { ReferencesName string SQL string IsQueryTime bool // contains filtered or unexported fields }
func (*Join) Catalog ¶
func (j *Join) Catalog(defs Definitions) string
func (*Join) JoinConditionsTemplate ¶
func (*Join) ReferencesFields ¶
func (*Join) SourceFields ¶
type ModuleObjectType ¶
type ModuleObjectType int
const ( ModuleQuery ModuleObjectType = iota + 1 ModuleMutation ModuleFunction ModuleMutationFunction )
type ModuleRoot ¶
type ModuleRoot struct { Name string Type ModuleObjectType }
func ModuleRootInfo ¶
func ModuleRootInfo(def *ast.Definition) *ModuleRoot
type Mutation ¶
type Mutation struct { ObjectName string Catalog string Type ObjectMutationType ObjectDefinition *ast.Definition // contains filtered or unexported fields }
func MutationInfo ¶
func MutationInfo(defs Definitions, query *ast.FieldDefinition) *Mutation
func (*Mutation) DBFieldName ¶
func (*Mutation) DefaultSequencesValues ¶
func (*Mutation) FieldDefinition ¶
func (m *Mutation) FieldDefinition(name string) *ast.FieldDefinition
func (*Mutation) M2MReferencesFields ¶
func (*Mutation) ReferencesFields ¶
func (Mutation) ReferencesFieldsReferences ¶
func (Mutation) ReferencesFieldsSource ¶
func (*Mutation) ReferencesMutation ¶
type Object ¶
type Object struct { Name string Type string Catalog string SoftDelete bool IsCube bool // contains filtered or unexported fields }
func DataObjectInfo ¶
func DataObjectInfo(def *ast.Definition) *Object
func (*Object) ApplyArguments ¶ added in v0.1.5
func (info *Object) ApplyArguments(defs Definitions, args map[string]any, builder sqlBuilder) (err error)
func (*Object) Definition ¶
func (info *Object) Definition() *ast.Definition
func (*Object) FieldForName ¶
func (*Object) HasArguments ¶ added in v0.1.5
func (*Object) InputFilterName ¶
func (*Object) InputInsertDataName ¶
func (*Object) M2MReferencesQueryInfo ¶
func (info *Object) M2MReferencesQueryInfo(defs Definitions, name string) *References
func (*Object) ReferencesQueryInfo ¶
func (info *Object) ReferencesQueryInfo(defs Definitions, name string) *References
func (*Object) ReferencesQueryInfoByName ¶
func (info *Object) ReferencesQueryInfoByName(defs Definitions, name string) *References
func (*Object) SoftDeleteCondition ¶
func (*Object) SoftDeleteSet ¶
type ObjectMutationType ¶
type ObjectMutationType int
const ( MutationTypeInsert ObjectMutationType = iota MutationTypeUpdate MutationTypeDelete )
type ObjectQueryType ¶
type ObjectQueryType int
const ( QueryTypeSelect ObjectQueryType = iota QueryTypeSelectOne QueryTypeAggregate QueryTypeAggregateBucket SubQueryTypeReferencesData SubQueryTypeJoinData SubQueryTypeFunctionCallData SubQueryTypeFunctionCallTableJoinData )
type QueryRequest ¶
type References ¶
type References struct { Name string ReferencesName string Query string Description string ReferencesQuery string ReferencesDescription string IsM2M bool M2MName string // contains filtered or unexported fields }
func FieldReferencesInfo ¶
func FieldReferencesInfo(defs Definitions, def *ast.Definition, field *ast.FieldDefinition) *References
func ReferencesInfo ¶
func ReferencesInfo(def *ast.Directive) *References
func (*References) FromM2MJoinConditions ¶
func (info *References) FromM2MJoinConditions(defs Definitions, m2mAlias, rightAlias string, isDBLeft, isDBRight bool) (string, error)
func (*References) JoinConditions ¶
func (info *References) JoinConditions(defs Definitions, leftAlias, rightAlias string, isDBLeft, isDBRight bool) (string, error)
func (*References) ReferencesFields ¶
func (info *References) ReferencesFields() []string
func (*References) ReferencesObjectDef ¶
func (info *References) ReferencesObjectDef(defs Definitions) *ast.Definition
func (*References) SourceFields ¶
func (info *References) SourceFields() []string
func (*References) ToM2MJoinConditions ¶
func (info *References) ToM2MJoinConditions(defs Definitions, leftAlias, m2mAlias string, isDBLeft, isDBRight bool) (string, error)
type ScalarType ¶
type ScalarType struct { Name string Description string Arguments ast.ArgumentDefinitionList ExtraField func(field *ast.FieldDefinition) *ast.FieldDefinition JSONType string JSONToStructType string JSONNativeType string // ToOutputType converts SQL string to output type. ToOutputTypeSQL func(sql string, raw bool) string ToStructFieldSQL func(sql string) string FilterInput string ListFilterInput string ParseValue func(value any) (any, error) ParseArray func(value any) (any, error) AggType string MeasurementAggs string OpenAPISchema *openapi3.Schema }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.