Documentation
¶
Index ¶
- Constants
- func AddInitFunc(rank int, initFunc transport.WebsocketInitFunc) module.Option
- func AddInitFuncFactory[T InitFuncFactory](rank int) module.Option
- func DecorateServer(decorator any) module.Option
- func DecorateWithDependency[T any](decorator func(srv *handler.Server, dep T) *handler.Server) module.Option
- func GetLoader[K comparable, T any](ctx context.Context, factory LoaderFactory[K, T]) *dataloader.Loader[K, T]
- func InitFunc(registry *InitFuncRegistry) transport.WebsocketInitFunc
- func NewErrorPresenter(params ErrorPresenterParams) graphql.ErrorPresenterFunc
- func NewGraphiQLHandler(title, endpoint string, subscriptionsEnabled bool) http.HandlerFunc
- func NewGraphqlServer(params ServerParams) *handler.Server
- func NewHandlerRoute(handler *handler.Server, config Config) (modulusHttp.RouteProvider, modulusHttp.RouteProvider)
- func NewManifesto() module.Manifesto
- func NewModule(options ...module.Option) *module.Module
- func NewPlaygroundHandlerRoute(config Config) modulusHttp.RouteProvider
- func OverrideErrorPresenter[T ErrorPresenterFactory](gqlModule *module.Module) *module.Module
- func WithLoaders(ctx context.Context, loaders *sync.Map) context.Context
- type Config
- type ErrorPresenterFactory
- type ErrorPresenterParams
- type InitFuncFactory
- type InitFuncRegistry
- type LoaderFactory
- type LoadersInitializer
- func (LoadersInitializer) ExtensionName() string
- func (l LoadersInitializer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler
- func (l LoadersInitializer) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response
- func (LoadersInitializer) Validate(graphql.ExecutableSchema) error
- type PlaygroundConfig
- type ServerParams
Constants ¶
const (
LoadersKey contextKey = "Loaders"
)
Variables ¶
This section is empty.
Functions ¶
func AddInitFunc ¶ added in v0.2.4
func AddInitFunc(rank int, initFunc transport.WebsocketInitFunc) module.Option
AddInitFunc registers a transport.WebsocketInitFunc that runs whenever a WebSocket subscription connection is initialized (i.e. on the client's "connection_init" message). InitFuncs are ranked the same way http.AddMiddlewareToPipeline ranks HTTP middlewares: lower ranks run first, same-rank entries run in registration order. Each one acts like a middleware, receiving the context and InitPayload produced by the previous one (see InitFunc), and can reject the connection by returning an error or thread values through the context for the next InitFunc and the resolvers.
If your InitFunc needs its own dependencies (e.g. an authenticator resolved through DI), use AddInitFuncFactory instead.
func AddInitFuncFactory ¶ added in v0.2.4
func AddInitFuncFactory[T InitFuncFactory](rank int) module.Option
AddInitFuncFactory registers an InitFuncFactory whose own dependencies are resolved through DI: T is constructed by the container (so its constructor can request whatever it needs, e.g. an authenticator or a repository), and the transport.WebsocketInitFunc it returns from InitFunc() is added to the registry at rank, same as AddInitFunc. This mirrors how http.AddMiddlewareFactoryToPipeline builds an HTTP middleware with dependencies via http.MiddlewareFactory.
The concrete type T must be registered as a provider elsewhere (typically in the consuming module's own AddProviders call), the same way a MiddlewareFactory implementation is.
func DecorateServer ¶ added in v0.2.3
DecorateServer - decorates GraphQL server with additional options. decorator is a function that gets server with additional dependencies and returns a server Example: DecorateServer(func(srv *handler.Server) *handler.Server)
func DecorateWithDependency ¶ added in v0.2.3
func GetLoader ¶
func GetLoader[K comparable, T any](ctx context.Context, factory LoaderFactory[K, T]) *dataloader.Loader[K, T]
func InitFunc ¶ added in v0.2.4
func InitFunc(registry *InitFuncRegistry) transport.WebsocketInitFunc
InitFunc composes all registered transport.WebsocketInitFunc (see AddInitFunc/AddInitFuncFactory) into a single one, used as the Websocket transport's InitFunc. Registered functions run in rank order, acting like a middleware chain: each one receives the context and InitPayload produced by the previous one, and can reject the connection by returning an error, or thread values through the context for the next InitFunc and for the resolvers. The registry is read on every call rather than once here, since fx.Invoke registrations that populate it (see AddInitFunc) must all have already run by the time a real connection triggers this - reading it once at provide-time could race a registration that hasn't happened yet.
func NewErrorPresenter ¶
func NewErrorPresenter(params ErrorPresenterParams) graphql.ErrorPresenterFunc
func NewGraphiQLHandler ¶ added in v0.2.4
func NewGraphiQLHandler(title, endpoint string, subscriptionsEnabled bool) http.HandlerFunc
NewGraphiQLHandler renders GraphiQL 5 (the current major version - it dropped the UMD CDN bundle gqlgen's own playground.Handler relies on, so this ships its own ESM-based page instead of using that helper).
subscriptionsEnabled should be true only when the server's subscription transport is graphql-ws-compatible (i.e. config.SubscriptionTransport == "ws"); GraphiQL's fetcher wires subscriptions over graphql-ws, which doesn't speak the SSE-based subscription protocol.
func NewGraphqlServer ¶
func NewGraphqlServer( params ServerParams, ) *handler.Server
func NewHandlerRoute ¶
func NewHandlerRoute(handler *handler.Server, config Config) (modulusHttp.RouteProvider, modulusHttp.RouteProvider)
func NewManifesto ¶
NewManifestModule creates a new graphql module with the manifest module.
func NewPlaygroundHandlerRoute ¶
func NewPlaygroundHandlerRoute(config Config) modulusHttp.RouteProvider
func OverrideErrorPresenter ¶
func OverrideErrorPresenter[T ErrorPresenterFactory](gqlModule *module.Module) *module.Module
OverrideErrorPresenter overrides the error presenter provider.
Types ¶
type Config ¶
type Config struct {
ComplexityLimit int `env:"GQL_COMPLEXITY_LIMIT, default=200"`
Path string `env:"GQL_API_URL, default=/graphql"`
IntrospectionEnabled bool `env:"GQL_INTROSPECTION_ENABLED, default=true"`
TracingEnabled bool `env:"GQL_TRACING_ENABLED, default=false"`
ReturnCause bool `env:"GQL_RETURN_CAUSE, default=false"`
SubscriptionTransport string `env:"GQL_SUBSCRIPTION_TRANSPORT, default=ws" comment:"Transport for GraphQL subscriptions. Allowed values: ws, sse"`
SubscriptionPingInterval time.Duration `env:"GQL_SUBSCRIPTION_PING_INTERVAL, default=10s" comment:"Keepalive ping interval connection"`
SubscriptionOriginPatterns []string `` /* 292-byte string literal not displayed */
Playground PlaygroundConfig
}
type ErrorPresenterFactory ¶
type ErrorPresenterFactory interface {
NewErrorPresenter() graphql.ErrorPresenterFunc
}
type ErrorPresenterParams ¶
type ErrorPresenterParams struct {
fx.In
ErrorPipeline *errhttp.ErrorPipeline `optional:"true"`
Config Config
}
type InitFuncFactory ¶ added in v0.2.4
type InitFuncFactory interface {
InitFunc() transport.WebsocketInitFunc
}
InitFuncFactory lets a WebSocket InitFunc be built with its own dependencies resolved through DI (see AddInitFuncFactory), the same way http.MiddlewareFactory lets an HTTP middleware be built with dependencies for http.AddMiddlewareFactoryToPipeline.
type InitFuncRegistry ¶ added in v0.2.4
type InitFuncRegistry struct {
// contains filtered or unexported fields
}
InitFuncRegistry accumulates transport.WebsocketInitFunc entries added via AddInitFunc/AddInitFuncFactory, ranked the same way http.Pipeline ranks HTTP middlewares: lower ranks run first, same-rank entries run in the order they were added. It's a shared mutable singleton (like http.Pipeline) populated by fx.Invoke calls before InitFunc ever reads from it.
func NewInitFuncRegistry ¶ added in v0.2.4
func NewInitFuncRegistry() *InitFuncRegistry
func (*InitFuncRegistry) Add ¶ added in v0.2.4
func (r *InitFuncRegistry) Add(rank int, fn transport.WebsocketInitFunc)
Add appends fn at the given rank.
func (*InitFuncRegistry) List ¶ added in v0.2.4
func (r *InitFuncRegistry) List() []transport.WebsocketInitFunc
List returns the flat, rank-sorted slice of registered InitFuncs.
type LoaderFactory ¶
type LoaderFactory[K comparable, T any] interface { Create() *dataloader.Loader[K, T] }
type LoadersInitializer ¶
type LoadersInitializer struct{}
func NewLoadersInitializer ¶
func NewLoadersInitializer() *LoadersInitializer
func (LoadersInitializer) ExtensionName ¶
func (LoadersInitializer) ExtensionName() string
func (LoadersInitializer) InterceptOperation ¶
func (l LoadersInitializer) InterceptOperation( ctx context.Context, next graphql.OperationHandler, ) graphql.ResponseHandler
InterceptOperation Init loaders before each operation
func (LoadersInitializer) InterceptResponse ¶
func (l LoadersInitializer) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response
InterceptResponse Init loaders before each event in subscription
func (LoadersInitializer) Validate ¶
func (LoadersInitializer) Validate(graphql.ExecutableSchema) error
type PlaygroundConfig ¶
type ServerParams ¶
type ServerParams struct {
fx.In
Config Config
Schema graphql.ExecutableSchema
LoadersInitializer *LoadersInitializer `optional:"true"`
Logger *slog.Logger
ErrorPresenter graphql.ErrorPresenterFunc
InitFunc transport.WebsocketInitFunc
}