graphql

package
v1.4.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package graphql provides GraphQL integration with automatic OpenAPI documentation

Index

Constants

View Source
const (
	DefaultPath              = "/graphql"
	DefaultPlaygroundPath    = "/playground"
	DefaultQueryCacheSize    = 1000
	DefaultComplexityLimit   = 0 // No limit
	DefaultIntrospection     = true
	DefaultSubscriptionsPath = "/graphql/subscriptions"
)

GraphQL configuration defaults

View Source
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

func GetEchoContext(ctx context.Context) echo.Context

GetEchoContext retrieves the Echo context from a GraphQL resolver context Returns nil if not found

func GetUserFromContext

func GetUserFromContext(ctx context.Context, key string) interface{}

GetUserFromContext is a helper to get user information from the Echo context Useful for authentication in resolvers

func Handler

func Handler(config Config) *handler.Server

Handler creates a gqlgen handler from a Config This is used internally by echonext.App.GraphQL but can be used directly

func MustGetEchoContext

func MustGetEchoContext(ctx context.Context) echo.Context

MustGetEchoContext retrieves the Echo context from a GraphQL resolver context Panics if not found

func PlaygroundHandler

func PlaygroundHandler(title, graphqlPath string) http.Handler

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL