plan

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzePlanKind

func AnalyzePlanKind(operation, definition *ast.Document, operationName string) (subscription, streaming bool, error error)

Types

type ArgumentConfiguration

type ArgumentConfiguration struct {
	Name       string
	SourceType SourceType
	SourcePath []string
}

type ArgumentsConfigurations

type ArgumentsConfigurations []ArgumentConfiguration

func (ArgumentsConfigurations) ForName

type Configuration

type Configuration struct {
	DefaultFlushInterval int64
	DataSources          []DataSourceConfiguration
	Fields               FieldConfigurations
}

type DataSourceConfiguration

type DataSourceConfiguration struct {
	RootNodes  []TypeField
	ChildNodes []TypeField
	Factory    PlannerFactory
	Custom     json.RawMessage
}

func (*DataSourceConfiguration) HasRootNode

func (d *DataSourceConfiguration) HasRootNode(typeName, fieldName string) bool

type DataSourcePlanner

type DataSourcePlanner interface {
	Register(visitor *Visitor, customConfiguration json.RawMessage, isNested bool) error
	ConfigureFetch() FetchConfiguration
	ConfigureSubscription() SubscriptionConfiguration
	DataSourcePlanningBehavior() DataSourcePlanningBehavior
	// DownstreamResponseFieldAlias allows the DataSourcePlanner to overwrite the response path with an alias
	// It's required to set OverrideFieldPathFromAlias to true
	// This function is useful in the following scenario
	// 1. The downstream Query doesn't contain an alias
	// 2. The path configuration rewrites the field to an existing field
	// 3. The DataSourcePlanner is using an alias to the upstream
	// Example:
	//
	// type Query {
	//		country: Country
	//		countryAlias: Country
	// }
	//
	// Both, country and countryAlias have a path in the FieldConfiguration of "country"
	// In theory, they would be treated as the same field
	// However, by using DownstreamResponseFieldAlias, it's possible for the DataSourcePlanner to use an alias for countryAlias.
	// In this case, the response would contain both, country and countryAlias fields in the response.
	// At the same time, the downstream Query would only expect the response on the path "country",
	// as both country and countryAlias have a mapping to the path "country".
	// The DataSourcePlanner could keep track that it rewrites the upstream query and use DownstreamResponseFieldAlias
	// to indicate to the Planner to expect the response for countryAlias on the path "countryAlias" instead of "country".
	DownstreamResponseFieldAlias(downstreamFieldRef int) (alias string, exists bool)
}

type DataSourcePlanningBehavior

type DataSourcePlanningBehavior struct {
	// MergeAliasedRootNodes will reuse a data source for multiple root fields with aliases if true.
	// Example:
	//  {
	//    rootField
	//    alias: rootField
	//  }
	// On dynamic data sources (e.g. GraphQL, SQL, ...) this should return true and for
	// static data sources (e.g. REST, static, GRPC...) it should be false.
	MergeAliasedRootNodes bool
	// OverrideFieldPathFromAlias will let the planner know if the response path should also be aliased (= true)
	// or not (= false)
	// Example:
	//  {
	//    rootField
	//    alias: original
	//  }
	// When true expected response will be { "rootField": ..., "alias": ... }
	// When false expected response will be { "rootField": ..., "original": ... }
	OverrideFieldPathFromAlias bool
}

type FetchConfiguration

type FetchConfiguration struct {
	Input                string
	Variables            resolve.Variables
	DataSource           resolve.DataSource
	DisallowSingleFlight bool
}

type FieldConfiguration

type FieldConfiguration struct {
	TypeName              string
	FieldName             string
	DisableDefaultMapping bool
	Path                  []string
	Arguments             ArgumentsConfigurations
	RequiresFields        []string
}

type FieldConfigurations

type FieldConfigurations []FieldConfiguration

func (FieldConfigurations) ForTypeField

func (f FieldConfigurations) ForTypeField(typeName, fieldName string) *FieldConfiguration

type FieldMapping

type FieldMapping struct {
	TypeName              string
	FieldName             string
	DisableDefaultMapping bool
	Path                  []string
}

type Kind

type Kind int
const (
	SynchronousResponseKind Kind = iota + 1
	StreamingResponseKind
	SubscriptionResponseKind
)

type LocalTypeFieldExtractor added in v1.14.0

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

LocalTypeFieldExtractor takes an ast.Document as input and generates the TypeField configuration for both root fields & child fields If a type is a federation entity (annotated with @key directive) and a field is is extended, this field will be skipped so that only "local" fields will be generated

func NewLocalTypeFieldExtractor added in v1.14.0

func NewLocalTypeFieldExtractor(document *ast.Document) *LocalTypeFieldExtractor

func (*LocalTypeFieldExtractor) GetAllNodes added in v1.14.0

func (e *LocalTypeFieldExtractor) GetAllNodes() (rootNodes, childNodes []TypeField)

