resolve

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VariableRendererKindPlain                 = "plain"
	VariableRendererKindPlanWithValidation    = "plainWithValidation"
	VariableRendererKindJson                  = "json"
	VariableRendererKindJsonWithValidation    = "jsonWithValidation"
	VariableRendererKindGraphqlWithValidation = "graphqlWithValidation"
	VariableRendererKindGraphqlResolve        = "graphqlResolve"
	VariableRendererKindCsv                   = "csv"
)

Variables

View Source
var (
	ErrResolverClosed = errors.New("resolver closed")
)
View Source
var (
	ErrUnableToResolve = errors.New("unable to resolve operation")
)

Functions

func GetDurationNanoSinceTraceStart

func GetDurationNanoSinceTraceStart(ctx context.Context) int64

func SetInputUndefinedVariables

func SetInputUndefinedVariables(preparedInput *bytes.Buffer, undefinedVariables []string) error

func SetPlannerStats

func SetPlannerStats(ctx context.Context, stats PlannerStats)

func SetTraceStart

func SetTraceStart(ctx context.Context, predictableDebugTimings bool) context.Context

func SingleFlightDisallowed

func SingleFlightDisallowed(ctx context.Context) bool

Types

type Array

type Array struct {
	Path                []string
	Nullable            bool
	ResolveAsynchronous bool
	Item                Node
	Items               []Node
}

func (*Array) HasChildFetches

func (a *Array) HasChildFetches() bool

func (*Array) NodeKind

func (_ *Array) NodeKind() NodeKind

func (*Array) NodePath

func (a *Array) NodePath() []string

type BatchEntityFetch

type BatchEntityFetch struct {
	Input                BatchInput
	DataSource           DataSource
	PostProcessing       PostProcessingConfiguration
	DataSourceIdentifier []byte
	DisallowSingleFlight bool
	Trace                *DataSourceLoadTrace
	Info                 *FetchInfo
}

BatchEntityFetch - TODO: document better allows to join nested fetches to the same subgraph into a single fetch

func (*BatchEntityFetch) FetchKind

func (_ *BatchEntityFetch) FetchKind() FetchKind

type BatchInput

type BatchInput struct {
	Header InputTemplate
	Items  []InputTemplate
	// If SkipNullItems is set to true, items that render to null will not be included in the batch but skipped
	SkipNullItems bool
	// Same as SkipNullItems but for empty objects
	SkipEmptyObjectItems bool
	// If SkipErrItems is set to true, items that return an error during rendering will not be included in the batch but skipped
	// In this case, the error will be swallowed
	// E.g. if a field is not nullable and the value is null, the item will be skipped
	SkipErrItems bool
	Separator    InputTemplate
	Footer       InputTemplate
}

type BigInt

type BigInt struct {
	Path     []string
	Nullable bool
	Export   *FieldExport `json:"export,omitempty"`
}

func (*BigInt) NodeKind

func (_ *BigInt) NodeKind() NodeKind

func (*BigInt) NodePath

func (b *BigInt) NodePath() []string

type Boolean

type Boolean struct {
	Path     []string
	Nullable bool
	Export   *FieldExport `json:"export,omitempty"`
}

func (*Boolean) NodeKind

func (_ *Boolean) NodeKind() NodeKind

func (*Boolean) NodePath

func (b *Boolean) NodePath() []string

type BufPair

type BufPair struct {
	Data   *fastbuffer.FastBuffer
	Errors *fastbuffer.FastBuffer
}

func NewBufPair

func NewBufPair() *BufPair

func (*BufPair) HasData

func (b *BufPair) HasData() bool

func (*BufPair) HasErrors

func (b *BufPair) HasErrors() bool

func (*BufPair) Reset

func (b *BufPair) Reset()

func (*BufPair) WriteErr

func (b *BufPair) WriteErr(message, locations, path, extensions []byte)

type CSVVariableRenderer

type CSVVariableRenderer struct {
	Kind string
	// contains filtered or unexported fields
}

CSVVariableRenderer is an implementation of VariableRenderer It renders the provided list of Values as comma separated Values in plaintext (no JSON encoding of Values)

func NewCSVVariableRenderer

func NewCSVVariableRenderer(arrayValueType JsonRootType) *CSVVariableRenderer

func NewCSVVariableRendererFromTypeRef

func NewCSVVariableRendererFromTypeRef(operation, definition *ast.Document, variableTypeRef int) *CSVVariableRenderer

func (*CSVVariableRenderer) GetKind

func (c *CSVVariableRenderer) GetKind() string

func (*CSVVariableRenderer) RenderVariable

func (c *CSVVariableRenderer) RenderVariable(_ context.Context, data []byte, out io.Writer) error

type ConnectDoneStats

type ConnectDoneStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Network                  string `json:"network"`
	Addr                     string `json:"addr"`
	Err                      string `json:"err,omitempty"`
}

