server
API reference for the server package, generated from Go doc comments.
import "github.com/grx-gql/grx/server"Package server is the HTTP entry point for the grx GraphQL runtime. It wires user-supplied schema values, plugins, and transports into a value that satisfies http.Handler and serves both the GraphiQL playground and the GraphQL endpoint.
Index
type Config
Config tunes a Server. Schema is required; the remaining fields have safe zero-value defaults.
type Config struct {
// Schema selects the root resolvers the executor reflects over.
// Query is required; Mutation and Subscription are optional. See
// [schema.Config] for the field-by-field documentation.
Schema schema.Config
// Plugins are invoked at every lifecycle stage of a GraphQL
// request, in registration order. They may short-circuit a request
// by returning an error.
Plugins []plugins.Plugin
// PlaygroundPath is the URL path at which the bundled GraphiQL
// playground is served on GET. The empty string disables the
// playground.
PlaygroundPath string
// Transports registers protocol handlers (WebSocket, SSE, ...) that the
// server consults. Routing depends on GraphQLPath and SubscriptionPath: when
// they differ, concrete *websocket.WebSocketTransport and *sse.Transport values are moved
// to SubscriptionPath only; other transports remain on GraphQLPath. Each request
// is offered to the relevant chain in order; the first Match wins. On GraphQLPath
// a default HTTP+JSON transport ([`http.Transport`](https://pkg.go.dev/github.com/grx-gql/grx/http#Transport)) is appended automatically
// so POST requests always succeed unless you customise that transport explicitly.
Transports []core.Transport
// GraphQLPath is the HTTP path for queries/mutations (default "/graphql").
GraphQLPath string
// SubscriptionPath, when set to a path different from GraphQLPath, routes
// concrete *websocket.WebSocketTransport and *sse.Transport from Transports only to
// that path. Empty means subscriptions share GraphQLPath.
SubscriptionPath string
}type Server
Server is an http.Handler that exposes a GraphQL endpoint and an optional GraphiQL playground. Construct one with New.
type Server struct {
// contains filtered or unexported fields
}func New
func New(config Config) (*Server, error)New builds a Server from cfg. It returns an error when the supplied schema cannot be reflected into a valid GraphQL schema.
func (*Server) ServeHTTP
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)ServeHTTP routes incoming HTTP traffic. It serves GraphiQL on GET to the configured playground path, returns 204 for /favicon.ico, and dispatches every /graphql request through the registered transports. Requests that no transport claims receive a 404.
Generated by gomarkdoc
Last updated on