resolve

package
v1.66.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 22 Imported by: 5

Documentation

Index

Constants

View Source
const (
	NodeKindObject NodeKind = iota + 1
	NodeKindEmptyObject
	NodeKindArray
	NodeKindEmptyArray
	NodeKindNull
	NodeKindString
	NodeKindBoolean
	NodeKindInteger
	NodeKindFloat
	NodeKindBigInt
	NodeKindCustom

	FetchKindSingle FetchKind = iota + 1
	FetchKindParallel
	FetchKindBatch
)
View Source
const (
	VariableRendererKindPlain                 = "plain"
	VariableRendererKindPlanWithValidation    = "plainWithValidation"
	VariableRendererKindJson                  = "json"
	VariableRendererKindJsonWithValidation    = "jsonWithValidation"
	VariableRendererKindGraphqlWithValidation = "graphqlWithValidation"
	VariableRendererKindCsv                   = "csv"
)

Variables

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

Functions

This section is empty.

Types

type AfterFetchHook

type AfterFetchHook interface {
	OnData(ctx HookContext, output []byte, singleFlight bool)
	OnError(ctx HookContext, output []byte, singleFlight bool)
}

type Array

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

func (*Array) NodeKind

func (_ *Array) NodeKind() NodeKind

type BatchFetch

type BatchFetch struct {
	Fetch        *SingleFetch
	BatchFactory DataSourceBatchFactory
}

func (*BatchFetch) FetchKind

func (_ *BatchFetch) FetchKind() FetchKind

type BeforeFetchHook

type BeforeFetchHook interface {
	OnBeforeFetch(ctx HookContext, input []byte)
}

type BigInt added in v1.66.0

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

func (BigInt) NodeKind added in v1.66.0

func (BigInt) NodeKind() NodeKind

type Boolean

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

func (*Boolean) NodeKind

func (_ *Boolean) NodeKind() NodeKind

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 Context

type Context struct {
	Variables []byte
	Request   Request

	RenameTypeNames []RenameTypeName
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context) *Context

func (*Context) Context added in v1.63.0

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

func (*Context) Free

func (c *Context) Free()

func (*Context) SetAfterFetchHook

func (c *Context) SetAfterFetchHook(hook AfterFetchHook)

func (*Context) SetBeforeFetchHook

func (c *Context) SetBeforeFetchHook(hook BeforeFetchHook)

func (*Context) WithContext added in v1.63.0

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 added in v1.64.1

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

func (*CustomNode) NodeKind added in v1.64.1

func (_ *CustomNode) NodeKind() NodeKind

type CustomResolve added in v1.64.1

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

type DataSource

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

type DataSourceBatch

type DataSourceBatch interface {
	Demultiplex(responseBufPair *BufPair, outputBuffers []*BufPair) (err error)
	Input() *fastbuffer.FastBuffer
}

type DataSourceBatchFactory

type DataSourceBatchFactory interface {
	CreateBatch(inputs [][]byte) (DataSourceBatch, error)
}

type Defer

type Defer struct {
	Enabled    bool
	PatchIndex int
}

type DeferField

type DeferField struct{}

type EmptyArray

type EmptyArray struct{}

func (*EmptyArray) NodeKind

func (_ *EmptyArray) NodeKind() NodeKind

type EmptyObject

type EmptyObject struct{}

func (*EmptyObject) NodeKind

func (_ *EmptyObject) NodeKind() NodeKind

type Fetch

type Fetch interface {
	FetchKind() FetchKind
}

type FetchKind

type FetchKind int

type Fetcher

type Fetcher struct {
	EnableSingleFlightLoader bool
	// contains filtered or unexported fields
}

func NewFetcher

func NewFetcher(enableSingleFlightLoader bool) *Fetcher

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx *Context, fetch *SingleFetch, preparedInput *fastbuffer.FastBuffer, buf *BufPair) (err error)

func (*Fetcher) FetchBatch

func (f *Fetcher) FetchBatch(ctx *Context, fetch *BatchFetch, preparedInputs []*fastbuffer.FastBuffer, bufs []*BufPair) (err error)