type ConnectStartStats

type ConnectStartStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Network                  string `json:"network"`
	Addr                     string `json:"addr"`
}

type Context

type Context struct {
	Variables             []byte
	Request               Request
	RenameTypeNames       []RenameTypeName
	RequestTracingOptions RequestTraceOptions
	InitialPayload        []byte
	Extensions            []byte
	Stats                 Stats
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context) *Context

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Free

func (c *Context) Free()

func (*Context) SubgraphErrors

func (c *Context) SubgraphErrors() error

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context) *Context

type ContextVariable

type ContextVariable struct {
	Path     []string
	Renderer VariableRenderer
}

func (*ContextVariable) Equals

func (c *ContextVariable) Equals(another Variable) bool

func (*ContextVariable) GetVariableKind

func (_ *ContextVariable) GetVariableKind() VariableKind

func (*ContextVariable) TemplateSegment

func (c *ContextVariable) TemplateSegment() TemplateSegment

type CustomNode

type CustomNode struct {
	CustomResolve
	Nullable bool
	Path     []string
}

func (*CustomNode) NodeKind

func (_ *CustomNode) NodeKind() NodeKind

func (*CustomNode) NodePath

func (c *CustomNode) NodePath() []string

type CustomResolve

type CustomResolve interface {
	Resolve(value []byte) ([]byte, error)
}

type DNSDoneStats

type DNSDoneStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
}

type DNSStartStats

type DNSStartStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Host                     string `json:"host"`
}

type DataSource

type DataSource interface {
	Load(ctx context.Context, input []byte, w io.Writer) (err error)
}

type DataSourceLoadTrace

type DataSourceLoadTrace struct {
	RawInputData               json.RawMessage `json:"raw_input_data,omitempty"`
	Input                      json.RawMessage `json:"input,omitempty"`
	Output                     json.RawMessage `json:"output,omitempty"`
	LoadError                  string          `json:"error,omitempty"`
	DurationSinceStartNano     int64           `json:"duration_since_start_nanoseconds,omitempty"`
	DurationSinceStartPretty   string          `json:"duration_since_start_pretty,omitempty"`
	DurationLoadNano           int64           `json:"duration_load_nanoseconds,omitempty"`
	DurationLoadPretty         string          `json:"duration_load_pretty,omitempty"`
	SingleFlightUsed           bool            `json:"single_flight_used"`
	SingleFlightSharedResponse bool            `json:"single_flight_shared_response"`
	LoadSkipped                bool            `json:"load_skipped"`
	LoadStats                  *LoadStats      `json:"load_stats,omitempty"`
	Path                       string          `json:"-"`
}

type DeferField

type DeferField struct{}

type EmptyArray

type EmptyArray struct{}

func (*EmptyArray) NodeKind

func (_ *EmptyArray) NodeKind() NodeKind

func (*EmptyArray) NodePath

func (_ *EmptyArray) NodePath() []string

type EmptyObject

type EmptyObject struct{}

func (*EmptyObject) NodeKind

func (_ *EmptyObject) NodeKind() NodeKind

func (*EmptyObject) NodePath

func (_ *EmptyObject) NodePath() []string

type EntityFetch

type EntityFetch struct {
	Input                EntityInput
	DataSource           DataSource
	PostProcessing       PostProcessingConfiguration
	DataSourceIdentifier []byte
	DisallowSingleFlight bool
	Trace                *DataSourceLoadTrace
	Info                 *FetchInfo
}

func (*EntityFetch) FetchKind

func (_ *EntityFetch) FetchKind() FetchKind

type EntityInput

type EntityInput struct {
	Header      InputTemplate
	Item        InputTemplate
	SkipErrItem bool
	Footer      InputTemplate
}

type Fetch

type Fetch interface {
	FetchKind() FetchKind
}

type FetchConfiguration

type FetchConfiguration struct {
	Input      string
	Variables  Variables
	DataSource DataSource
	// DisallowSingleFlight is used for write operations like mutations, POST, DELETE etc. to disable singleFlight
	// By default SingleFlight for fetches is disabled and needs to be enabled on the Resolver first
	// If the resolver allows SingleFlight it's up to each individual DataSource Planner to decide whether an Operation
	// should be allowed to use SingleFlight
	DisallowSingleFlight bool
	// RequiresSerialFetch is used to indicate that the single fetches should be executed serially
	// When we have multiple fetches attached to the object - after post-processing of a plan we will get SerialFetch instead of ParallelFetch
	RequiresSerialFetch bool
	// RequiresParallelListItemFetch is used to indicate that the single fetches should be executed without batching
	// When we have multiple fetches attached to the object - after post-processing of a plan we will get ParallelListItemFetch instead of ParallelFetch
	RequiresParallelListItemFetch bool
	// RequiresEntityFetch will be set to true if the fetch is an entity fetch on an object. After post-processing, we will get EntityFetch
	RequiresEntityFetch bool
	// RequiresEntityBatchFetch indicates that entity fetches on array items could be batched. After post-processing, we will get EntityBatchFetch
	RequiresEntityBatchFetch bool
	PostProcessing           PostProcessingConfiguration
	// SetTemplateOutputToNullOnVariableNull will safely return "null" if one of the template variables renders to null
	// This is the case, e.g. when using batching and one sibling is null, resulting in a null value for one batch item
	// Returning null in this case tells the batch implementation to skip this item
	SetTemplateOutputToNullOnVariableNull bool
}

