Documentation
¶
Overview ¶
Package graphqlhandler evaluates and execute GraphQL requests to the remote server.
Index ¶
- Constants
- Variables
- func NewGraphQLHandler(operation *highv3.Operation, rawProxyAction *yaml.Node, ...) (proxyhandler.ProxyHandler, error)
- type GraphQLHandler
- func (ge *GraphQLHandler) Handle(ctx context.Context, request *proxyhandler.Request, ...) (*http.Response, any, error)
- func (ge *GraphQLHandler) Stream(ctx context.Context, request *proxyhandler.Request, writer http.ResponseWriter, ...) (*http.Response, error)
- func (*GraphQLHandler) Type() proxyhandler.ProxyActionType
- type GraphQLRequestBody
- type HTTPErrorMappingConfig
- type ProxyCustomGraphQLResponseConfig
- type ProxyGraphQLActionConfig
- type ProxyGraphQLRequestConfig
Constants ¶
const ProxyTypeGraphQL proxyhandler.ProxyActionType = "graphql"
ProxyTypeGraphQL represents a constant value for GraphQL proxy action.
Variables ¶
var ( ErrProxyActionRequired = errors.New("proxy action of GraphQL type must exist") ErrInvalidRequestMethod = errors.New( "invalid GraphQL request method. Accept GET or POST", ) ErrGraphQLQueryEmpty = errors.New("query is required for graphql proxy") ErrGraphQLUnsupportedQueryBatch = errors.New("graphql query batch is not supported") )
Functions ¶
func NewGraphQLHandler ¶
func NewGraphQLHandler( operation *highv3.Operation, rawProxyAction *yaml.Node, options *proxyhandler.NewProxyHandlerOptions, ) (proxyhandler.ProxyHandler, error)
NewGraphQLHandler creates a GraphQL request from operation.
Types ¶
type GraphQLHandler ¶
type GraphQLHandler struct {
// contains filtered or unexported fields
}
GraphQLHandler implements the ProxyHandler interface for GraphQL proxy.
func ValidateGraphQLString ¶
func ValidateGraphQLString(query string) (*GraphQLHandler, error)
ValidateGraphQLString parses and validates the GraphQL query string.
func (*GraphQLHandler) Handle ¶
func (ge *GraphQLHandler) Handle( ctx context.Context, request *proxyhandler.Request, options *proxyhandler.ProxyHandleOptions, ) (*http.Response, any, error)
Handle resolves the HTTP request and proxies that request to the remote server.
func (*GraphQLHandler) Stream ¶
func (ge *GraphQLHandler) Stream( ctx context.Context, request *proxyhandler.Request, writer http.ResponseWriter, options *proxyhandler.ProxyHandleOptions, ) (*http.Response, error)
Stream resolves the HTTP request and proxies that request to the remote server. The response is a stream.
func (*GraphQLHandler) Type ¶
func (*GraphQLHandler) Type() proxyhandler.ProxyActionType
Type returns type of the current handler.
type GraphQLRequestBody ¶
type GraphQLRequestBody struct {
Query string `json:"query"`
OperationName string `json:"operationName,omitempty"`
Variables map[string]any `json:"variables,omitempty"`
Extensions map[string]any `json:"extensions,omitempty"`
}
GraphQLRequestBody represents a request body to a GraphQL server.
type HTTPErrorMappingConfig ¶
type HTTPErrorMappingConfig struct{}
type ProxyCustomGraphQLResponseConfig ¶
type ProxyCustomGraphQLResponseConfig struct {
// The default HTTP error code will be used if the response body has errors.
// If not set, forward the HTTP status from the upstream response which is usually 200 OK.
HTTPErrorCode *int `json:"httpErrorCode,omitempty" yaml:"httpErrorCode,omitempty" jsonschema:"minimum=400,maximum=599,default=400"`
// Evaluation rules to map GraphQL errors to desired HTTP status codes.
HTTPErrors map[string][]string `json:"httpErrors,omitempty" yaml:"httpErrors,omitempty"`
// Configurations for transforming response data.
Body *gotransform.TemplateTransformerConfig `json:"body,omitempty" yaml:"body,omitempty"`
}
ProxyCustomGraphQLResponseConfig represents configurations for the proxy response.
func (ProxyCustomGraphQLResponseConfig) IsZero ¶
func (conf ProxyCustomGraphQLResponseConfig) IsZero() bool
IsZero checks if the configuration is empty.
type ProxyGraphQLActionConfig ¶
type ProxyGraphQLActionConfig struct {
// Type of the proxy action which is always graphql.
Type proxyhandler.ProxyActionType `json:"type" yaml:"type" jsonschema:"enum=graphql"`
// Configurations for the GraphQL proxy request.
Request *ProxyGraphQLRequestConfig `json:"request,omitempty" yaml:"request,omitempty"`
// Configurations for evaluating graphql responses.
Response *ProxyCustomGraphQLResponseConfig `json:"response,omitempty" yaml:"response,omitempty"`
}
ProxyGraphQLActionConfig represents a proxy action config for GraphQL.
type ProxyGraphQLRequestConfig ¶
type ProxyGraphQLRequestConfig struct {
// Overrides the request URL. Use the original request path if empty.
URL string `json:"url,omitempty" yaml:"url,omitempty"`
// Indicate the request method. The default method is POST.
Method string `json:"method,omitempty" yaml:"method,omitempty" jsonschema:"enum=GET,enum=POST,default=POST"`
// The configuration to transform request headers.
Headers map[string]jmes.FieldMappingEntryStringConfig `json:"headers,omitempty" yaml:"headers,omitempty"`
// GraphQL query to be sent.
Query string `json:"query" yaml:"query"`
// Definition of GraphQL variables.
Variables map[string]jmes.FieldMappingEntryConfig `json:"variables,omitempty" yaml:"variables,omitempty"`
// Definition of GraphQL extensions.
Extensions map[string]jmes.FieldMappingEntryConfig `json:"extensions,omitempty" yaml:"extensions,omitempty"`
}
ProxyGraphQLRequestConfig represents configurations for the proxy request.