graphql

package
v2.0.0-...-7724a3b Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 36 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// SubscriptionTypeUnknown is for unknown or undefined subscriptions.
	SubscriptionTypeUnknown = iota
	// SubscriptionTypeSSE is for Server-Sent Events (SSE) subscriptions.
	SubscriptionTypeSSE
	// SubscriptionTypeGraphQLWS is for subscriptions using a WebSocket connection with
	// 'graphql-ws' as protocol.
	SubscriptionTypeGraphQLWS
	// SubscriptionTypeGraphQLTransportWS is for subscriptions using a WebSocket connection with
	// 'graphql-transport-ws' as protocol.
	SubscriptionTypeGraphQLTransportWS
)
View Source
const (
	DefaultFlushIntervalInMilliseconds = 1000
)

Variables

View Source
var (
	ErrEmptyRequest = errors.New("the provided request is empty")
	ErrNilSchema    = errors.New("the provided schema is nil")
)
View Source
var DefaultComplexityCalculator = defaultComplexityCalculator{}
View Source
var (
	ErrRequiredStagesMissing = errors.New("required stages for custom execution engine v2 are missing")
)

Functions

func CreateTypeFieldArgumentsLookupMap

func CreateTypeFieldArgumentsLookupMap(typeFieldArgs []TypeFieldArguments) map[TypeFieldLookupKey]TypeFieldArguments

func MarshalRequest

func MarshalRequest(graphqlRequest Request) ([]byte, error)

func MarshalRequestString

func MarshalRequestString(graphqlRequest Request) (string, error)

func UnmarshalHttpRequest

func UnmarshalHttpRequest(r *http.Request, request *Request) error

func UnmarshalRequest

func UnmarshalRequest(reader io.Reader, request *Request) error

Types

type ComplexityCalculator

type ComplexityCalculator interface {
	Calculate(operation, definition *ast.Document) (ComplexityResult, error)
}

type ComplexityResult

type ComplexityResult struct {
	NodeCount    int
	Complexity   int
	Depth        int
	PerRootField []FieldComplexityResult
	Errors       Errors
}

type CustomExecutionEngineV2Executor

type CustomExecutionEngineV2Executor struct {
	ExecutionStages CustomExecutionEngineV2Stages
	// contains filtered or unexported fields
}

func NewCustomExecutionEngineV2Executor

func NewCustomExecutionEngineV2Executor(executionEngineV2 CustomExecutionEngineV2) (*CustomExecutionEngineV2Executor, error)

func NewCustomExecutionEngineV2ExecutorByStages

func NewCustomExecutionEngineV2ExecutorByStages(executionStages CustomExecutionEngineV2Stages) (*CustomExecutionEngineV2Executor, error)

func (*CustomExecutionEngineV2Executor) Execute

type CustomExecutionEngineV2InputValidationStage

type CustomExecutionEngineV2InputValidationStage interface {
	InputValidation(operation *Request) error
}

type CustomExecutionEngineV2NormalizerStage

type CustomExecutionEngineV2NormalizerStage interface {
	Normalize(operation *Request) error
}

type CustomExecutionEngineV2OptionalStages

type CustomExecutionEngineV2OptionalStages struct {
	NormalizerStage      CustomExecutionEngineV2NormalizerStage
	ValidatorStage       CustomExecutionEngineV2ValidatorStage
	InputValidationStage CustomExecutionEngineV2InputValidationStage
}

type CustomExecutionEngineV2RequiredStages

type CustomExecutionEngineV2RequiredStages struct {
	ResolverStage CustomExecutionEngineV2ResolverStage
}

type CustomExecutionEngineV2ResolverStage

type CustomExecutionEngineV2ResolverStage interface {
	Setup(ctx context.Context, postProcessor *postprocess.Processor, resolveContext *resolve.Context, operation *Request, options ...ExecutionOptionsV2)
	Plan(postProcessor *postprocess.Processor, operation *Request, report *operationreport.Report) (plan.Plan, error)
	Resolve(resolveContext *resolve.Context, planResult plan.Plan, writer resolve.SubscriptionResponseWriter) error
	Teardown()
}

