transport

package
v0.17.29 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSubscriptionError

func AddSubscriptionError(ctx context.Context, err *gqlerror.Error)

AddSubscriptionError is used to let websocket return an error message after subscription resolver returns a channel. for example:

func (r *subscriptionResolver) Method(ctx context.Context) (<-chan *model.Message, error) {
	ch := make(chan *model.Message)
	go func() {
     defer func() {
			close(ch)
     }
		// some kind of block processing (e.g.: gRPC client streaming)
		stream, err := gRPCClientStreamRequest(ctx)
		if err != nil {
			   transport.AddSubscriptionError(ctx, err)
            return // must return and close channel so websocket can send error back
     }
		for {
			m, err := stream.Recv()
			if err == io.EOF {
				return
			}
			if err != nil {
			   transport.AddSubscriptionError(ctx, err)
            return // must return and close channel so websocket can send error back
			}
			ch <- m
		}
	}()

	return ch, nil
}

see https://github.com/99designs/gqlgen/pull/2506 for more details

func AppendCloseReason

func AppendCloseReason(ctx context.Context, reason string) context.Context

func SendError

func SendError(w http.ResponseWriter, code int, errors ...*gqlerror.Error)

SendError sends a best effort error to a raw response writer. It assumes the client can understand the standard json error response

func SendErrorf

func SendErrorf(w http.ResponseWriter, code int, format string, args ...interface{})

SendErrorf wraps SendError to add formatted messages

Types

type GET

type GET struct {
	// Map of all headers that are added to graphql response. If not
	// set, only one header: Content-Type: application/json will be set.
	ResponseHeaders map[string][]string
}

GET implements the GET side of the default HTTP transport defined in https://github.com/APIs-guru/graphql-over-http#get

func (GET) Do

func (GET) Supports

func (h GET) Supports(r *http.Request) bool

type InitPayload

type InitPayload map[string]interface{}

InitPayload is a structure that is parsed from the websocket init message payload. TO use request headers for non-websocket, instead wrap the graphql handler in a middleware.

func GetInitPayload

func GetInitPayload(ctx context.Context) InitPayload

GetInitPayload gets a map of the data sent with the connection_init message, which is used by graphql clients as a stand-in for HTTP headers.

func (InitPayload) Authorization

func (p InitPayload) Authorization() string

Authorization is a short hand for getting the Authorization header from the payload.

func (InitPayload) GetString

func (p InitPayload) GetString(key string) string

GetString safely gets a string value from the payload. It returns an empty string if the payload is nil or the value isn't set.

type MultipartForm

type MultipartForm struct {
	// MaxUploadSize sets the maximum number of bytes used to parse a request body
	// as multipart/form-data.
	MaxUploadSize int64

	// MaxMemory defines the maximum number of bytes used to parse a request body
	// as multipart/form-data in memory, with the remainder stored on disk in
	// temporary files.
	MaxMemory int64

	// Map of all headers that are added to graphql response. If not
	// set, only one header: Content-Type: application/json will be set.
	ResponseHeaders map[string][]string
}

MultipartForm the Multipart request spec https://github.com/jaydenseric/graphql-multipart-request-spec

func (MultipartForm) Do

func (MultipartForm) Supports

func (f MultipartForm) Supports(r *http.Request) bool

type Options

type Options struct {
	// AllowedMethods is a list of allowed HTTP methods.
	AllowedMethods []string
}

Options responds to http OPTIONS and HEAD requests

func (Options) Do

func (Options) Supports

func (o Options) Supports(r *http.Request) bool

type POST

type POST struct {
	// Map of all headers that are added to graphql response. If not
	// set, only one header: Content-Type: application/json will be set.
	ResponseHeaders map[string][]string
}

POST implements the POST side of the default HTTP transport defined in https://github.com/APIs-guru/graphql-over-http#post

func (POST) Do

func (POST) Supports

func (h POST) Supports(r *http.Request) bool

type SSE

type SSE struct{}

func (SSE) Do

func (SSE) Supports

func (t SSE) Supports(r *http.Request) bool

type Websocket

type Websocket struct {
	Upgrader              websocket.Upgrader
	InitFunc              WebsocketInitFunc
	InitTimeout           time.Duration
	ErrorFunc             WebsocketErrorFunc
	KeepAlivePingInterval time.Duration
	PingPongInterval      time.Duration
	// contains filtered or unexported fields
}

func (Websocket) Do

func (Websocket) Supports

func (t Websocket) Supports(r *http.Request) bool

type WebsocketError

type WebsocketError struct {
	Err error

	// IsReadError flags whether the error occurred on read or write to the websocket
	IsReadError bool
}

func (WebsocketError) Error

func (e WebsocketError) Error() string

type WebsocketErrorFunc

type WebsocketErrorFunc func(ctx context.Context, err error)

type WebsocketInitFunc

type WebsocketInitFunc func(ctx context.Context, initPayload InitPayload) (context.Context, error)

Jump to

Keyboard shortcuts

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