Documentation ¶
Overview ¶
nolint: errcheck
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" "time" "github.com/Hangman-Studios/graphjin/core" _ "github.com/jackc/pgx/v4/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 ¶
- func GetConfigName() string
- func InitAdmin(db *sql.DB, dbtype string) error
- func NewDB(conf *Config, openDB bool, log *zap.SugaredLogger, fs afero.Fs) (*sql.DB, error)
- type Action
- type Admin
- type Auth
- type BuildInfo
- type Config
- type Core
- type Database
- type JWTConfig
- type Option
- type Payload
- type RateLimiter
- type Serv
- type Service
- func (s *Service) Attach(mux *http.ServeMux) error
- func (s *Service) Deploy(conf *Config, options ...Option) error
- func (s *Service) GetDB() *sql.DB
- func (s *Service) GraphQL(c context.Context, query string, vars json.RawMessage, rc *core.ReqConfig) (*core.Result, error)
- func (s *Service) Start() error
- func (s *Service) Subscribe(c context.Context, query string, vars json.RawMessage, rc *core.ReqConfig) (*core.Member, error)
- type Telemetry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfigName ¶
func GetConfigName() string
Types ¶
type Admin ¶
type Admin struct { // HotDeploy enables the ability to hot-deploy a new configuration // to GraphJin. HotDeploy bool `mapstructure:"hot_deploy"` // AdminSecret is the secret key used to control access // to the admin api AdminSecretKey string `mapstructure:"admin_secret_key"` }
Admin struct contains config values used for adminstration of the GraphJin service
type BuildInfo ¶
func GetBuildInfo ¶
func GetBuildInfo() BuildInfo
type Config ¶
type Config struct { // Core holds config values for the GraphJin compiler Core `mapstructure:",squash"` // Serv holds config values for the GraphJin Service Serv `mapstructure:",squash"` // Admin holds config values for adminstrationof GraphJin Service Admin `mapstructure:",squash"` // contains filtered or unexported fields }
Config struct holds the GraphJin service config values
func ReadInConfig ¶
ReadInConfig function reads in the config file for the environment specified in the GO_ENV environment variable. This is the best way to create a new GraphJin config.
func ReadInConfigFS ¶
ReadInConfigFS is the same as ReadInConfig but it also takes a filesytem as an argument
type Database ¶
type Database struct { Type string Host string Port uint16 DBName string User string Password string Schema string PoolSize int `mapstructure:"pool_size"` MaxConnections int `mapstructure:"max_connections"` MaxConnIdleTime time.Duration `mapstructure:"max_connection_idle_time"` MaxConnLifeTime time.Duration `mapstructure:"max_connection_life_time"` PingTimeout time.Duration `mapstructure:"ping_timeout"` EnableTLS bool `mapstructure:"enable_tls"` ServerName string `mapstructure:"server_name"` ServerCert string `mapstructure:"server_cert"` ClientCert string `mapstructure:"client_cert"` ClientKey string `mapstructure:"client_key"` }
Database config
type Option ¶
type Option func(*service) error
func OptionDeployActive ¶
func OptionDeployActive() Option
func OptionSetFS ¶
type Payload ¶
type Payload struct { Data json.RawMessage `json:"data,omitempty"` Errors []core.Error `json:"errors,omitempty"` }
type RateLimiter ¶
RateLimiter sets the API rate limits
type Serv ¶
type Serv struct { // AppName is the name of your application used in log and debug messages AppName string `mapstructure:"app_name"` // Production when set to true runs the service with production level // security and other defaults. For example allow lists are enforced. Production bool // ConfigPath is the default path to find all configuration // files and scripts under ConfigPath string `mapstructure:"config_path"` // SecretsFile is the file for the secret key store SecretsFile string `mapstructure:"secrets_file"` // LogLevel can be debug, error, warn, info LogLevel string `mapstructure:"log_level"` // LogFormat can be json or simple LogFormat string `mapstructure:"log_format"` // HostPost to run the service on. Example localhost:8080 HostPort string `mapstructure:"host_port"` // Host to run the service on Host string // Port to run the service on Port string // HTTPGZip enables HTTP compression HTTPGZip bool `mapstructure:"http_compress"` // ServerTiming enables the Server-Timing header ServerTiming bool `mapstructure:"server_timing"` // Enable the web UI. Disabled in production WebUI bool `mapstructure:"web_ui"` // EnableTracing enables OpenTrace request tracing EnableTracing bool `mapstructure:"enable_tracing"` // WatchAndReload enables reloading the service on config changes WatchAndReload bool `mapstructure:"reload_on_config_change"` // AuthFailBlock when enabled blocks requests with a 401 on auth failure AuthFailBlock bool `mapstructure:"auth_fail_block"` // MigrationsPath is the path to the database migration files MigrationsPath string `mapstructure:"migrations_path"` // AllowedOrigins sets the HTTP CORS Access-Control-Allow-Origin header AllowedOrigins []string `mapstructure:"cors_allowed_origins"` // AllowedHeaders sets the HTTP CORS Access-Control-Allow-Headers header AllowedHeaders []string `mapstructure:"cors_allowed_headers"` // DebugCORS enables debug logs for cors DebugCORS bool `mapstructure:"cors_debug"` // CacheControl sets the HTTP Cache-Control header CacheControl string `mapstructure:"cache_control"` // Telemetry struct contains OpenCensus metrics and tracing related config Telemetry Telemetry // Auth set the default auth used by the service Auth Auth // Auths sets multiple auths to be used by actions Auths []Auth // DB struct contains db config DB Database `mapstructure:"database"` Actions []Action // RateLimiter sets the API rate limits RateLimiter RateLimiter `mapstructure:"rate_limiter"` }
Serv struct contains config values used by the GraphJin service
type Telemetry ¶
type Telemetry struct { // Debug enables debug logging for metrics and tracing data. Debug bool // Interval to send out metrics and tracing data Interval *time.Duration Metrics struct { // Exporter is the name of the metrics exporter to use. Example: prometheus Exporter string // Endpoint to send the data to. Endpoint string // Namespace is set based on your exporter configration Namespace string // Key is set based on your exporter configuration Key string } Tracing struct { // Exporter is the name of the tracing exporter to use. Example: zipkin Exporter string // Endpoint to send the data to. Example: http://zipkin:9411/api/v2/spans Endpoint string // Sample sets how many requests to sample for tracing: Example: 0.6 Sample string // IncludeQuery when set the GraphQL query is included in the tracing data IncludeQuery bool `mapstructure:"include_query"` // IncludeParams when set variables used with the query are included in the // tracing data IncludeParams bool `mapstructure:"include_params"` // ExcludeHealthCheck when set health check tracing is excluded from the // tracing data ExcludeHealthCheck bool `mapstructure:"exclude_health_check"` } }
Telemetry struct contains OpenCensus metrics and tracing related config