type CustomExecutionEngineV2Stages

type CustomExecutionEngineV2Stages struct {
	RequiredStages CustomExecutionEngineV2RequiredStages
	OptionalStages *CustomExecutionEngineV2OptionalStages
}

func (*CustomExecutionEngineV2Stages) AllRequiredStagesProvided

func (c *CustomExecutionEngineV2Stages) AllRequiredStagesProvided() bool

type CustomExecutionEngineV2ValidatorStage

type CustomExecutionEngineV2ValidatorStage interface {
	ValidateForSchema(operation *Request) error
}

type DataSourceV2GeneratorOption

type DataSourceV2GeneratorOption func(options *dataSourceV2GeneratorOptions)

func WithDataSourceV2GeneratorSubscriptionConfiguration

func WithDataSourceV2GeneratorSubscriptionConfiguration(streamingClient *http.Client, subscriptionType SubscriptionType) DataSourceV2GeneratorOption

type DefaultFieldsValidator

type DefaultFieldsValidator struct {
}

func (DefaultFieldsValidator) Validate deprecated

func (d DefaultFieldsValidator) Validate(request *Request, schema *Schema, restrictions []Type) (RequestFieldsValidationResult, error)

Validate validates a request by checking if `restrictions` contains blocked fields.

Deprecated: This function can only handle blocked fields. Use `ValidateByFieldList` if you want to check for blocked or allowed fields instead.

func (DefaultFieldsValidator) ValidateByFieldList

func (d DefaultFieldsValidator) ValidateByFieldList(request *Request, schema *Schema, restrictionList FieldRestrictionList) (RequestFieldsValidationResult, error)

ValidateByFieldList will validate a request by using a list of allowed or blocked fields.

type EngineResultWriter

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

func NewEngineResultWriter

func NewEngineResultWriter() EngineResultWriter

func NewEngineResultWriterFromBuffer

func NewEngineResultWriterFromBuffer(buf *bytes.Buffer) EngineResultWriter

func (*EngineResultWriter) AsHTTPResponse

func (e *EngineResultWriter) AsHTTPResponse(status int, headers http.Header) *http.Response

func (*EngineResultWriter) Bytes

func (e *EngineResultWriter) Bytes() []byte

func (*EngineResultWriter) Complete

func (e *EngineResultWriter) Complete()

func (*EngineResultWriter) Flush

func (e *EngineResultWriter) Flush()

func (*EngineResultWriter) Len

func (e *EngineResultWriter) Len() int

func (*EngineResultWriter) Read

func (e *EngineResultWriter) Read(p []byte) (n int, err error)

func (*EngineResultWriter) Reset

func (e *EngineResultWriter) Reset()

func (*EngineResultWriter) SetFlushCallback

func (e *EngineResultWriter) SetFlushCallback(flushCb func(data []byte))

func (*EngineResultWriter) String

func (e *EngineResultWriter) String() string

func (*EngineResultWriter) Write

func (e *EngineResultWriter) Write(p []byte) (n int, err error)

type EngineV2Configuration

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

func NewEngineV2Configuration

func NewEngineV2Configuration(schema *Schema) EngineV2Configuration

func (*EngineV2Configuration) AddDataSource

func (e *EngineV2Configuration) AddDataSource(dataSource plan.DataSourceConfiguration)

func (*EngineV2Configuration) AddFieldConfiguration

func (e *EngineV2Configuration) AddFieldConfiguration(fieldConfig plan.FieldConfiguration)

func (*EngineV2Configuration) DataSources

func (*EngineV2Configuration) EnableSingleFlight

func (e *EngineV2Configuration) EnableSingleFlight(enable bool)

