server

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 18 Imported by: 0

README

graphql-go-server

Server implementation for graphql-go

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON           = "application/json"
	ContentTypeGraphQL        = "application/graphql"
	ContentTypeFormURLEncoded = "application/x-www-form-urlencoded"
)

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextFunc

type ContextFunc func(r *http.Request) context.Context

type FormatErrorFunc

type FormatErrorFunc func(err error) gqlerrors.FormattedError

type GraphQLTransportWS added in v0.3.0

type GraphQLTransportWS struct {
	ConnectionInitWaitTimeout time.Duration
	RootValueFunc             func(ctx context.Context, r *http.Request, op *ast.OperationDefinition) map[string]interface{}
	ContextValueFunc          func(c protocol.Context, msg protocol.OperationMessage, execArgs graphql.Params) (context.Context, gqlerrors.FormattedErrors)
	OnConnect                 func(c protocol.Context) (interface{}, error)
	OnPing                    func(c protocol.Context, payload map[string]interface{})
	OnPong                    func(c protocol.Context, payload map[string]interface{})
	OnDisconnect              func(c protocol.Context, code graphqltransportws.CloseCode, reason string)
	OnClose                   func(c protocol.Context, code graphqltransportws.CloseCode, reason string)
	OnSubscribe               func(c protocol.Context, msg graphqltransportws.SubscribeMessage) (*graphql.Params, gqlerrors.FormattedErrors)
	OnNext                    func(c protocol.Context, msg graphqltransportws.NextMessage, args graphql.Params, Result *graphql.Result) (*protocol.ExecutionResult, error)
	OnError                   func(c protocol.Context, msg graphqltransportws.ErrorMessage, errs gqlerrors.FormattedErrors) (gqlerrors.FormattedErrors, error)
	OnComplete                func(c protocol.Context, msg graphqltransportws.CompleteMessage) error
	OnOperation               func(c protocol.Context, msg graphqltransportws.SubscribeMessage, args graphql.Params, result interface{}) (interface{}, error)
}

type GraphQLWS added in v0.3.0

type GraphQLWS struct {
	ConnectionInitWaitTimeout time.Duration
	KeepAlive                 time.Duration
	RootValueFunc             func(ctx context.Context, r *http.Request, op *ast.OperationDefinition) map[string]interface{}
	ContextValueFunc          func(c protocol.Context, msg protocol.OperationMessage, execArgs graphql.Params) (context.Context, gqlerrors.FormattedErrors)
	OnConnect                 func(c protocol.Context, payload interface{}) (interface{}, error)
	OnDisconnect              func(c protocol.Context)
	OnOperation               func(c protocol.Context, msg graphqlws.StartMessage, params *graphql.Params) (*graphql.Params, error)
	OnOperationComplete       func(c protocol.Context, id string)
}

type Option

type Option func(opts *Options)

func WithContextFunc

func WithContextFunc(f ContextFunc) Option

func WithFormatErrorFunc

func WithFormatErrorFunc(f FormatErrorFunc) Option

func WithGraphQLTransportWS added in v0.3.0

func WithGraphQLTransportWS(o *GraphQLTransportWS) Option

func WithGraphQLWS added in v0.3.0

func WithGraphQLWS(o *GraphQLWS) Option

func WithGraphiQLOptions

func WithGraphiQLOptions(o *ide.GraphiQLOptions) Option

func WithLogFunc added in v0.3.0

func WithLogFunc(l logger.LogFunc) Option

func WithPlaygroundOptions

func WithPlaygroundOptions(o *ide.PlaygroundOptions) Option

func WithPretty

func WithPretty() Option

func WithResultCallbackFunc

func WithResultCallbackFunc(f ResultCallbackFunc) Option

func WithRootValueFunc

func WithRootValueFunc(f RootValueFunc) Option

type Options added in v0.3.0

type Options struct {
	// common configs
	Pretty             bool
	LogFunc            logger.LogFunc
	RootValueFunc      RootValueFunc
	ContextFunc        ContextFunc
	FormatErrorFunc    FormatErrorFunc
	ResultCallbackFunc ResultCallbackFunc

	// WebSocket configs
	GraphQLWS          *GraphQLWS
	GraphQLTransportWS *GraphQLTransportWS

	// IDE configs
	Playground *ide.PlaygroundOptions
	GraphiQL   *ide.GraphiQLOptions
}

func NewOptions added in v0.3.0

func NewOptions(opts ...Option) *Options

NewOptions creates a new default options with optional options funcs

type RequestOptions

type RequestOptions struct {
	Query         string                 `json:"query" url:"query" schema:"query"`
	Variables     map[string]interface{} `json:"variables" url:"variables" schema:"variables"`
	OperationName string                 `json:"operationName" url:"operationName" schema:"operationName"`
}

RequestOptions options

func GetRequestOptions

func GetRequestOptions(r *http.Request) *RequestOptions

GetRequestOptions Parses a http.Request into GraphQL request options struct without clearning the body

func NewRequestOptions

func NewRequestOptions(r *http.Request) *RequestOptions

NewRequestOptions Parses a http.Request into GraphQL request options struct

type RequestType added in v0.3.0

type RequestType string

type ResultCallbackFunc

type ResultCallbackFunc func(ctx context.Context, params *graphql.Params, result *graphql.Result, responseBody []byte)

type RootValueFunc

type RootValueFunc func(ctx context.Context, r *http.Request) map[string]interface{}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(schema graphql.Schema, opts ...Option) *Server

New creates a new server

func (*Server) ContextHandler

func (s *Server) ContextHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

ContextHandler provides an entrypoint into executing graphQL queries with a user-provided context.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP provides an entrypoint into executing graphQL queries.

func (*Server) WSHandler

func (s *Server) WSHandler(w http.ResponseWriter, r *http.Request)

WSHandler handles websocket connection upgrade

Directories

Path Synopsis
example
ws

Jump to

Keyboard shortcuts

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