plan

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 9 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
	Schema               string
}

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 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) *Planner

func (*Planner) Plan

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

func (*Planner) SetConfig

func (p *Planner) SetConfig(config Configuration)

type PlannerFactory

type PlannerFactory interface {
	Planner() DataSourcePlanner
}

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