func (*EngineV2Configuration) FieldConfigurations

func (e *EngineV2Configuration) FieldConfigurations() plan.FieldConfigurations

func (*EngineV2Configuration) SetCustomResolveMap

func (e *EngineV2Configuration) SetCustomResolveMap(customResolveMap map[string]resolve.CustomResolve)

func (*EngineV2Configuration) SetDataSources

func (e *EngineV2Configuration) SetDataSources(dataSources []plan.DataSourceConfiguration)

func (*EngineV2Configuration) SetFieldConfigurations

func (e *EngineV2Configuration) SetFieldConfigurations(fieldConfigs plan.FieldConfigurations)

func (*EngineV2Configuration) SetWebsocketBeforeStartHook

func (e *EngineV2Configuration) SetWebsocketBeforeStartHook(hook WebsocketBeforeStartHook)

SetWebsocketBeforeStartHook - sets before start hook which will be called before processing any operation sent over websockets

type ErrorPath

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

func (*ErrorPath) Len

func (e *ErrorPath) Len() int

func (*ErrorPath) MarshalJSON

func (e *ErrorPath) MarshalJSON() ([]byte, error)

func (*ErrorPath) String

func (e *ErrorPath) String() string

type Errors

type Errors interface {
	error
	WriteResponse(writer io.Writer) (n int, err error)
	Count() int
	ErrorByIndex(i int) error
}

type ExecutionEngineV2

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

func NewExecutionEngineV2

func NewExecutionEngineV2(ctx context.Context, logger abstractlogger.Logger, engineConfig EngineV2Configuration) (*ExecutionEngineV2, error)

func (*ExecutionEngineV2) Execute

func (e *ExecutionEngineV2) Execute(ctx context.Context, operation *Request, writer resolve.SubscriptionResponseWriter, options ...ExecutionOptionsV2) error

func (*ExecutionEngineV2) GetWebsocketBeforeStartHook

func (e *ExecutionEngineV2) GetWebsocketBeforeStartHook() WebsocketBeforeStartHook

func (*ExecutionEngineV2) InputValidation

func (e *ExecutionEngineV2) InputValidation(operation *Request) error

func (*ExecutionEngineV2) Normalize

func (e *ExecutionEngineV2) Normalize(operation *Request) error

func (*ExecutionEngineV2) Plan

func (e *ExecutionEngineV2) Plan(postProcessor *postprocess.Processor, operation *Request, report *operationreport.Report) (plan.Plan, error)

func (*ExecutionEngineV2) Resolve

func (e *ExecutionEngineV2) Resolve(resolveContext *resolve.Context, planResult plan.Plan, writer resolve.SubscriptionResponseWriter) error

func (*ExecutionEngineV2) Setup

func (e *ExecutionEngineV2) Setup(ctx context.Context, postProcessor *postprocess.Processor, resolveContext *resolve.Context, operation *Request, options ...ExecutionOptionsV2)

func (*ExecutionEngineV2) Teardown

func (e *ExecutionEngineV2) Teardown()

func (*ExecutionEngineV2) ValidateForSchema

func (e *ExecutionEngineV2) ValidateForSchema(operation *Request) error

type ExecutionEngineV2Executor

type ExecutionEngineV2Executor interface {
	Execute(ctx context.Context, operation *Request, writer resolve.SubscriptionResponseWriter, options ...ExecutionOptionsV2) error
}

type ExecutionOptionsV2

type ExecutionOptionsV2 func(postProcessor *postprocess.Processor, resolveContext *resolve.Context)

func WithAdditionalHttpHeaders

func WithAdditionalHttpHeaders(headers http.Header, excludeByKeys ...string) ExecutionOptionsV2

func WithHeaderModifier

func WithHeaderModifier(modifier postprocess.HeaderModifier) ExecutionOptionsV2

func WithUpstreamHeaders

func WithUpstreamHeaders(header http.Header) ExecutionOptionsV2