GetAllNodes returns all Root- & ChildNodes

type Plan

type Plan interface {
	PlanKind() Kind
	SetFlushInterval(interval int64)
}

type Planner

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

func NewPlanner

func NewPlanner(config Configuration, closer <-chan struct{}) *Planner

NewPlanner creates a new Planner from the Configuration as well as the resolve.Closer The resolve.Closer will be closed when the engine is no longer being used. This allows all stateful DataSources to shutdown and cleanup their memory.

func (*Planner) Plan

func (p *Planner) Plan(operation, definition *ast.Document, operationName string, report *operationreport.Report) (plan Plan)

func (*Planner) SetCloser added in v1.19.1

func (p *Planner) SetCloser(closer <-chan struct{})

func (*Planner) SetConfig

func (p *Planner) SetConfig(config Configuration)

type PlannerFactory

type PlannerFactory interface {
	// Planner should return the DataSourcePlanner
	// closer is the closing channel for all stateful DataSources
	// At runtime, the Execution Engine will be instantiated with one global resolve.Closer.
	// Once the Closer gets closed, all stateful DataSources must close their connections and cleanup themselves.
	// They can do so by starting a goroutine on instantiation time that blocking reads on the resolve.Closer.
	// Once the Closer emits the close event, they have to terminate (e.g. close database connections).
	Planner(closer <-chan struct{}) DataSourcePlanner
}

type RequiredFieldExtractor added in v1.14.0

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

RequiredFieldExtractor extracts all required fields from an ast.Document containing a parsed federation subgraph SDL by visiting the directives specified in the federation specification and extracting the required meta data

func NewRequiredFieldExtractor added in v1.14.0

func NewRequiredFieldExtractor(document *ast.Document) *RequiredFieldExtractor

func (*RequiredFieldExtractor) GetAllRequiredFields added in v1.14.0

func (f *RequiredFieldExtractor) GetAllRequiredFields() FieldConfigurations

type SourceType

type SourceType string
const (
	ObjectFieldSource   SourceType = "object_field"
	FieldArgumentSource SourceType = "field_argument"
)

type StreamingResponsePlan

type StreamingResponsePlan struct {
	Response      resolve.GraphQLStreamingResponse
	FlushInterval int64
}

func (*StreamingResponsePlan) PlanKind

func (_ *StreamingResponsePlan) PlanKind() Kind

func (*StreamingResponsePlan) SetFlushInterval

func (s *StreamingResponsePlan) SetFlushInterval(interval int64)

type SubscriptionConfiguration

type SubscriptionConfiguration struct {
	Input                 string
	SubscriptionManagerID string
	Variables             resolve.Variables
}

type SubscriptionResponsePlan

type SubscriptionResponsePlan struct {
	Response      resolve.GraphQLSubscription
	FlushInterval int64
}

func (*SubscriptionResponsePlan) PlanKind

func (_ *SubscriptionResponsePlan) PlanKind() Kind

func (*SubscriptionResponsePlan) SetFlushInterval

func (s *SubscriptionResponsePlan) SetFlushInterval(interval int64)

type SynchronousResponsePlan

type SynchronousResponsePlan struct {
	Response      *resolve.GraphQLResponse
	FlushInterval int64
}

func (*SynchronousResponsePlan) PlanKind

func (_ *SynchronousResponsePlan) PlanKind() Kind

func (*SynchronousResponsePlan) SetFlushInterval

func (s *SynchronousResponsePlan) SetFlushInterval(interval int64)

type TypeField

type TypeField struct {
	TypeName   string
	FieldNames []string
}

type Visitor

type Visitor struct {
	Operation, Definition *ast.Document
	Walker                *astvisitor.Walker
	Importer              astimport.Importer
	Config                Configuration

	OperationName string
	// contains filtered or unexported fields
}

func (*Visitor) AllowVisitor

func (v *Visitor) AllowVisitor(kind astvisitor.VisitorKind, ref int, visitor interface{}) bool

func (*Visitor) EnterDirective

func (v *Visitor) EnterDirective(ref int)

func (*Visitor) EnterDocument

func (v *Visitor) EnterDocument(operation, definition *ast.Document)

func (*Visitor) EnterField

func (v *Visitor) EnterField(ref int)

func (*Visitor) EnterOperationDefinition

func (v *Visitor) EnterOperationDefinition(ref int)

func (*Visitor) EnterSelectionSet

func (v *Visitor) EnterSelectionSet(ref int)

func (*Visitor) LeaveDocument

func (v *Visitor) LeaveDocument(operation, definition *ast.Document)

func (*Visitor) LeaveField

func (v *Visitor) LeaveField(ref int)

func (*Visitor) LeaveSelectionSet

func (v *Visitor) LeaveSelectionSet(ref int)

Jump to

Keyboard shortcuts

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