type FetchInfo

type FetchInfo struct {
	DataSourceID string
}

type FetchKind

type FetchKind int
const (
	FetchKindSingle FetchKind = iota + 1
	FetchKindParallel
	FetchKindSerial
	FetchKindParallelListItem
	FetchKindEntity
	FetchKindEntityBatch
)

type Fetches

type Fetches []Fetch

type Field

type Field struct {
	Name                    []byte
	Value                   Node
	Position                Position
	Defer                   *DeferField
	Stream                  *StreamField
	OnTypeNames             [][]byte
	SkipDirectiveDefined    bool
	SkipVariableName        string
	IncludeDirectiveDefined bool
	IncludeVariableName     string
	Info                    *FieldInfo
}

type FieldExport

type FieldExport struct {
	Path     []string
	AsString bool
}

FieldExport takes the value of the field during evaluation (rendering of the field) and stores it in the variables using the Path as JSON pointer.

type FieldInfo

type FieldInfo struct {
	// Name is the name of the field.
	Name string
	// ParentTypeNames is the list of possible parent types for this field.
	// E.g. for a root field, this will be Query, Mutation, Subscription.
	// For a field on an object type, this will be the name of that object type.
	// For a field on an interface type, this will be the name of that interface type and all of its possible implementations.
	ParentTypeNames []string
	// NamedType is the underlying node type of the field.
	// E.g. for a field of type Hobby! this will be Hobby.
	// For a field of type [Hobby] this will be Hobby.
	// For a field of type [Hobby!]! this will be Hobby.
	// For scalar fields, this will return string, int, float, boolean, ID.
	NamedType string
	Source    TypeFieldSource
}

func (*FieldInfo) Merge

func (i *FieldInfo) Merge(other *FieldInfo)

type Float

type Float struct {
	Path     []string
	Nullable bool
	Export   *FieldExport `json:"export,omitempty"`
}

func (*Float) NodeKind

func (_ *Float) NodeKind() NodeKind

func (*Float) NodePath

func (f *Float) NodePath() []string

type GetConnStats

type GetConnStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	HostPort                 string `json:"host_port"`
}

type GotConnStats

type GotConnStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Reused                   bool   `json:"reused"`
	WasIdle                  bool   `json:"was_idle"`
	IdleTimeNano             int64  `json:"idle_time_nanoseconds"`
	IdleTimePretty           string `json:"idle_time_pretty"`
}

type GotFirstResponseByteStats

type GotFirstResponseByteStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
}

type GraphQLResponse

type GraphQLResponse struct {
	Data            *Object
	RenameTypeNames []RenameTypeName
	Info            *GraphQLResponseInfo
}

type GraphQLResponseInfo

type GraphQLResponseInfo struct {
	OperationType ast.OperationType
}

type GraphQLSubscription

type GraphQLSubscription struct {
	Trigger  GraphQLSubscriptionTrigger
	Response *GraphQLResponse
}

type GraphQLSubscriptionTrigger

type GraphQLSubscriptionTrigger struct {
	Input          []byte
	InputTemplate  InputTemplate
	Variables      Variables
	Source         SubscriptionDataSource
	PostProcessing PostProcessingConfiguration
}

type GraphQLVariableRenderer

type GraphQLVariableRenderer struct {
	JSONSchema string
	Kind       string
	// contains filtered or unexported fields
}

GraphQLVariableRenderer is an implementation of VariableRenderer It renders variables according to the GraphQL Specification

func NewGraphQLVariableRenderer

func NewGraphQLVariableRenderer(jsonSchema string) *GraphQLVariableRenderer

NewGraphQLVariableRenderer - to be used in tests only

func NewGraphQLVariableRendererFromJSONRootTypeWithoutValidation

func NewGraphQLVariableRendererFromJSONRootTypeWithoutValidation(rootType JsonRootType) (*GraphQLVariableRenderer, error)

NewGraphQLVariableRendererFromJSONRootTypeWithoutValidation - to be used in tests only

func NewGraphQLVariableRendererFromTypeRef