type Extractor

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

func NewExtractor

func NewExtractor() *Extractor

func (*Extractor) ExtractFieldsFromRequest

func (e *Extractor) ExtractFieldsFromRequest(request *Request, schema *Schema, report *operationreport.Report, data RequestTypes)

func (*Extractor) ExtractFieldsFromRequestSingleOperation

func (e *Extractor) ExtractFieldsFromRequestSingleOperation(request *Request, schema *Schema, report *operationreport.Report, data RequestTypes)

type FederationEngineConfigFactory

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

FederationEngineConfigFactory is used to create a v2 engine config for a supergraph with multiple data sources for subgraphs.

func (*FederationEngineConfigFactory) EngineV2Configuration

func (f *FederationEngineConfigFactory) EngineV2Configuration() (conf EngineV2Configuration, err error)

func (*FederationEngineConfigFactory) MergedSchema

func (f *FederationEngineConfigFactory) MergedSchema() (*Schema, error)

func (*FederationEngineConfigFactory) SetMergedSchemaFromString

func (f *FederationEngineConfigFactory) SetMergedSchemaFromString(mergedSchema string) (err error)

type FederationEngineConfigFactoryOption

type FederationEngineConfigFactoryOption func(options *federationEngineConfigFactoryOptions)

func WithCustomResolveMap

func WithCustomResolveMap(customResolveMap map[string]resolve.CustomResolve) FederationEngineConfigFactoryOption

func WithFederationHttpClient

func WithFederationHttpClient(client *http.Client) FederationEngineConfigFactoryOption

func WithFederationStreamingClient

func WithFederationStreamingClient(client *http.Client) FederationEngineConfigFactoryOption

func WithFederationSubscriptionType

func WithFederationSubscriptionType(subscriptionType SubscriptionType) FederationEngineConfigFactoryOption

type FieldComplexityResult

type FieldComplexityResult struct {
	TypeName   string
	FieldName  string
	Alias      string
	NodeCount  int
	Complexity int
	Depth      int
}

type FieldRestrictionList

type FieldRestrictionList struct {
	Kind  FieldRestrictionListKind
	Types []Type
}

type FieldRestrictionListKind

type FieldRestrictionListKind int
const (
	AllowList FieldRestrictionListKind = iota
	BlockList
)

type FieldRestrictionValidator

type FieldRestrictionValidator interface {
	ValidateByFieldList(request *Request, schema *Schema, restrictionList FieldRestrictionList) (RequestFieldsValidationResult, error)
}

type InputValidationResult

type InputValidationResult struct {
	Valid  bool
	Errors Errors
}

type NormalizationResult

type NormalizationResult struct {
	Successful bool
	Errors     Errors
}

type OperationType

type OperationType ast.OperationType

type ProxyEngineConfigFactory

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

ProxyEngineConfigFactory is used to create a v2 engine config with a single upstream and a single data source for this upstream.

func NewProxyEngineConfigFactory

func NewProxyEngineConfigFactory(schema *Schema, proxyUpstreamConfig ProxyUpstreamConfig, opts ...ProxyEngineConfigFactoryOption) *ProxyEngineConfigFactory

func (*ProxyEngineConfigFactory) EngineV2Configuration

func (p *ProxyEngineConfigFactory) EngineV2Configuration() (EngineV2Configuration, error)

type ProxyEngineConfigFactoryOption

type ProxyEngineConfigFactoryOption func(options *proxyEngineConfigFactoryOptions)

func WithProxyHttpClient

func WithProxyHttpClient(client *http.Client) ProxyEngineConfigFactoryOption

func WithProxyStreamingClient

func WithProxyStreamingClient(client *http.Client) ProxyEngineConfigFactoryOption

type ProxyUpstreamConfig

type ProxyUpstreamConfig struct {
	URL              string
	Method           string
	StaticHeaders    http.Header
	SubscriptionType SubscriptionType
}

