...

Package transport

import "github.com/99designs/gqlgen/graphql/handler/transport"
Overview
Index

Overview ▾

Index ▾

func AddSubscriptionError(ctx context.Context, err *gqlerror.Error)
func AppendCloseReason(ctx context.Context, reason string) context.Context
func SendError(w http.ResponseWriter, code int, errors ...*gqlerror.Error)
func SendErrorf(w http.ResponseWriter, code int, format string, args ...interface{})
type GET
    func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (h GET) Supports(r *http.Request) bool
type GRAPHQL
    func (h GRAPHQL) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (h GRAPHQL) Supports(r *http.Request) bool
type InitPayload
    func GetInitPayload(ctx context.Context) InitPayload
    func (p InitPayload) Authorization() string
    func (p InitPayload) GetString(key string) string
type MultipartForm
    func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (f MultipartForm) Supports(r *http.Request) bool
type Options
    func (o Options) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (o Options) Supports(r *http.Request) bool
type POST
    func (h POST) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (h POST) Supports(r *http.Request) bool
type SSE
    func (t SSE) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (t SSE) Supports(r *http.Request) bool
type UrlEncodedForm
    func (h UrlEncodedForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (h UrlEncodedForm) Supports(r *http.Request) bool
type Websocket
    func (t Websocket) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
    func (t Websocket) Supports(r *http.Request) bool
type WebsocketCloseFunc
type WebsocketError
    func (e WebsocketError) Error() string
type WebsocketErrorFunc
type WebsocketInitFunc

Package files

error.go headers.go http_form_multipart.go http_form_urlencoded.go http_get.go http_graphql.go http_post.go options.go reader.go sse.go util.go websocket.go websocket_close_reason.go websocket_graphql_transport_ws.go websocket_graphqlws.go websocket_init.go websocket_resolver_error.go websocket_subprotocol.go

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

type GET

GET implements the GET side of the default HTTP transport defined in https://github.com/APIs-guru/graphql-over-http#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
}

func (GET) Do

func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (GET) Supports

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

type GRAPHQL

GRAPHQL implements the application/graphql side of the HTTP transport see: https://graphql.org/learn/serving-over-http/#post-request If the "application/graphql" Content-Type header is present, treat the HTTP POST body contents as the GraphQL query string.

type GRAPHQL 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
}

func (GRAPHQL) Do

func (h GRAPHQL) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (GRAPHQL) Supports

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

type InitPayload

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.

type InitPayload map[string]interface{}

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

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

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
}

func (MultipartForm) Do

func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (MultipartForm) Supports

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

type Options

Options responds to http OPTIONS and HEAD requests

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

func (Options) Do

func (o Options) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (Options) Supports

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

type POST

POST implements the POST side of the default HTTP transport defined in https://github.com/APIs-guru/graphql-over-http#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
}

func (POST) Do

func (h POST) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (POST) Supports

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

type SSE

type SSE struct{}

func (SSE) Do

func (t SSE) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (SSE) Supports

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

type UrlEncodedForm

FORM implements the application/x-www-form-urlencoded side of the default HTTP transport

type UrlEncodedForm 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
}

func (UrlEncodedForm) Do

func (h UrlEncodedForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (UrlEncodedForm) Supports

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

type Websocket

type Websocket struct {
    Upgrader              websocket.Upgrader
    InitFunc              WebsocketInitFunc
    InitTimeout           time.Duration
    ErrorFunc             WebsocketErrorFunc
    CloseFunc             WebsocketCloseFunc
    KeepAlivePingInterval time.Duration
    PongOnlyInterval      time.Duration
    PingPongInterval      time.Duration
    /* If PingPongInterval has a non-0 duration, then when the server sends a ping
     * it sets a ReadDeadline of PingPongInterval*2 and if the client doesn't respond
     * with pong before that deadline is reached then the connection will die with a
     * 1006 error code.
     *
     * MissingPongOk if true, tells the server to not use a ReadDeadline such that a
     * missing/slow pong response from the client doesn't kill the connection.
     */
    MissingPongOk bool
    // contains filtered or unexported fields
}

func (Websocket) Do

func (t Websocket) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)

func (Websocket) Supports

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

type WebsocketCloseFunc

Callback called when websocket is closed.

type WebsocketCloseFunc func(ctx context.Context, closeCode int)

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, *InitPayload, error)