func NewGraphQLVariableRendererFromTypeRef(operation, definition *ast.Document, variableTypeRef int) (*GraphQLVariableRenderer, error)

NewGraphQLVariableRendererFromTypeRef creates a new GraphQLVariableRenderer The argument typeRef must exist on the operation ast.Document, otherwise it will panic!

func NewGraphQLVariableRendererFromTypeRefWithOverrides

func NewGraphQLVariableRendererFromTypeRefWithOverrides(operation, definition *ast.Document, variableTypeRef int, overrides map[string]graphqljsonschema.JsonSchema) (*GraphQLVariableRenderer, error)

func NewGraphQLVariableRendererFromTypeRefWithoutValidation

func NewGraphQLVariableRendererFromTypeRefWithoutValidation(operation, definition *ast.Document, variableTypeRef int) (*GraphQLVariableRenderer, error)

func (*GraphQLVariableRenderer) GetKind

func (g *GraphQLVariableRenderer) GetKind() string

func (*GraphQLVariableRenderer) RenderVariable

func (g *GraphQLVariableRenderer) RenderVariable(ctx context.Context, data []byte, out io.Writer) error

type GraphQLVariableResolveRenderer

type GraphQLVariableResolveRenderer struct {
	Kind string
	Node Node
}

func NewGraphQLVariableResolveRenderer

func NewGraphQLVariableResolveRenderer(node Node) *GraphQLVariableResolveRenderer

func (*GraphQLVariableResolveRenderer) GetKind

func (*GraphQLVariableResolveRenderer) RenderVariable

func (g *GraphQLVariableResolveRenderer) RenderVariable(ctx context.Context, data []byte, out io.Writer) error

type HeaderVariable

type HeaderVariable struct {
	Path []string
}

func (*HeaderVariable) Equals

func (h *HeaderVariable) Equals(another Variable) bool

func (*HeaderVariable) GetVariableKind

func (h *HeaderVariable) GetVariableKind() VariableKind

func (*HeaderVariable) TemplateSegment

func (h *HeaderVariable) TemplateSegment() TemplateSegment

type InputTemplate

type InputTemplate struct {
	Segments []TemplateSegment
	// SetTemplateOutputToNullOnVariableNull will safely return "null" if one of the template variables renders to null
	// This is the case, e.g. when using batching and one sibling is null, resulting in a null value for one batch item
	// Returning null in this case tells the batch implementation to skip this item
	SetTemplateOutputToNullOnVariableNull bool
}

func (*InputTemplate) Render

func (i *InputTemplate) Render(ctx *Context, data []byte, preparedInput *bytes.Buffer) error

func (*InputTemplate) RenderAndCollectUndefinedVariables

func (i *InputTemplate) RenderAndCollectUndefinedVariables(ctx *Context, data []byte, preparedInput *bytes.Buffer, undefinedVariables *[]string) (err error)

type Integer

type Integer struct {
	Path     []string
	Nullable bool
	Export   *FieldExport `json:"export,omitempty"`
}

func (*Integer) NodeKind

func (_ *Integer) NodeKind() NodeKind

func (*Integer) NodePath

func (i *Integer) NodePath() []string

type JSONVariableRenderer

type JSONVariableRenderer struct {
	JSONSchema string
	Kind       string
	// contains filtered or unexported fields
}

JSONVariableRenderer is an implementation of VariableRenderer It renders the provided data as JSON If configured, it also does a JSON Validation Check before rendering

func NewJSONVariableRenderer

func NewJSONVariableRenderer() *JSONVariableRenderer

func NewJSONVariableRendererWithValidation

func NewJSONVariableRendererWithValidation(jsonSchema string) *JSONVariableRenderer

func NewJSONVariableRendererWithValidationFromTypeRef

func NewJSONVariableRendererWithValidationFromTypeRef(operation, definition *ast.Document, variableTypeRef int) (*JSONVariableRenderer, error)

NewJSONVariableRendererWithValidationFromTypeRef creates a new JSONVariableRenderer The argument typeRef must exist on the operation ast.Document, otherwise it will panic!

func (*JSONVariableRenderer) GetKind

func (r *JSONVariableRenderer) GetKind() string

func (*JSONVariableRenderer) RenderVariable

func (r *JSONVariableRenderer) RenderVariable(ctx context.Context, data []byte, out io.Writer) error

type JsonRootType

type JsonRootType struct {
	Value  jsonparser.ValueType
	Values []jsonparser.ValueType
	Kind   JsonRootTypeKind
}

func (JsonRootType) Satisfies

func (t JsonRootType) Satisfies(dataType jsonparser.ValueType) bool

type JsonRootTypeKind

type JsonRootTypeKind int
const (
	JsonRootTypeKindSingle JsonRootTypeKind = iota
	JsonRootTypeKindMultiple
)

type LoadStats