ProxyUpstreamConfig holds configuration to configure a single data source to a single upstream.

type Request

type Request struct {
	OperationName string          `json:"operationName,omitempty"`
	Variables     json.RawMessage `json:"variables,omitempty"`
	Query         string          `json:"query"`
	// contains filtered or unexported fields
}

func (*Request) CalculateComplexity

func (r *Request) CalculateComplexity(complexityCalculator ComplexityCalculator, schema *Schema) (ComplexityResult, error)

func (*Request) IsIntrospectionQuery

func (r *Request) IsIntrospectionQuery() (result bool, err error)

func (*Request) IsIntrospectionQueryStrict

func (r *Request) IsIntrospectionQueryStrict() (result bool, err error)

IsIntrospectionQueryStrict returns true if the client tries to query __schema or __type fields in any way. IsIntrospectionQuery returns false if schema/type introspection query contains additional non-introspection fields. This breaks the granular access schema of Tyk Gateway.

func (*Request) IsNormalized

func (r *Request) IsNormalized() bool

func (*Request) Normalize

func (r *Request) Normalize(schema *Schema) (result NormalizationResult, err error)

func (*Request) OperationType

func (r *Request) OperationType() (OperationType, error)

func (Request) Print

func (r Request) Print(writer io.Writer) (n int, err error)

func (*Request) SetHeader

func (r *Request) SetHeader(header http.Header)

func (*Request) ValidateFieldRestrictions

func (r *Request) ValidateFieldRestrictions(schema *Schema, restrictedFieldsList FieldRestrictionList, validator FieldRestrictionValidator) (RequestFieldsValidationResult, error)

ValidateFieldRestrictions will validate a request by using a list of allowed or blocked fields.

func (*Request) ValidateForSchema

func (r *Request) ValidateForSchema(schema *Schema) (result ValidationResult, err error)

func (*Request) ValidateInput

func (r *Request) ValidateInput(schema *Schema) (InputValidationResult, error)

func (*Request) ValidateRestrictedFields deprecated

func (r *Request) ValidateRestrictedFields(schema *Schema, restrictedFields []Type) (RequestFieldsValidationResult, error)

ValidateRestrictedFields validates a request by checking if `restrictedFields` contains blocked fields.

Deprecated: This function can only handle blocked fields. Use `ValidateFieldRestrictions` if you want to check for blocked or allowed fields instead.

type RequestError

type RequestError struct {
	Message   string                   `json:"message"`
	Locations []graphqlerrors.Location `json:"locations,omitempty"`
	Path      ErrorPath                `json:"path"`
}

func (RequestError) Error

func (o RequestError) Error() string

func (RequestError) MarshalJSON

func (o RequestError) MarshalJSON() ([]byte, error)

type RequestErrors

type RequestErrors []RequestError

func RequestErrorsFromError

func RequestErrorsFromError(err error) RequestErrors

func RequestErrorsFromOperationReport

func RequestErrorsFromOperationReport(report operationreport.Report) (errors RequestErrors)

func (RequestErrors) Count

func (o RequestErrors) Count() int

func (RequestErrors) Error

func (o RequestErrors) Error() string

func (RequestErrors) ErrorByIndex

func (o RequestErrors) ErrorByIndex(i int) error

func (RequestErrors) WriteResponse

func (o RequestErrors) WriteResponse(writer io.Writer) (n int, err error)

type RequestFields

type RequestFields map[string]struct{}

type RequestFieldsValidationResult

type RequestFieldsValidationResult struct {
	Valid  bool
	Errors Errors
}

type RequestFieldsValidator

type RequestFieldsValidator interface {
	Validate(request *Request, schema *Schema, restrictions []Type) (RequestFieldsValidationResult, error)
}

type RequestTypes

type RequestTypes map[string]RequestFields

type Response

