Documentation
¶
Index ¶
- func BuildHandler(db *pgxpool.Pool, schemaName string, ps *ParsedSchema, ...) (http.Handler, error)
- func CreateTable(ctx context.Context, db *pgxpool.Pool, schemaName string, t TypeDef, ...) error
- func MaxDepthFromEnv() int
- type FieldDef
- type ParsedSchema
- type Schema
- type Store
- type TypeDef
- type ValidationDetail
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildHandler ¶
func BuildHandler(db *pgxpool.Pool, schemaName string, ps *ParsedSchema, scalars map[string]scalar.Plugin, modifiers []plugin.QueryModifier, filters []plugin.FilterPlugin, maxDepth int) (http.Handler, error)
BuildHandler creates an HTTP handler that serves GraphQL for the given schema. It builds a dynamic graphql-go schema with Query (list, get) and Mutation (create) per type. Relation fields are resolved by loading the referenced record from the DB.
func CreateTable ¶
func CreateTable(ctx context.Context, db *pgxpool.Pool, schemaName string, t TypeDef, scalars map[string]scalar.Plugin) error
CreateTable creates a PostgreSQL table for the given TypeDef. Table name convention: {schemaName}_{typeName_lowercase}. The "id" field is always TEXT PRIMARY KEY regardless of its SDL scalar. Relation fields produce a FK column: {snake_field_name}_id TEXT [NOT NULL] REFERENCES {schemaName}_{referencedType}(id).
func MaxDepthFromEnv ¶
func MaxDepthFromEnv() int
MaxDepthFromEnv reads the max relation depth from the STRATUM_MAX_DEPTH environment variable.
Types ¶
type FieldDef ¶
type FieldDef struct {
Name string
Type string // SDL scalar name or referenced type name for relations.
NonNull bool
IsRelation bool // true when Type refers to another object type.
IsList bool // true for list relations [OtherType] (1:N).
}
FieldDef represents a single field within an object type.
type ParsedSchema ¶
type ParsedSchema struct {
Types []TypeDef
}
ParsedSchema is the result of parsing a GraphQL SDL string.
func ParseSDL ¶
func ParseSDL(sdl string) (*ParsedSchema, error)
ParseSDL parses a GraphQL SDL string and extracts user-defined object types. Fields whose type refers to another object type in the same schema are marked as relations (IsRelation = true). The returned types are topologically sorted so that referenced types appear before the types that reference them. Returns an error if the SDL is invalid or defines no object types.
type Schema ¶
type Schema struct {
Name string
SDL string
Parsed *ParsedSchema
Version int
CreatedAt time.Time
UpdatedAt time.Time
Handler http.Handler
}
Schema is a stored, live schema with its metadata and active GraphQL handler.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory registry of live schemas.
type ValidationDetail ¶
type ValidationError ¶
type ValidationError struct {
Msg string
Details []ValidationDetail
// contains filtered or unexported fields
}
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error