type LoadStats struct {
	GetConn              GetConnStats              `json:"get_conn"`
	GotConn              GotConnStats              `json:"got_conn"`
	GotFirstResponseByte GotFirstResponseByteStats `json:"got_first_response_byte"`
	DNSStart             DNSStartStats             `json:"dns_start"`
	DNSDone              DNSDoneStats              `json:"dns_done"`
	ConnectStart         ConnectStartStats         `json:"connect_start"`
	ConnectDone          ConnectDoneStats          `json:"connect_done"`
	TLSHandshakeStart    TLSHandshakeStartStats    `json:"tls_handshake_start"`
	TLSHandshakeDone     TLSHandshakeDoneStats     `json:"tls_handshake_done"`
	WroteHeaders         WroteHeadersStats         `json:"wrote_headers"`
	WroteRequest         WroteRequestStats         `json:"wrote_request"`
}

type Loader

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

func (*Loader) Free

func (l *Loader) Free()

func (*Loader) LoadGraphQLResponseData

func (l *Loader) LoadGraphQLResponseData(ctx *Context, response *GraphQLResponse, resolvable *Resolvable) (err error)

type Node

type Node interface {
	NodeKind() NodeKind
	NodePath() []string
}

type NodeKind

type NodeKind int
const (
	NodeKindObject NodeKind = iota + 1
	NodeKindEmptyObject
	NodeKindArray
	NodeKindEmptyArray
	NodeKindNull
	NodeKindString
	NodeKindBoolean
	NodeKindInteger
	NodeKindFloat
	NodeKindBigInt
	NodeKindCustom
	NodeKindScalar
)

type Null

type Null struct {
}

func (*Null) NodeKind

func (_ *Null) NodeKind() NodeKind

func (*Null) NodePath

func (_ *Null) NodePath() []string

type Object

type Object struct {
	Nullable             bool
	Path                 []string
	Fields               []*Field
	Fetch                Fetch
	UnescapeResponseJson bool `json:"unescape_response_json,omitempty"`
}

func (*Object) HasChildFetches

func (o *Object) HasChildFetches() bool

func (*Object) NodeKind

func (_ *Object) NodeKind() NodeKind

func (*Object) NodePath

func (o *Object) NodePath() []string

type ObjectVariable

type ObjectVariable struct {
	Path     []string
	Renderer VariableRenderer
}

func (*ObjectVariable) Equals

func (o *ObjectVariable) Equals(another Variable) bool

func (*ObjectVariable) GetVariableKind

func (o *ObjectVariable) GetVariableKind() VariableKind

func (*ObjectVariable) TemplateSegment

func (o *ObjectVariable) TemplateSegment() TemplateSegment

type ParallelFetch

type ParallelFetch struct {
	Fetches []Fetch
	Trace   *DataSourceLoadTrace
}

ParallelFetch - TODO: document better should be used only for object fields which could be fetched parallel

func (*ParallelFetch) FetchKind

func (_ *ParallelFetch) FetchKind() FetchKind

type ParallelListItemFetch

type ParallelListItemFetch struct {
	Fetch  *SingleFetch
	Traces []*SingleFetch
	Trace  *DataSourceLoadTrace
}

The ParallelListItemFetch can be used to make nested parallel fetches within a list Usually, you want to batch fetches within a list, which is the default behavior of SingleFetch However, if the data source does not support batching, you can use this fetch to make parallel fetches within a list

func (*ParallelListItemFetch) FetchKind

func (_ *ParallelListItemFetch) FetchKind() FetchKind

type PlainVariableRenderer

type PlainVariableRenderer struct {
	JSONSchema string
	Kind       string
	// contains filtered or unexported fields
}

PlainVariableRenderer is an implementation of VariableRenderer It renders the provided data as plain text E.g. a provided JSON string of "foo" will be rendered as foo, without quotes. If a nested JSON Object is provided, it will be rendered as is. This renderer can be used e.g. to render the provided scalar into a URL.

func NewPlainVariableRenderer

func NewPlainVariableRenderer() *PlainVariableRenderer

func NewPlainVariableRendererWithValidation

func NewPlainVariableRendererWithValidation(jsonSchema string) *PlainVariableRenderer

func NewPlainVariableRendererWithValidationFromTypeRef

func NewPlainVariableRendererWithValidationFromTypeRef(operation, definition *ast.Document, variableTypeRef int, variablePath ...string) (*PlainVariableRenderer, error)

NewPlainVariableRendererWithValidationFromTypeRef creates a new PlainVariableRenderer The argument typeRef must exist on the operation ast.Document, otherwise it will panic!

func (*PlainVariableRenderer) GetKind

func (p *PlainVariableRenderer) GetKind() string

func (*PlainVariableRenderer) RenderVariable

func (p *PlainVariableRenderer) RenderVariable(ctx context.Context, data []byte, out io.Writer) error