type Response struct {
	Errors Errors `json:"errors,omitempty"`
	Data   any    `json:"data"` // we add this here to ensure that "data":null is added to an error response
}

func (Response) Marshal

func (r Response) Marshal() ([]byte, error)

type Schema

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

func NewSchemaFromReader

func NewSchemaFromReader(reader io.Reader) (*Schema, error)

func NewSchemaFromString

func NewSchemaFromString(schema string) (*Schema, error)

func (*Schema) Document

func (s *Schema) Document() []byte

func (*Schema) GetAllFieldArguments

func (s *Schema) GetAllFieldArguments(skipFieldFuncs ...SkipFieldFunc) []TypeFieldArguments

func (*Schema) GetAllNestedFieldChildrenFromTypeField

func (s *Schema) GetAllNestedFieldChildrenFromTypeField(typeName string, fieldName string, skipFieldFuncs ...SkipFieldFunc) []TypeFields

func (*Schema) HasMutationType

func (s *Schema) HasMutationType() bool

func (*Schema) HasQueryType

func (s *Schema) HasQueryType() bool

HasQueryType TODO: should be deprecated?

func (*Schema) HasSubscriptionType

func (s *Schema) HasSubscriptionType() bool

func (*Schema) Hash

func (s *Schema) Hash() uint64

Hash returns the hash of the schema.

func (*Schema) Input

func (s *Schema) Input() []byte

func (*Schema) IsNormalized

func (s *Schema) IsNormalized() bool

func (*Schema) MutationTypeName

func (s *Schema) MutationTypeName() string

func (*Schema) Normalize

func (s *Schema) Normalize() (result NormalizationResult, err error)

func (*Schema) QueryTypeName

func (s *Schema) QueryTypeName() string

func (*Schema) SubscriptionTypeName

func (s *Schema) SubscriptionTypeName() string

func (*Schema) Validate

func (s *Schema) Validate() (result ValidationResult, err error)

type SchemaValidationError

type SchemaValidationError struct {
	Message string `json:"message"`
}

func (SchemaValidationError) Error

func (s SchemaValidationError) Error() string

type SchemaValidationErrors

type SchemaValidationErrors []SchemaValidationError

func (SchemaValidationErrors) Count

func (s SchemaValidationErrors) Count() int

func (SchemaValidationErrors) Error

func (s SchemaValidationErrors) Error() string

func (SchemaValidationErrors) ErrorByIndex

func (s SchemaValidationErrors) ErrorByIndex(i int) error

func (SchemaValidationErrors) WriteResponse

func (s SchemaValidationErrors) WriteResponse(writer io.Writer) (n int, err error)

type SkipFieldFunc

type SkipFieldFunc func(typeName, fieldName string, definition ast.Document) bool

func NewIsDataSourceConfigV2RootFieldSkipFunc

func NewIsDataSourceConfigV2RootFieldSkipFunc(dataSources []plan.DataSourceConfiguration) SkipFieldFunc

func NewSkipReservedNamesFunc

func NewSkipReservedNamesFunc() SkipFieldFunc

type SubscriptionType

type SubscriptionType int

type Type

type Type struct {
	Name   string   `json:"name"`
	Fields []string `json:"fields"`
}

type TypeFieldArguments

type TypeFieldArguments struct {
	TypeName      string
	FieldName     string
	ArgumentNames []string
}

type TypeFieldLookupKey

type TypeFieldLookupKey string

func CreateTypeFieldLookupKey

func CreateTypeFieldLookupKey(typeName string, fieldName string) TypeFieldLookupKey

type TypeFields

type TypeFields struct {
	TypeName   string
	FieldNames []string
}

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors Errors
}

func ValidateSchemaString

func ValidateSchemaString(schema string) (result ValidationResult, err error)

type WebsocketBeforeStartHook

type WebsocketBeforeStartHook interface {
	OnBeforeStart(reqCtx context.Context, operation *Request) error
}

Jump to

Keyboard shortcuts

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