Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateTableRefSDL(schemaName string, ref catalog.TableRef, opts ...SchemaOption) string
- func GenerateTableSDL(schemaName string, table catalog.Table, opts ...SchemaOption) string
- func IsKnownArgPlaceholder(p ContextPlaceholder) bool
- func ToGraphQLName(name string) string
- func ValidGraphQLName(name string) bool
- func WithSDL(table catalog.Table, sdl string) catalog.Table
- func WithScalarFuncSDL(fn catalog.ScalarFunction, sdl string) catalog.ScalarFunction
- func WithTableFuncInOutSDL(fn catalog.TableFunctionInOut, sdl string) catalog.TableFunctionInOut
- func WithTableFuncSDL(fn catalog.TableFunction, sdl string) catalog.TableFunction
- func WithTableRefSDL(ref catalog.TableRef, sdl string) catalog.TableRef
- type AppInfo
- type Application
- type ApplicationDBInitializer
- type ApplicationDBMigrator
- type CatalogMux
- func (m *CatalogMux) HandleFunc(schema, name string, handler HandlerFunc, opts ...Option) error
- func (m *CatalogMux) HandleTableFunc(schema, name string, handler HandlerFunc, opts ...Option) error
- func (m *CatalogMux) SDL() string
- func (m *CatalogMux) ScalarFunc(schema string, fn catalog.ScalarFunction)
- func (m *CatalogMux) Schema(ctx context.Context, name string) (catalog.Schema, error)
- func (m *CatalogMux) Schemas(ctx context.Context) ([]catalog.Schema, error)
- func (m *CatalogMux) Table(schema string, table catalog.Table, opts ...SchemaOption)
- func (m *CatalogMux) TableFunc(schema string, fn catalog.TableFunction)
- func (m *CatalogMux) TableFuncInOut(schema string, fn catalog.TableFunctionInOut)
- func (m *CatalogMux) TableRef(schema string, ref catalog.TableRef, opts ...SchemaOption)
- func (m *CatalogMux) WithSDL(sdl string)
- type ContextPlaceholder
- type DataSourceInfo
- type DataSourceUser
- type HandlerFunc
- type MultiCatalogMux
- type MultiCatalogProvider
- type Option
- func Arg(name string, typ Type) Option
- func ArgDesc(name string, typ Type, description string) Option
- func ArgFromContext(name string, typ Type, placeholder ContextPlaceholder) Option
- func Col(name string, typ Type) Option
- func ColDesc(name string, typ Type, description string) Option
- func ColNullable(name string, typ Type) Option
- func ColPK(name string, typ Type) Option
- func Desc(description string) Option
- func Mutation() Option
- func Return(typ Type) Option
- func ReturnList(typ Type) Option
- type Request
- func (r *Request) Bool(name string) bool
- func (r *Request) Bytes(name string) []byte
- func (r *Request) Context() context.Context
- func (r *Request) Float32(name string) float32
- func (r *Request) Float64(name string) float64
- func (r *Request) Geometry(name string) orb.Geometry
- func (r *Request) Get(name string) any
- func (r *Request) Int8(name string) int8
- func (r *Request) Int16(name string) int16
- func (r *Request) Int32(name string) int32
- func (r *Request) Int64(name string) int64
- func (r *Request) JSON(name string, out any) error
- func (r *Request) String(name string) string
- func (r *Request) Uint8(name string) uint8
- func (r *Request) Uint16(name string) uint16
- func (r *Request) Uint32(name string) uint32
- func (r *Request) Uint64(name string) uint64
- type Result
- type SchemaOption
- func WithDescription(desc string) SchemaOption
- func WithFieldDescription(field, desc string) SchemaOption
- func WithFieldReferences(fieldName, referencesName, query, referencesQuery string) SchemaOption
- func WithFilterRequired(fields ...string) SchemaOption
- func WithM2M() SchemaOption
- func WithM2MReferences(referencesName string, sourceFields, referencesFields []string, ...) SchemaOption
- func WithPK(fields ...string) SchemaOption
- func WithRawSDL(sdl string) SchemaOption
- func WithReferences(referencesName string, sourceFields, referencesFields []string, ...) SchemaOption
- type StructKind
- type StructType
- func (s *StructType) AsType() Type
- func (s *StructType) Desc(description string) *StructType
- func (s *StructType) Field(name string, typ Type) *StructType
- func (s *StructType) FieldDesc(name string, typ Type, description string) *StructType
- func (s *StructType) FieldFromSource(name string, typ Type, originalName string) *StructType
- func (s *StructType) FieldList(name string, typ Type) *StructType
- func (s *StructType) FieldNullable(name string, typ Type) *StructType
- type TLSConfigProvider
- type Type
Constants ¶
const DefaultSchema = "default"
DefaultSchema is the fixed schema name treated as root level (no @module directive). All other schema names become nested modules.
Variables ¶
var ( Boolean = Type{/* contains filtered or unexported fields */} Int8 = Type{/* contains filtered or unexported fields */} Int16 = Type{/* contains filtered or unexported fields */} Int32 = Type{/* contains filtered or unexported fields */} Int64 = Type{/* contains filtered or unexported fields */} Uint8 = Type{/* contains filtered or unexported fields */} Uint16 = Type{/* contains filtered or unexported fields */} Uint32 = Type{/* contains filtered or unexported fields */} Uint64 = Type{/* contains filtered or unexported fields */} Float32 = Type{/* contains filtered or unexported fields */} Float64 = Type{/* contains filtered or unexported fields */} String = Type{/* contains filtered or unexported fields */} Binary = Type{/* contains filtered or unexported fields */} Timestamp = Type{/* contains filtered or unexported fields */} Date = Type{/* contains filtered or unexported fields */} Geometry = Type{/* contains filtered or unexported fields */} // JSON is the raw JSON scalar type. The wire representation is a string; // the handler is responsible for json.Marshal / json.Unmarshal of complex // values. In the public GraphQL schema this is the JSON scalar — clients // receive the raw JSON value. JSON = Type{/* contains filtered or unexported fields */} )
Arrow type references — use these in Arg(), Return(), Col() options.
var ReservedSchemas = map[string]bool{ "_mount": true, "_funcs": true, }
ReservedSchemas that cannot be used by app developers.
Functions ¶
func GenerateTableRefSDL ¶
func GenerateTableRefSDL(schemaName string, ref catalog.TableRef, opts ...SchemaOption) string
GenerateTableRefSDL generates SDL for a catalog.TableRef from its Arrow schema. Table refs are always @view (read-only). If WithRawSDL is provided, returns that SDL directly.
func GenerateTableSDL ¶
func GenerateTableSDL(schemaName string, table catalog.Table, opts ...SchemaOption) string
GenerateTableSDL generates SDL for a catalog.Table from its Arrow schema. Mutable tables get @table, read-only tables get @view. If WithRawSDL is provided, returns that SDL directly.
func IsKnownArgPlaceholder ¶ added in v0.3.24
func IsKnownArgPlaceholder(p ContextPlaceholder) bool
IsKnownArgPlaceholder reports whether the given context placeholder is in the recognized whitelist for app.ArgFromContext.
func ToGraphQLName ¶
ToGraphQLName transforms a string into a valid GraphQL identifier. Replaces invalid characters with underscores, prepends _ if starts with digit.
func ValidGraphQLName ¶
ValidGraphQLName returns true if name is a valid GraphQL identifier.
func WithScalarFuncSDL ¶
func WithScalarFuncSDL(fn catalog.ScalarFunction, sdl string) catalog.ScalarFunction
WithScalarFuncSDL wraps a catalog.ScalarFunction with its hugr SDL definition.
func WithTableFuncInOutSDL ¶
func WithTableFuncInOutSDL(fn catalog.TableFunctionInOut, sdl string) catalog.TableFunctionInOut
WithTableFuncInOutSDL wraps a catalog.TableFunctionInOut with its hugr SDL definition.
func WithTableFuncSDL ¶
func WithTableFuncSDL(fn catalog.TableFunction, sdl string) catalog.TableFunction
WithTableFuncSDL wraps a catalog.TableFunction with its hugr SDL definition.
Types ¶
type Application ¶
type Application interface {
Listner() (net.Listener, error)
Info() AppInfo
Catalog(ctx context.Context) (catalog.Catalog, error)
// Init is called during server startup to perform any necessary initialization.
// This performs after registering the application data sources on the hugr side.
// This will be called by the Hugr server
Init(ctx context.Context) error
// Shutdown is called during graceful shutdown to clean up resources.
// Called before unregistering from hugr.
Shutdown(ctx context.Context) error
}
type ApplicationDBMigrator ¶
type CatalogMux ¶
type CatalogMux struct {
// contains filtered or unexported fields
}
CatalogMux is a goroutine-safe catalog multiplexer. Like http.ServeMux routes URLs to handlers, CatalogMux routes schema+name pairs to functions, tables, and table references.
The catalog is static once built — SDL does not change at runtime. For dynamic multi-catalog scenarios, see MultiCatalogProvider in client/apps.
Thread safety: read methods (Schemas, Schema, SDL) and the direct registration methods (ScalarFunc, TableFunc, Table, TableRef, ...) are safe for concurrent use. The higher-level registration helpers HandleFunc and HandleTableFunc additionally update the shared struct-type registry and are **not** goroutine-safe among themselves: build the catalog from a single goroutine (typically Application.Catalog), then publish it. After the catalog is handed to the runtime, all subsequent reads are safe for any number of goroutines.
func (*CatalogMux) HandleFunc ¶
func (m *CatalogMux) HandleFunc(schema, name string, handler HandlerFunc, opts ...Option) error
HandleFunc registers a Go function as a scalar function. The handler is called once per row with typed arguments via Request. Options declare arguments and return type: Arg(), Return().
mux.HandleFunc("math", "add", func(w *app.Result, r *app.Request) error {
return w.Set(r.Int64("a") + r.Int64("b"))
}, app.Arg("a", app.Int64), app.Arg("b", app.Int64), app.Return(app.Int64))
func (*CatalogMux) HandleTableFunc ¶
func (m *CatalogMux) HandleTableFunc(schema, name string, handler HandlerFunc, opts ...Option) error
HandleTableFunc registers a Go function as a table function. The handler is called once and writes rows via Result.Append(). Options declare arguments and result columns: Arg(), Col(), ColPK(), ColNullable().
mux.HandleTableFunc("users", "search", func(w *app.Result, r *app.Request) error {
w.Append(int64(1), "Alice")
return nil
}, app.Arg("query", app.String), app.ColPK("id", app.Int64), app.Col("name", app.String))
func (*CatalogMux) SDL ¶
func (m *CatalogMux) SDL() string
SDL returns the full GraphQL SDL for the catalog. If WithSDL was called, returns that string. Otherwise collects SDL from all registered items across non-system schemas. Objects from the default schema have no @module directive; objects from named schemas get @module(name) injected per-definition during SDL generation (see schemaModuleName in sdl_gen.go). System schemas (_mount, _funcs) are excluded.
func (*CatalogMux) ScalarFunc ¶
func (m *CatalogMux) ScalarFunc(schema string, fn catalog.ScalarFunction)
ScalarFunc registers a catalog.ScalarFunction directly.
func (*CatalogMux) Table ¶
func (m *CatalogMux) Table(schema string, table catalog.Table, opts ...SchemaOption)
Table registers a catalog.Table directly. If the table doesn't have SDL attached (via WithSDL), SDL is auto-generated from the Arrow schema. Mutable tables → @table, read-only → @view. SchemaOptions configure PK, references, field_references, etc.
func (*CatalogMux) TableFunc ¶
func (m *CatalogMux) TableFunc(schema string, fn catalog.TableFunction)
TableFunc registers a catalog.TableFunction directly.
func (*CatalogMux) TableFuncInOut ¶
func (m *CatalogMux) TableFuncInOut(schema string, fn catalog.TableFunctionInOut)
TableFuncInOut registers a catalog.TableFunctionInOut directly.
func (*CatalogMux) TableRef ¶
func (m *CatalogMux) TableRef(schema string, ref catalog.TableRef, opts ...SchemaOption)
TableRef registers a catalog.TableRef in the given schema. If the ref doesn't have SDL attached (via WithTableRefSDL), SDL is auto-generated from the Arrow schema as a @view. SchemaOptions configure PK, references, field_references, etc.
func (*CatalogMux) WithSDL ¶
func (m *CatalogMux) WithSDL(sdl string)
WithSDL sets a raw SDL string that overrides all auto-generated SDL. When set, SDL() returns this string instead of collecting from registered items.
type ContextPlaceholder ¶ added in v0.3.24
type ContextPlaceholder string
ContextPlaceholder is a typed wrapper for server-side context placeholders used with app.ArgFromContext. Use the predefined constants below — passing a string that isn't in the recognized whitelist will fail at registration.
const ( // AuthUserID — current user's ID as a string. AuthUserID ContextPlaceholder = "[$auth.user_id]" // AuthUserIDInt — current user's ID parsed as integer. AuthUserIDInt ContextPlaceholder = "[$auth.user_id_int]" // AuthUserName — current user's display name. AuthUserName ContextPlaceholder = "[$auth.user_name]" // AuthRole — current authenticated role. AuthRole ContextPlaceholder = "[$auth.role]" // AuthType — auth method (e.g. "apiKey", "jwt", "oidc", "impersonation"). AuthType ContextPlaceholder = "[$auth.auth_type]" // AuthProvider — auth provider name. AuthProvider ContextPlaceholder = "[$auth.provider]" // AuthImpersonatedByRole — original role when impersonating. AuthImpersonatedByRole ContextPlaceholder = "[$auth.impersonated_by_role]" // AuthImpersonatedByUserID — original user ID when impersonating. AuthImpersonatedByUserID ContextPlaceholder = "[$auth.impersonated_by_user_id]" // AuthImpersonatedByUserName — original user name when impersonating. AuthImpersonatedByUserName ContextPlaceholder = "[$auth.impersonated_by_user_name]" )
Recognized context placeholders. The hugr planner resolves these via perm.AuthVars(ctx) at request time. When the underlying value is unavailable (e.g. unauthenticated request), the planner substitutes NULL.
This list mirrors pkg/catalog/sdl/placeholders.go on the server side; keep them in sync.
type DataSourceInfo ¶
type DataSourceUser ¶
type DataSourceUser interface {
Application
DataSources(ctx context.Context) ([]DataSourceInfo, error)
}
type HandlerFunc ¶
HandlerFunc is the function signature for scalar and table function handlers.
type MultiCatalogMux ¶
type MultiCatalogProvider ¶
type MultiCatalogProvider interface {
SetMultiCatalogMux(mux MultiCatalogMux)
InitMultiCatalog(ctx context.Context) error
}
type Option ¶
type Option func(*funcDef)
Option configures function registration.
func ArgFromContext ¶ added in v0.3.24
func ArgFromContext(name string, typ Type, placeholder ContextPlaceholder) Option
ArgFromContext declares a function argument whose value is server-injected from a context placeholder. The argument is hidden from the GraphQL schema — clients cannot pass a value for it. At handler execution time, read it via Request.String(name), Request.Int64(name), etc., the same as a regular argument.
Use the predefined ContextPlaceholder constants (AuthUserID, AuthRole, etc.). Passing an unknown placeholder fails at registration time.
Example:
mux.HandleFunc("default", "my_orders", handler,
app.Arg("limit", app.Int64),
app.ArgFromContext("user_id", app.String, app.AuthUserID),
app.Return(app.String),
)
func ColNullable ¶
ColNullable declares a nullable result column for a table function.
func Mutation ¶ added in v0.3.23
func Mutation() Option
Mutation marks a scalar function as a mutation. The generated SDL will extend MutationFunction instead of Function, exposing the function as a GraphQL mutation operation rather than a query.
func ReturnList ¶ added in v0.3.24
ReturnList declares that the scalar function returns a list of the given scalar element type (e.g. ReturnList(app.String) → [String!]).
The wire format is a native Arrow LIST of the element's underlying type (NOT JSON), so DuckDB receives a proper LIST value and the planner does not need json_cast. The handler returns a Go slice via Set.
ReturnList does NOT support struct element types — for lists of structs, register the function as a table function via HandleTableFunc instead. Passing a struct type sets a registration error that fails registration.
The generated SDL preserves the scalar-return convention (outer-nullable, element-non-null): `[String!]`.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request provides typed access to function arguments.
func (*Request) JSON ¶ added in v0.3.24
JSON unmarshals the named argument's JSON string value into out. Use this for arguments declared with Arg(name, JSON) or Arg(name, struct.AsType()), where the planner inlines the GraphQL input value as a JSON literal that arrives at the handler as a string.
Returns nil (no-op) if the argument is empty.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result writes function output. For scalar functions, use Set() to write the return value. For table functions, use Append() to write rows.
func (*Result) Append ¶
Append writes a row to a table function result. Values must match the column order from Col() options.
func (*Result) SetJSON ¶ added in v0.3.24
SetJSON marshals the value to a JSON string and stores it as the scalar return. Use this when the function's Return type is JSON or a struct (via Struct().AsType()).
Returns an error if the function's return type is not JSON-compatible (including when called on a table function).
func (*Result) SetJSONValue ¶ added in v0.3.24
SetJSONValue is the most flexible JSON setter. It accepts:
- string: stored as-is (assumed valid JSON)
- []byte: stored as string(b) (assumed valid JSON)
- any other value: marshaled via json.Marshal
Returns an error if the function's return type is not JSON-compatible (including when called on a table function).
type SchemaOption ¶
type SchemaOption func(*schemaDef)
SchemaOption configures SDL generation for tables, table functions, and table refs.
func WithDescription ¶
func WithDescription(desc string) SchemaOption
WithDescription sets the description for the table/view/function type.
func WithFieldDescription ¶
func WithFieldDescription(field, desc string) SchemaOption
WithFieldDescription sets the description for a specific field.
func WithFieldReferences ¶
func WithFieldReferences(fieldName, referencesName, query, referencesQuery string) SchemaOption
WithFieldReferences adds a field-level @field_references directive.
func WithFilterRequired ¶
func WithFilterRequired(fields ...string) SchemaOption
WithFilterRequired marks fields as requiring a filter when queried.
func WithM2M ¶
func WithM2M() SchemaOption
WithM2M marks the table as a many-to-many junction table.
func WithM2MReferences ¶
func WithM2MReferences(referencesName string, sourceFields, referencesFields []string, query, referencesQuery, m2mName string) SchemaOption
WithM2MReferences adds an object-level @references directive with is_m2m flag.
func WithPK ¶
func WithPK(fields ...string) SchemaOption
WithPK marks fields as primary key. Multiple calls or multiple names for composite PK.
func WithRawSDL ¶
func WithRawSDL(sdl string) SchemaOption
WithRawSDL provides user-written SDL directly, skipping auto-generation.
func WithReferences ¶
func WithReferences(referencesName string, sourceFields, referencesFields []string, query, referencesQuery string) SchemaOption
WithReferences adds an object-level @references directive.
type StructKind ¶ added in v0.3.24
type StructKind int
StructKind selects whether the struct is used as an output type (GraphQL OBJECT) or as an input type (GraphQL INPUT_OBJECT).
const ( // StructKindOutput produces a GraphQL Object type used as a function return. StructKindOutput StructKind = iota // StructKindInput produces a GraphQL InputObject type used as a function argument. StructKindInput )
type StructType ¶ added in v0.3.24
type StructType struct {
// contains filtered or unexported fields
}
StructType describes a custom GraphQL struct type generated by the SDK SDL builder. Use Struct or InputStruct to start a builder, add fields, then call AsType to convert it into a Type usable with Return / Arg.
The wire representation is a JSON string. The hugr planner inlines complex argument values automatically; for return values the SDL emits @function (json_cast: true) so the planner casts the JSON output to the structured type before returning to the client.
func InputStruct ¶ added in v0.3.24
func InputStruct(name string) *StructType
InputStruct begins building an input struct (GraphQL InputObject type).
func Struct ¶ added in v0.3.24
func Struct(name string) *StructType
Struct begins building an output struct (GraphQL Object type). The returned builder is mutable; chain Field/Desc/etc. and finish with AsType.
func (*StructType) AsType ¶ added in v0.3.24
func (s *StructType) AsType() Type
AsType converts the struct definition into a Type usable with Return / Arg. The wire dt is arrow.BinaryTypes.String (JSON wire format); the GraphQL type name is the struct's name. The structDef back-pointer enables the SDL generator to emit the type definition alongside the function field.
func (*StructType) Desc ¶ added in v0.3.24
func (s *StructType) Desc(description string) *StructType
Desc sets the GraphQL doc description for the type.
func (*StructType) Field ¶ added in v0.3.24
func (s *StructType) Field(name string, typ Type) *StructType
Field adds a non-null field of the given type. The type may be a scalar (e.g. app.String, app.Int64) or another struct via its AsType() method (the JSON wire format handles nesting).
func (*StructType) FieldDesc ¶ added in v0.3.24
func (s *StructType) FieldDesc(name string, typ Type, description string) *StructType
FieldDesc adds a non-null field with a description.
func (*StructType) FieldFromSource ¶ added in v0.3.24
func (s *StructType) FieldFromSource(name string, typ Type, originalName string) *StructType
FieldFromSource adds a non-null field whose underlying JSON key differs from the GraphQL name. The generated SDL emits a @field_source(field: "<originalName>") directive so the planner extracts the value from the underlying JSON correctly.
Only valid on output structs. Panics if called on an input struct (caught at builder time as a programmer error).
func (*StructType) FieldList ¶ added in v0.3.24
func (s *StructType) FieldList(name string, typ Type) *StructType
FieldList adds a non-null list field ([Type!]!). The element type may be any scalar or struct — JSON serialization handles nested arrays naturally.
func (*StructType) FieldNullable ¶ added in v0.3.24
func (s *StructType) FieldNullable(name string, typ Type) *StructType
FieldNullable adds a nullable field of the given type.
type TLSConfigProvider ¶
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type wraps an arrow.DataType with a GraphQL type name for SDL generation. When structDef is non-nil, the type represents a custom struct that the SDL generator emits as a separate type definition; the wire representation is a JSON string (arrow.BinaryTypes.String).