type PlannerStats

type PlannerStats struct {
	PlanningTimeNano         int64  `json:"planning_time_nanoseconds"`
	PlanningTimePretty       string `json:"planning_time_pretty"`
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
}

type Position

type Position struct {
	Line   uint32
	Column uint32
}

type PostProcessingConfiguration

type PostProcessingConfiguration struct {
	// SelectResponseDataPath used to make a jsonparser.Get call on the response data
	SelectResponseDataPath []string
	// SelectResponseErrorsPath is similar to SelectResponseDataPath, but for errors
	// If this is set, the response will be considered an error if the jsonparser.Get call returns a non-empty value
	// The value will be expected to be a GraphQL error object
	SelectResponseErrorsPath []string
	// ResponseTemplate is processed after the SelectResponseDataPath is applied
	// It can be used to "render" the response data into a different format
	// E.g. when you're making a representations Request with two entities, you will get back an array of two objects
	// However, you might want to render this into a single object with two properties
	// This can be done with a ResponseTemplate
	ResponseTemplate *InputTemplate
	// MergePath can be defined to merge the result of the post-processing into the parent object at the given path
	// e.g. if the parent is {"a":1}, result is {"foo":"bar"} and the MergePath is ["b"],
	// the result will be {"a":1,"b":{"foo":"bar"}}
	// If the MergePath is empty, the result will be merged into the parent object
	// In this case, the result would be {"a":1,"foo":"bar"}
	// This is useful if you make multiple fetches, e.g. parallel fetches, that would otherwise overwrite each other
	MergePath []string
}

type RenameTypeName

type RenameTypeName struct {
	From, To []byte
}

type Reporter

type Reporter interface {
	SubscriptionUpdateSent()
}

type Request

type Request struct {
	ID     string
	Header http.Header
}

type RequestTraceOptions

type RequestTraceOptions struct {
	// Enable switches tracing on or off
	Enable bool
	// ExcludePlannerStats excludes planner timing information from the trace output
	ExcludePlannerStats bool
	// ExcludeRawInputData excludes the raw input for a load operation from the trace output
	ExcludeRawInputData bool
	// ExcludeInput excludes the rendered input for a load operation from the trace output
	ExcludeInput bool
	// ExcludeOutput excludes the result of a load operation from the trace output
	ExcludeOutput bool
	// ExcludeLoadStats excludes the load timing information from the trace output
	ExcludeLoadStats bool
	// EnablePredictableDebugTimings makes the timings in the trace output predictable for debugging purposes
	EnablePredictableDebugTimings          bool
	IncludeTraceOutputInResponseExtensions bool
}

func (*RequestTraceOptions) DisableAll

func (r *RequestTraceOptions) DisableAll()

func (*RequestTraceOptions) EnableAll

func (r *RequestTraceOptions) EnableAll()

type Resolvable

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

func NewResolvable

func NewResolvable() *Resolvable

func (*Resolvable) Init

func (r *Resolvable) Init(ctx *Context, initialData []byte, operationType ast.OperationType) (err error)

func (*Resolvable) InitSubscription

func (r *Resolvable) InitSubscription(ctx *Context, initialData []byte, postProcessing PostProcessingConfiguration) (err error)

func (*Resolvable) Reset

func (r *Resolvable) Reset()

func (*Resolvable) Resolve

func (r *Resolvable) Resolve(ctx context.Context, root *Object, out io.Writer) error

type ResolvableObjectVariable

type ResolvableObjectVariable struct {
	Renderer *GraphQLVariableResolveRenderer
}

func NewResolvableObjectVariable

func NewResolvableObjectVariable(node *Object) *ResolvableObjectVariable

func (*ResolvableObjectVariable) Equals

func (h *ResolvableObjectVariable) Equals(another Variable) bool

func (*ResolvableObjectVariable) GetVariableKind

func (h *ResolvableObjectVariable) GetVariableKind() VariableKind

func (*ResolvableObjectVariable) TemplateSegment

func (h *ResolvableObjectVariable) TemplateSegment() TemplateSegment

type Resolver

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

func New

func New(ctx context.Context, options ResolverOptions) *Resolver

New returns a new Resolver, ctx.Done() is used to cancel all active subscriptions & streams

func (*Resolver) AsyncResolveGraphQLSubscription

func (r *Resolver) AsyncResolveGraphQLSubscription(ctx *Context, subscription *GraphQLSubscription, writer SubscriptionResponseWriter, id SubscriptionIdentifier) (err error)

func (*Resolver) AsyncUnsubscribeClient

func (r *Resolver) AsyncUnsubscribeClient(connectionID int64) error

func (*Resolver) AsyncUnsubscribeSubscription

func (r *Resolver) AsyncUnsubscribeSubscription(id SubscriptionIdentifier) error

