Documentation
¶
Overview ¶
Package serv provides an API to include and use the GraphJin service with your own code. For detailed documentation visit https://graphjin.com
Example usage:
package main
import (
"database/sql"
"fmt"
"github.com/aegion-dynamic/graphjin-slim/core/v3"
_ "github.com/jackc/pgx/v5/stdlib"
)
func main() {
conf := serv.Config{ AppName: "Test App" }
conf.DB.Host := "127.0.0.1"
conf.DB.Port := 5432
conf.DB.DBName := "test_db"
conf.DB.User := "postgres"
conf.DB.Password := "postgres"
gjs, err := serv.NewGraphJinService(conf)
if err != nil {
log.Fatal(err)
}
if err := gjs.Start(); err != nil {
log.Fatal(err)
}
}
Index ¶
- Variables
- func GetConfigName() string
- func NewDB(conf *Config, openDB bool, log *zap.SugaredLogger, fs core.FS) (*sql.DB, error)
- type CachingConfig
- type Config
- type Core
- type Database
- type HandlerFunc
- type HookFn
- type HttpService
- func (s *HttpService) Attach(mux Mux) error
- func (s *HttpService) AttachWithNS(mux Mux, namespace string) error
- func (s *HttpService) Close() error
- func (s *HttpService) Deploy(conf *Config, options ...Option) error
- func (s *HttpService) GetDB() *sql.DB
- func (s *HttpService) GetGraphJin() *core.GraphJin
- func (s *HttpService) GraphQL(ah HandlerFunc) http.Handler
- func (s *HttpService) GraphQLWithNS(ah HandlerFunc, ns string) http.Handler
- func (s *HttpService) ModuleRoutes() []module.Route
- func (s *HttpService) REST(ah HandlerFunc) http.Handler
- func (s *HttpService) RESTWithNS(ah HandlerFunc, ns string) http.Handler
- func (s *HttpService) Reload() error
- func (s *HttpService) Shutdown(ctx context.Context) error
- func (s *HttpService) Start() error
- type KeystoreConfig
- type Mux
- type Option
- func OptionDisableQueryLearning() Option
- func OptionSetDB(db *sql.DB) Option
- func OptionSetDatabases(dbs map[string]*sql.DB) Option
- func OptionSetFS(fs core.FS) Option
- func OptionSetHookFunc(fn HookFn) Option
- func OptionSetLogOutput(output zapcore.WriteSyncer) Option
- func OptionSetModule(mods ...module.Module) Option
- func OptionSetMutationHook(h core.MutationHook) Option
- func OptionSetNamespace(namespace string) Option
- func OptionSetQueryPolicyHook(h core.QueryPolicyHook) Option
- func OptionSetRuntimeSchemaDDLDir(dir string) Option
- func OptionSetZapLogger(zlog *zap.Logger) Option
- type RateLimiter
- type RedisConfig
- type SecretsConfig
- type Serv
Constants ¶
This section is empty.
Variables ¶
var ErrGraphJinNotInitialized = errors.New("GraphJin not initialized - no database configured")
ErrGraphJinNotInitialized is returned when GraphJin core is not initialized
Functions ¶
Types ¶
type CachingConfig ¶
type CachingConfig struct{}
CachingConfig is a placeholder; response caching is not part of slim.
type Config ¶
type Config struct {
// Configuration for the GraphJin compiler core
Core `mapstructure:",squash" jsonschema:"title=Compiler Configuration"`
// Configuration for the GraphJin Service
Serv `mapstructure:",squash" jsonschema:"title=Service Configuration"`
// Name of another config file in the same directory to inherit and
// override (one level only; the inherited file cannot itself inherit).
Inherits string `mapstructure:"inherits" jsonschema:"title=Inherit From Config File"`
// contains filtered or unexported fields
}
Configuration for the GraphJin service
func ReadInConfig ¶
ReadInConfig reads the config file for the environment.
func ReadInConfigFS ¶
ReadInConfigFS is the same as ReadInConfig but with a filesystem argument.
func (*Config) AbsolutePath ¶
AbsolutePath returns the absolute path of the file.
func (*Config) ShouldUseJSONLogs ¶
ShouldUseJSONLogs returns true if logs should be in JSON format.
type HandlerFunc ¶
HandlerFunc is the signature for auth handler functions that run before each request. In the slim build, auth is handled externally by the caller.
type HttpService ¶
func NewGraphJinService ¶
func NewGraphJinService(conf *Config, options ...Option) (*HttpService, error)
NewGraphJinService a new service
func (*HttpService) Attach ¶
func (s *HttpService) Attach(mux Mux) error
Attach route to the internal http service
func (*HttpService) AttachWithNS ¶
func (s *HttpService) AttachWithNS(mux Mux, namespace string) error
AttachWithNS a namespaced route to the internal http service
func (*HttpService) Close ¶
func (s *HttpService) Close() error
Close shuts down the in-process service resources owned by HttpService. It is useful for embedded use and tests that do not call Start().
func (*HttpService) Deploy ¶
func (s *HttpService) Deploy(conf *Config, options ...Option) error
Deploy a new configuration
func (*HttpService) GetDB ¶
func (s *HttpService) GetDB() *sql.DB
GetDB fetching internal db client (returns any connection from the pool)
func (*HttpService) GetGraphJin ¶
func (s *HttpService) GetGraphJin() *core.GraphJin
GetGraphJin fetching internal GraphJin core
func (*HttpService) GraphQL ¶
func (s *HttpService) GraphQL(ah HandlerFunc) http.Handler
GraphQLis the http handler the GraphQL endpoint
func (*HttpService) GraphQLWithNS ¶
func (s *HttpService) GraphQLWithNS(ah HandlerFunc, ns string) http.Handler
GraphQLWithNS is the http handler the namespaced GraphQL endpoint
func (*HttpService) ModuleRoutes ¶ added in v3.35.0
func (s *HttpService) ModuleRoutes() []module.Route
ModuleRoutes returns the HTTP routes contributed by mounted modules. Applications attaching the service to their own mux can register these alongside the standard endpoints.
func (*HttpService) REST ¶
func (s *HttpService) REST(ah HandlerFunc) http.Handler
REST is the http handler the REST endpoint
func (*HttpService) RESTWithNS ¶
func (s *HttpService) RESTWithNS(ah HandlerFunc, ns string) http.Handler
RESTWithNS is the http handler the namespaced REST endpoint
func (*HttpService) Reload ¶
func (s *HttpService) Reload() error
Reload re-runs database discover and reinitializes service.
func (*HttpService) Shutdown ¶
func (s *HttpService) Shutdown(ctx context.Context) error
Shutdown gracefully stops the running HTTP server so that a blocking Start returns. In-flight requests are drained until the context deadline, after which the server is force-closed. It is safe to call more than once and before Start (a no-op when the server was never started). Callers that embed the service and run their own signal handling use this to unblock Start; the service resources (databases, cache, etc.) are then released as Start returns, or explicitly via Close.
func (*HttpService) Start ¶
func (s *HttpService) Start() error
Start the service listening on the configured port
type KeystoreConfig ¶
type KeystoreConfig = configmodule.KeystoreConfig
type Option ¶
type Option func(*graphjinService) error
func OptionDisableQueryLearning ¶
func OptionDisableQueryLearning() Option
OptionDisableQueryLearning suppresses dev-mode named-query and fragment auto-save for this embedded service instance. Existing saved queries remain discoverable and executable. This is intended for deterministic evaluation and other read-only harnesses whose catalog must not mutate while measured.
func OptionSetDB ¶
OptionSetDB sets a new db client. The connection is stored under the DefaultDBName key in the dbs map for backward compatibility.
func OptionSetDatabases ¶
OptionSetDatabases sets named database clients for multi-database embeddings.
func OptionSetHookFunc ¶
OptionSetHookFunc sets a function to be called on every request
func OptionSetLogOutput ¶
func OptionSetLogOutput(output zapcore.WriteSyncer) Option
OptionSetLogOutput sets the log output writer (e.g., os.Stderr for MCP stdio mode)
func OptionSetModule ¶ added in v3.35.0
OptionSetModule registers optional product-surface modules (embedded web console, OpenAPI export, ...). The application supplies them; the service knows only the module.Module interface. Modules read their own section under the top-level `modules:` config key; without a matching section a module stays inert.
func OptionSetMutationHook ¶ added in v3.36.11
func OptionSetMutationHook(h core.MutationHook) Option
OptionSetMutationHook installs a hook that receives the open mutation transaction and the row changes captured by the engine.
func OptionSetNamespace ¶
OptionSetNamespace sets service namespace
func OptionSetQueryPolicyHook ¶ added in v3.36.13
func OptionSetQueryPolicyHook(h core.QueryPolicyHook) Option
OptionSetQueryPolicyHook installs a request-scoped policy hook that can constrain compiled query IR before SQL generation.
func OptionSetRuntimeSchemaDDLDir ¶
OptionSetRuntimeSchemaDDLDir sets where the core stores generated schema-DDL restart snapshots, relative to the service filesystem root.
func OptionSetZapLogger ¶
OptionSetZapLogger sets service structured logger
type RateLimiter ¶
type RateLimiter = configmodule.RateLimiter
type RedisConfig ¶
type RedisConfig = configmodule.RedisConfig
type SecretsConfig ¶
type SecretsConfig = configmodule.SecretsConfig
type Serv ¶
type Serv = configmodule.Service
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config contains service configuration mechanics.
|
Package config contains service configuration mechanics. |
|
Package database contains service database configuration and adapters.
|
Package database contains service database configuration and adapters. |
|
Package http contains the service HTTP routing contract.
|
Package http contains the service HTTP routing contract. |
|
Package lifecycle owns service startup and shutdown mechanics.
|
Package lifecycle owns service startup and shutdown mechanics. |
|
Package module is the seam between the service and optional product-surface modules (embedded web console, OpenAPI export, ...).
|
Package module is the seam between the service and optional product-surface modules (embedded web console, OpenAPI export, ...). |