graphql

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 4 Imported by: 1

README

GraphQL

GraphQL is a query language for the web. For server-side projects mainly serving client-side web applications GraphQL can be a great choice.

Similarly to the grpc transport, this transport is also limited to synchronous calls. Go kit at its core uses RPC for communication, so subscriptions are not supported.

Go has several bindings for GraphQL, but gqlgen seems to be the most advanced.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodeRequestFunc

type DecodeRequestFunc func(context.Context, interface{}) (request interface{}, err error)

DecodeRequestFunc extracts a user-domain request object from a GraphQL request. It's designed to be used in GraphQL servers, for server-side endpoints. One straightforward DecodeRequestFunc could be something that decodes from the GraphQL request message to the concrete request type.

type EncodeErrorResponseFunc

type EncodeErrorResponseFunc func(context.Context, error) error

EncodeErrorResponseFunc transforms the passed error to a GraphQL error. It's designed to be used in GraphQL servers, for server-side endpoints.

type EncodeResponseFunc

type EncodeResponseFunc func(context.Context, interface{}) (response interface{}, err error)

EncodeResponseFunc encodes the passed response object to the GraphQL response message. It's designed to be used in GraphQL servers, for server-side endpoints. One straightforward EncodeResponseFunc could be something that encodes the object directly to the GraphQL response message.

func ErrorResponseEncoder

func ErrorResponseEncoder(
	encoder EncodeResponseFunc,
	errorEncoder EncodeErrorResponseFunc,
) EncodeResponseFunc

ErrorResponseEncoder encodes the passed response object to a GraphQL response or error.

type Handler

type Handler interface {
	ServeGraphQL(ctx context.Context, request interface{}) (context.Context, interface{}, error)
}

Handler which should be called from the GraphQL binding of the service implementation. The incoming request parameter, and returned response parameter, are both GraphQL types, not user-domain.

func NewErrorEncoderHandler

func NewErrorEncoderHandler(handler Handler, errorEncoder EncodeErrorResponseFunc) Handler

NewErrorEncoderHandler wraps a GraphQL handler and encodes the returned error using the error encoder (if necessary).

For example, a returned endpoint error might need additional encoding.

type Server

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

Server wraps an endpoint and implements graphql.Handler.

func NewServer

func NewServer(
	e endpoint.Endpoint,
	dec DecodeRequestFunc,
	enc EncodeResponseFunc,
	opts ...ServerOption,
) *Server

NewServer constructs a new server, which implements wraps the provided endpoint and implements the Handler interface. Consumers should write bindings that adapt the concrete GraphQL queries and methods in the schema. Request and response objects are from the caller business domain, not GraphQL input and response types.

func (Server) ServeGraphQL

func (s Server) ServeGraphQL(ctx context.Context, req interface{}) (context.Context, interface{}, error)

ServeGraphQL implements the Handler interface.

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

ServerOption sets an optional parameter for servers.

func ServerErrorHandler

func ServerErrorHandler(errorHandler transport.ErrorHandler) ServerOption

ServerErrorHandler is used to handle non-terminal errors. By default, non-terminal errors are ignored.

Jump to

Keyboard shortcuts

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