func (*Resolver) ResolveGraphQLResponse

func (r *Resolver) ResolveGraphQLResponse(ctx *Context, response *GraphQLResponse, data []byte, writer io.Writer) (err error)

func (*Resolver) ResolveGraphQLSubscription

func (r *Resolver) ResolveGraphQLSubscription(ctx *Context, subscription *GraphQLSubscription, writer SubscriptionResponseWriter) error

type ResolverOptions

type ResolverOptions struct {
	// MaxConcurrency limits the number of concurrent resolve operations
	// if set to 0, no limit is applied
	// It is advised to set this to a reasonable value to prevent excessive memory usage
	// Each concurrent resolve operation allocates ~50kb of memory
	// In addition, there's a limit of how many concurrent requests can be efficiently resolved
	// This depends on the number of CPU cores available, the complexity of the operations, and the origin services
	MaxConcurrency int

	MaxSubscriptionWorkers int

	Debug bool

	Reporter Reporter
}

type ResponseWriter

type ResponseWriter interface {
	io.Writer
}

type Scalar

type Scalar struct {
	Path     []string
	Nullable bool
	Export   *FieldExport `json:"export,omitempty"`
}

func (*Scalar) NodeKind

func (_ *Scalar) NodeKind() NodeKind

func (*Scalar) NodePath

func (s *Scalar) NodePath() []string

type SegmentType

type SegmentType int
const (
	StaticSegmentType SegmentType = iota + 1
	VariableSegmentType
)

type SerialFetch

type SerialFetch struct {
	Fetches []Fetch
	Trace   *DataSourceLoadTrace
}

SerialFetch - TODO: document better should be used only for object fields which should be fetched serial

func (*SerialFetch) FetchKind

func (_ *SerialFetch) FetchKind() FetchKind

type SimpleResolver

type SimpleResolver struct {
}

func NewSimpleResolver

func NewSimpleResolver() *SimpleResolver

type SingleFetch

type SingleFetch struct {
	FetchConfiguration
	SerialID             int
	InputTemplate        InputTemplate
	DataSourceIdentifier []byte
	Trace                *DataSourceLoadTrace
	Info                 *FetchInfo
}

func (*SingleFetch) FetchKind

func (_ *SingleFetch) FetchKind() FetchKind

type SingleFlightStats

type SingleFlightStats struct {
	SingleFlightUsed           bool
	SingleFlightSharedResponse bool
}

func GetSingleFlightStats

func GetSingleFlightStats(ctx context.Context) *SingleFlightStats

type Stats

type Stats struct {
	NumberOfFetches      atomic.Int32
	CombinedResponseSize atomic.Int64
	ResolvedNodes        int
	ResolvedObjects      int
	ResolvedLeafs        int
}

func (*Stats) Reset

func (s *Stats) Reset()

type StreamField

type StreamField struct {
	InitialBatchSize int
}

type String

type String struct {
	Path                 []string
	Nullable             bool
	Export               *FieldExport `json:"export,omitempty"`
	UnescapeResponseJson bool         `json:"unescape_response_json,omitempty"`
	IsTypeName           bool         `json:"is_type_name,omitempty"`
}

func (*String) NodeKind

func (_ *String) NodeKind() NodeKind

func (*String) NodePath

func (s *String) NodePath() []string

type SubscriptionDataSource

type SubscriptionDataSource interface {
	Start(ctx *Context, input []byte, updater SubscriptionUpdater) error
	UniqueRequestID(ctx *Context, input []byte, xxh *xxhash.Digest) (err error)
}

type SubscriptionIdentifier

type SubscriptionIdentifier struct {
	ConnectionID   int64
	SubscriptionID int64
	// contains filtered or unexported fields
}

type SubscriptionResponseWriter

type SubscriptionResponseWriter interface {
	ResponseWriter
	Flush()
	Complete()
}

type SubscriptionUpdater

type SubscriptionUpdater interface {
	Update(data []byte)
	Done()
}

type TLSHandshakeDoneStats

type TLSHandshakeDoneStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Err                      string `json:"err,omitempty"`
}

type TLSHandshakeStartStats

type TLSHandshakeStartStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
}

type TemplateSegment

type TemplateSegment struct {
	SegmentType        SegmentType
	Data               []byte
	VariableKind       VariableKind
	VariableSourcePath []string
	Renderer           VariableRenderer
	Segments           []TemplateSegment
}

type TraceFetch

type TraceFetch struct {
	Id                   string                 `json:"id,omitempty"`
	Type                 TraceFetchType         `json:"type,omitempty"`
	Path                 string                 `json:"path,omitempty"`
	DataSourceID         string                 `json:"data_source_id,omitempty"`
	Fetches              []*TraceFetch          `json:"fetches,omitempty"`
	DataSourceLoadTrace  *DataSourceLoadTrace   `json:"datasource_load_trace,omitempty"`
	DataSourceLoadTraces []*DataSourceLoadTrace `json:"data_source_load_traces,omitempty"`
}