type Fetches

type Fetches []Fetch

type Field

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

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 Float

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

func (*Float) NodeKind

func (_ *Float) NodeKind() NodeKind

type FlushWriter

type FlushWriter interface {
	io.Writer
	Flush()
}

type GraphQLResponse

type GraphQLResponse struct {
	Data            Node
	RenameTypeNames []RenameTypeName
}

type GraphQLResponsePatch

type GraphQLResponsePatch struct {
	Value     Node
	Fetch     Fetch
	Operation []byte
}

type GraphQLStreamingResponse

type GraphQLStreamingResponse struct {
	InitialResponse *GraphQLResponse
	Patches         []*GraphQLResponsePatch
	FlushInterval   int64
}

type GraphQLSubscription

type GraphQLSubscription struct {
	Trigger  GraphQLSubscriptionTrigger
	Response *GraphQLResponse
}

type GraphQLSubscriptionTrigger

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

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 added in v1.61.0

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 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 HookContext

type HookContext struct {
	CurrentPath []byte
}

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 *fastbuffer.FastBuffer) error

type Integer

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

func (*Integer) NodeKind

func (_ *Integer) NodeKind() NodeKind

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 Node

type Node interface {
	NodeKind() NodeKind
}

type NodeKind

type NodeKind int

type Null

type Null struct {
	Defer Defer
}

func (*Null) NodeKind

func (_ *Null) NodeKind() NodeKind

type Object

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

func (*Object) NodeKind

func (_ *Object) NodeKind() NodeKind

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
}

func (*ParallelFetch) FetchKind

func (_ *ParallelFetch) 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 Position

type Position struct {
	Line   uint32
	Column uint32
}

type ProcessResponseConfig

type ProcessResponseConfig struct {
	ExtractGraphqlResponse    bool
	ExtractFederationEntities bool
}

type RenameTypeName

type RenameTypeName struct {
	From, To []byte
}

type Request

type Request struct {
	Header http.Header
}

type Resolver

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

func New

func New(ctx context.Context, fetcher *Fetcher, enableDataLoader bool) *Resolver

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

func (*Resolver) MergeBufPairData

func (r *Resolver) MergeBufPairData(from, to *BufPair, prefixDataWithComma bool)

func (*Resolver) MergeBufPairErrors

func (r *Resolver) MergeBufPairErrors(from, to *BufPair)

func (*Resolver) MergeBufPairs

func (r *Resolver) MergeBufPairs(from, to *BufPair, prefixDataWithComma bool)

func (*Resolver) ResolveGraphQLResponse

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

func (*Resolver) ResolveGraphQLResponsePatch

func (r *Resolver) ResolveGraphQLResponsePatch(ctx *Context, patch *GraphQLResponsePatch, data, path, extraPath []byte, writer io.Writer) (err error)

func (*Resolver) ResolveGraphQLStreamingResponse

func (r *Resolver) ResolveGraphQLStreamingResponse(ctx *Context, response *GraphQLStreamingResponse, data []byte, writer FlushWriter) (err error)

func (*Resolver) ResolveGraphQLSubscription

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

type SegmentType

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

type SingleFetch

type SingleFetch struct {
	BufferId   int
	Input      string
	DataSource DataSource
	Variables  Variables
	// 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
	DisableDataLoader     bool
	InputTemplate         InputTemplate
	DataSourceIdentifier  []byte
	ProcessResponseConfig ProcessResponseConfig
	// 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 (*SingleFetch) FetchKind

func (_ *SingleFetch) FetchKind() FetchKind

type Stream

type Stream struct {
	Enabled          bool
	InitialBatchSize int
	PatchIndex       int
}

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

type SubscriptionDataSource

type SubscriptionDataSource interface {
	Start(ctx context.Context, input []byte, next chan<- []byte) error
}

type TemplateSegment

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

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
)

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 VariableSchema

type VariableSchema struct {
}

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)

Jump to

Keyboard shortcuts

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