Documentation
¶
Overview ¶
Package compile turns one validated GraphQL root field into exactly one parameterized SQL statement, PostGraphile-style: nested selections become jsonb_build_object trees, relations become LEFT JOIN LATERAL subqueries, lists become jsonb_agg — so the database returns the response JSON directly and there is no N+1 problem to paper over.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoerceInput ¶ added in v0.1.1
CoerceInput converts a GraphQL input value into a driver-friendly parameter for the given column — enum value names map to their PostgreSQL labels, json/jsonb values are re-encoded as text, array elements coerce recursively. CompileHook plugins building their own DML must route column values through this before ParamSet.Add, or enum/jsonb params reach the driver raw.
func QuoteIdent ¶
QuoteIdent is exported for plugins building SQL fragments.
func TableRefSQL ¶
TableRefSQL renders a quoted schema-qualified relation reference.
Types ¶
type Compiler ¶
Compiler compiles GraphQL fields against a built schema.
func (*Compiler) MutationWithCTEs ¶
func (c *Compiler) MutationWithCTEs(req *Request, f *ast.Field, meta *schema.FieldMeta, ctes string, ps *ParamSet, overrides map[string]string) (*Statement, error)
MutationWithCTEs compiles the payload selection of a mutation root field against a caller-supplied CTE chain. The chain's final CTE must be named __mut and yield the mutated row(s); params created via ps are preserved and the payload's own params continue after them. This is the extension point CompileHook plugins (e.g. nested-mutations) use to replace the DML while reusing payload/relation compilation. overrides remaps "schema.table" row sources to CTE names so the payload can see rows inserted by the supplied CTEs (same-snapshot rule).
type ParamSet ¶
type ParamSet struct {
// contains filtered or unexported fields
}
ParamSet lets CompileHook plugins build parameterized SQL fragments whose placeholder numbering composes with the core compiler.
type Request ¶
type Request struct {
Field *ast.Field
Fragments ast.FragmentDefinitionList
Vars map[string]any
Built *schema.Built
MaxDepth int
// MaxPageSize caps first/last and is the default page size when neither
// is given. Values <= 0 fall back to defaultMaxPageSize.
MaxPageSize int
}
Request is one root field to compile.
type Statement ¶
type Statement struct {
SQL string
Args []any
// ReturnsRow is false when zero rows means null (single lookups).
Mutation bool
}
Statement is a single executable SQL statement. The statement always returns a single row with a single jsonb column named "data" (possibly zero rows for missed single-row lookups).