type TraceFetchEvents

type TraceFetchEvents struct {
	InputBeforeSourceLoad json.RawMessage `json:"input_before_source_load,omitempty"`
}

type TraceFetchType

type TraceFetchType string
const (
	TraceFetchTypeSingle           TraceFetchType = "single"
	TraceFetchTypeParallel         TraceFetchType = "parallel"
	TraceFetchTypeSerial           TraceFetchType = "serial"
	TraceFetchTypeParallelListItem TraceFetchType = "parallelListItem"
	TraceFetchTypeEntity           TraceFetchType = "entity"
	TraceFetchTypeBatchEntity      TraceFetchType = "batchEntity"
)

type TraceField

type TraceField struct {
	Name            string     `json:"name,omitempty"`
	Value           *TraceNode `json:"value,omitempty"`
	ParentTypeNames []string   `json:"parent_type_names,omitempty"`
	NamedType       string     `json:"named_type,omitempty"`
	DataSourceIDs   []string   `json:"data_source_ids,omitempty"`
}

type TraceInfo

type TraceInfo struct {
	TraceStart     time.Time    `json:"-"`
	TraceStartTime string       `json:"trace_start_time"`
	TraceStartUnix int64        `json:"trace_start_unix"`
	PlannerStats   PlannerStats `json:"planner_stats"`
	// contains filtered or unexported fields
}

func GetTraceInfo

func GetTraceInfo(ctx context.Context) *TraceInfo

type TraceNode

type TraceNode struct {
	Info                 *TraceInfo    `json:"info,omitempty"`
	Fetch                *TraceFetch   `json:"fetch,omitempty"`
	NodeType             TraceNodeType `json:"node_type,omitempty"`
	Nullable             bool          `json:"nullable,omitempty"`
	Path                 []string      `json:"path,omitempty"`
	Fields               []*TraceField `json:"fields,omitempty"`
	Items                []*TraceNode  `json:"items,omitempty"`
	UnescapeResponseJson bool          `json:"unescape_response_json,omitempty"`
	IsTypeName           bool          `json:"is_type_name,omitempty"`
}

func GetTrace

func GetTrace(ctx context.Context, root *Object) *TraceNode

type TraceNodeType

type TraceNodeType string
const (
	TraceNodeTypeObject      TraceNodeType = "object"
	TraceNodeTypeEmptyObject TraceNodeType = "emptyObject"
	TraceNodeTypeArray       TraceNodeType = "array"
	TraceNodeTypeEmptyArray  TraceNodeType = "emptyArray"
	TraceNodeTypeNull        TraceNodeType = "null"
	TraceNodeTypeString      TraceNodeType = "string"
	TraceNodeTypeBoolean     TraceNodeType = "boolean"
	TraceNodeTypeInteger     TraceNodeType = "integer"
	TraceNodeTypeFloat       TraceNodeType = "float"
	TraceNodeTypeBigInt      TraceNodeType = "bigint"
	TraceNodeTypeCustom      TraceNodeType = "custom"
	TraceNodeTypeScalar      TraceNodeType = "scalar"
	TraceNodeTypeUnknown     TraceNodeType = "unknown"
)

type TypeFieldSource

type TypeFieldSource struct {
	IDs []string
}

type Variable

type Variable interface {
	GetVariableKind() VariableKind
	Equals(another Variable) bool
	TemplateSegment() TemplateSegment
}

type VariableKind

type VariableKind int
const (
	ContextVariableKind VariableKind = iota + 1
	ObjectVariableKind
	HeaderVariableKind
	ResolvableObjectVariableKind
	ListVariableKind
)

type VariableRenderer

type VariableRenderer interface {
	GetKind() string
	RenderVariable(ctx context.Context, data []byte, out io.Writer) error
}

VariableRenderer is the interface to allow custom implementations of rendering Variables Depending on where a Variable is being used, a different method for rendering is required E.g. a Variable needs to be rendered conforming to the GraphQL specification, when used within a GraphQL Query If a Variable is used within a JSON Object, the contents need to be rendered as a JSON Object

type Variables

type Variables []Variable

func NewVariables

func NewVariables(variables ...Variable) Variables

func (*Variables) AddVariable

func (v *Variables) AddVariable(variable Variable) (name string, exists bool)

type WroteHeadersStats

type WroteHeadersStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
}

type WroteRequestStats

type WroteRequestStats struct {
	DurationSinceStartNano   int64  `json:"duration_since_start_nanoseconds"`
	DurationSinceStartPretty string `json:"duration_since_start_pretty"`
	Err                      string `json:"err,omitempty"`
}

Jump to

Keyboard shortcuts

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