gql

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 16 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPermissions

func CheckPermissions(opt *Options) graphql.OperationMiddleware

CheckPermissions check the graphql operation permissions base on the package authz

func FromIncomingContext

func FromIncomingContext(ctx context.Context) (*gin.Context, error)

FromIncomingContext retrieves the gin.Context from the context.Context

func Middleware

func Middleware() handler.Middleware

Middleware is a builder for initializing graphql handler, it is middleware for gin. see handler.MiddlewareNewFunc

func RegisterGraphqlServer

func RegisterGraphqlServer(websrv *web.Server, servers ...*gqlgen.Server) error

RegisterGraphqlServer is a builder for initializing graphql servers, initialize order is based on the router group order.

func RegisterMiddleware

func RegisterMiddleware() web.Option

RegisterMiddleware register a middleware to web server

func RegisterSchema

func RegisterSchema(websrv *web.Server, schemas ...graphql.ExecutableSchema) (ss []*gqlgen.Server, err error)

RegisterSchema is builder for initializing graphql schemas, initialize order is based on the router group order. graphql middleware must registry to web server first though web.RegisterMiddleware(gql.New())

it graphql pkg handler.NewDefaultServer to create a graphql server

func WrapOperationHandler

func WrapOperationHandler(handlerFunc gin.HandlerFunc) graphql.OperationMiddleware

WrapOperationHandler wrap gin.HandlerFunc to graphql.OperationMiddleware

func WrapResponseHandler

func WrapResponseHandler(handlerFunc gin.HandlerFunc) graphql.ResponseMiddleware

WrapResponseHandler wrap gin.HandlerFunc to graphql.ResponseHandler

Types

type Handler

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

Handler for graphql.

While Subscription, response flow is defference from query or mutation.

func New

func New() *Handler

New create a graphql handler for middleware register

func (*Handler) ApplyFunc

func (h *Handler) ApplyFunc(cfg *conf.Configuration) gin.HandlerFunc

ApplyFunc is middleware for gin. it seeks the global authorization first, New one if not found.

func (*Handler) Name

func (h *Handler) Name() string

type Options

type Options struct {
	// QueryPath is the path to register the graphql handler.default is "POST /query"
	QueryPath string `yaml:"queryPath" json:"queryPath"`
	// WebSocketPath is the path to register the websocket handler.default is "GET /query"
	WebSocketPath string `yaml:"webSocketPath" json:"webSocketPath"`
	// DocPath is the path to register the playground handler.default is "GET /".
	// If it is empty, the playground will not be registered.
	DocPath string `yaml:"docPath" json:"docPath"`
	// Group is used to be found the matching group router, it must the same as the base path of a route group.
	Group string `yaml:"group" json:"group"`
	// Endpoint is the URL to send GraphQL requests to in the playground.
	Endpoint string `yaml:"endpoint" json:"endpoint"`
	// DocHeader is the header to send GraphQL requests to in the playground.
	DocHeader map[string]string `yaml:"header" json:"header"`
	// WithAuthorization indicates whether parse graphql operations to resource-action data for default authorization.
	//
	// if you want to use custom authorization, you can set it to false, then after RegisterSchema returns the graphql server,
	// Example:
	//
	//   gqlServers,_ := gql.RegisterSchema(router, schema1, schema2)
	//   gqlServers[0].AroundOperations(func(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {....})
	//
	// Notice: gin.engine.contextWithFallback must be true while using authorization
	WithAuthorization bool `yaml:"withAuthorization" json:"withAuthorization"`
	// AppCode is used to be found the matching app code in the authorization configuration.
	AppCode string `yaml:"appCode" json:"appCode"`
	// use woocoo web handler as graphql OperationHandler Middlewares and ResponseHandler Middlewares
	// Example:
	//
	//  middlewares:
	//    response:
	//      - jwt: ...
	//    operation:
	//      - tenant: ...
	//
	Middlewares map[string]any `yaml:"middlewares" json:"middlewares"`
	// contains filtered or unexported fields
}

Options handler option

Jump to

Keyboard shortcuts

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