Documentation
¶
Overview ¶
Package graphql provides GraphQL integration with automatic OpenAPI documentation
Index ¶
- Constants
- func GetEchoContext(ctx context.Context) echo.Context
- func GetUserFromContext(ctx context.Context, key string) interface{}
- func Handler(config Config) *handler.Server
- func MustGetEchoContext(ctx context.Context) echo.Context
- func PlaygroundHandler(title, graphqlPath string) http.Handler
- func SubscriptionHandler(schema graphql.ExecutableSchema) *handler.Server
- func WithMiddleware(middlewares ...echo.MiddlewareFunc) echo.MiddlewareFunc
- func WrapWithEchoContext(srv *handler.Server) echo.HandlerFunc
- type Config
- type Middleware
- type Route
- type SubscriptionConfig
Constants ¶
const ( DefaultPath = "/graphql" DefaultPlaygroundPath = "/playground" DefaultQueryCacheSize = 1000 DefaultComplexityLimit = 0 // No limit DefaultIntrospection = true DefaultSubscriptionsPath = "/graphql/subscriptions" )
GraphQL configuration defaults
const (
// EchoContextKey is the key used to store echo.Context in GraphQL context
EchoContextKey contextKey = "echonext_echo_context"
)
Variables ¶
This section is empty.
Functions ¶
func GetEchoContext ¶
GetEchoContext retrieves the Echo context from a GraphQL resolver context Returns nil if not found
func GetUserFromContext ¶
GetUserFromContext is a helper to get user information from the Echo context Useful for authentication in resolvers
func Handler ¶
Handler creates a gqlgen handler from a Config This is used internally by echonext.App.GraphQL but can be used directly
func MustGetEchoContext ¶
MustGetEchoContext retrieves the Echo context from a GraphQL resolver context Panics if not found
func PlaygroundHandler ¶
PlaygroundHandler creates a playground handler for the given GraphQL path
func SubscriptionHandler ¶
func SubscriptionHandler(schema graphql.ExecutableSchema) *handler.Server
SubscriptionHandler creates a gqlgen handler for subscriptions
func WithMiddleware ¶
func WithMiddleware(middlewares ...echo.MiddlewareFunc) echo.MiddlewareFunc
WithMiddleware wraps a GraphQL handler with Echo middleware context
func WrapWithEchoContext ¶
func WrapWithEchoContext(srv *handler.Server) echo.HandlerFunc
WrapWithEchoContext creates an Echo handler that injects context into GraphQL requests
Types ¶
type Config ¶
type Config struct {
// Path is the endpoint path for GraphQL queries/mutations (default: /graphql)
Path string
// PlaygroundPath is the endpoint for GraphQL Playground (default: /playground, empty to disable)
PlaygroundPath string
// Schema is the gqlgen executable schema
Schema graphql.ExecutableSchema
// ComplexityLimit sets the maximum query complexity (0 = no limit)
ComplexityLimit int
// QueryCacheSize sets the LRU cache size for parsed queries
QueryCacheSize int
// EnableIntrospection enables schema introspection (default: true)
EnableIntrospection bool
// EnableTracing enables Apollo tracing
EnableTracing bool
// WebSocketUpgrader for subscriptions (nil = use default)
WebSocketUpgrader *websocket.Upgrader
// RecoverFunc handles panics in resolvers
RecoverFunc graphql.RecoverFunc
// ErrorPresenter customizes error responses
ErrorPresenter graphql.ErrorPresenterFunc
}
Config configures GraphQL endpoint behavior
func DefaultConfig ¶
func DefaultConfig(schema graphql.ExecutableSchema) Config
DefaultConfig returns sensible default configuration
type Middleware ¶
type Middleware func(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler
Middleware creates Echo middleware that can be used with GraphQL handlers This is useful for authentication, logging, etc.
type Route ¶
type Route struct {
Summary string
Description string
Tags []string
DocumentInOpenAPI bool // Whether to include in OpenAPI spec
}
Route configures GraphQL endpoint metadata for OpenAPI documentation
type SubscriptionConfig ¶
type SubscriptionConfig struct {
// Path is the WebSocket endpoint path (default: /graphql/subscriptions)
Path string
// KeepAliveInterval is the interval for keep-alive pings
KeepAliveInterval int // in seconds
}
SubscriptionConfig configures WebSocket subscriptions