graphql_datasource

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 38 Imported by: 5

Documentation

Index

Constants

View Source
const EntityInterfacesDefinition = `` /* 1096-byte string literal not displayed */

Variables

View Source
var (
	DefaultPostProcessingConfiguration = resolve.PostProcessingConfiguration{
		SelectResponseDataPath:   []string{"data"},
		SelectResponseErrorsPath: []string{"errors"},
	}
	EntitiesPostProcessingConfiguration = resolve.PostProcessingConfiguration{
		SelectResponseDataPath:   []string{"data", "_entities"},
		SelectResponseErrorsPath: []string{"errors"},
	}
	SingleEntityPostProcessingConfiguration = resolve.PostProcessingConfiguration{
		SelectResponseDataPath:   []string{"data", "_entities", "0"},
		SelectResponseErrorsPath: []string{"errors"},
	}
)

Functions

func EntityInterfacesPlanConfiguration

func EntityInterfacesPlanConfiguration(t *testing.T, factory plan.PlannerFactory[Configuration]) *plan.Configuration

func EntityInterfacesPlanConfigurationBench

func EntityInterfacesPlanConfigurationBench(t *testing.B, factory plan.PlannerFactory[Configuration]) *plan.Configuration

func IsDefaultGraphQLSubscriptionClient

func IsDefaultGraphQLSubscriptionClient(client GraphQLSubscriptionClient) bool

Types

type Configuration

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

func NewConfiguration

func NewConfiguration(input ConfigurationInput) (Configuration, error)

func (*Configuration) FederationConfiguration

func (c *Configuration) FederationConfiguration() *FederationConfiguration

func (*Configuration) IsFederationEnabled

func (c *Configuration) IsFederationEnabled() bool

func (*Configuration) IsGRPC

func (c *Configuration) IsGRPC() bool

func (*Configuration) UpstreamSchema

func (c *Configuration) UpstreamSchema() (*ast.Document, error)

type ConfigurationInput

type ConfigurationInput struct {
	Fetch                  *FetchConfiguration
	Subscription           *SubscriptionConfiguration
	SchemaConfiguration    *SchemaConfiguration
	CustomScalarTypeFields []SingleTypeField

	GRPC *grpcdatasource.GRPCConfiguration
}

type DefaultSubscriptionClientFactory

type DefaultSubscriptionClientFactory struct{}

func (*DefaultSubscriptionClientFactory) NewSubscriptionClient

type Factory

type Factory[T Configuration] struct {
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory(executionContext context.Context, httpClient *http.Client, subscriptionClient GraphQLSubscriptionClient) (*Factory[Configuration], error)

NewFactory (HTTP) creates a new factory for the GraphQL datasource planner Graphql Datasource could be stateful in case you are using subscriptions, make sure you are using the same execution context for all datasources

func NewFactoryGRPC

func NewFactoryGRPC(executionContext context.Context, grpcClient grpc.ClientConnInterface) (*Factory[Configuration], error)

NewFactoryGRPC creates a gRPC factory for the GraphQL datasource planner. Graphql Datasource could be stateful in case you are using subscriptions, make sure you are using the same execution context for all datasources.

func NewFactoryGRPCClientProvider

func NewFactoryGRPCClientProvider(executionContext context.Context, clientProvider func() grpc.ClientConnInterface) (*Factory[Configuration], error)

NewFactoryGRPCClientProvider creates a new factory for the GraphQL datasource planner This factory is used when the gRPC client is provided by a function. This is useful when you don't want to provide a static client to the factory and let the consumer decide how to provide the client to the datasource. For example, when you need to recreate the client in case of a connection error.

func (*Factory[T]) Context

func (f *Factory[T]) Context() context.Context

func (*Factory[T]) EnableSubgraphFieldSelectionMergingNullabilityRelaxation

func (f *Factory[T]) EnableSubgraphFieldSelectionMergingNullabilityRelaxation()

EnableSubgraphFieldSelectionMergingNullabilityRelaxation implements plan.SubgraphFieldSelectionMergingNullabilityRelaxer. It configures the factory to use a shared pool whose validator allows differing nullability on fields in non-overlapping concrete types.

func (*Factory[T]) Planner

func (f *Factory[T]) Planner(logger abstractlogger.Logger) plan.DataSourcePlanner[T]

func (*Factory[T]) PlanningBehavior

func (f *Factory[T]) PlanningBehavior() plan.DataSourcePlanningBehavior

func (*Factory[T]) UpstreamSchema

func (f *Factory[T]) UpstreamSchema(dataSourceConfig plan.DataSourceConfiguration[T]) (*ast.Document, bool)

type FederationConfiguration

type FederationConfiguration struct {
	Enabled    bool
	ServiceSDL string
}

type FetchConfiguration

type FetchConfiguration struct {
	URL    string
	Method string
	Header http.Header
}

type GraphQLBody

type GraphQLBody struct {
	Query         string          `json:"query,omitempty"`
	OperationName string          `json:"operationName,omitempty"`
	Variables     json.RawMessage `json:"variables,omitempty"`
	Extensions    json.RawMessage `json:"extensions,omitempty"`
}

type GraphQLSubscriptionClient

type GraphQLSubscriptionClient interface {
	// Subscribe to the origin source. The implementation must not block the calling goroutine.
	Subscribe(ctx *resolve.Context, options GraphQLSubscriptionOptions, updater resolve.SubscriptionUpdater) error
}

func NewGraphQLSubscriptionClient

func NewGraphQLSubscriptionClient(ctx context.Context, opts ...SubscriptionClientOption) GraphQLSubscriptionClient

NewGraphQLSubscriptionClient creates a new subscription client.

type GraphQLSubscriptionClientFactory

type GraphQLSubscriptionClientFactory interface {
	NewSubscriptionClient(ctx context.Context, options ...SubscriptionClientOption) GraphQLSubscriptionClient
}

GraphQLSubscriptionClientFactory abstracts the way of creating a new GraphQLSubscriptionClient. This can be very handy for testing purposes.

type GraphQLSubscriptionOptions

type GraphQLSubscriptionOptions struct {
	URL                                     string              `json:"url"`
	InitialPayload                          json.RawMessage     `json:"initial_payload"`
	Body                                    GraphQLBody         `json:"body"`
	Header                                  http.Header         `json:"header"`
	UseSSE                                  bool                `json:"use_sse"`
	SSEMethodPost                           bool                `json:"sse_method_post"`
	ForwardedClientHeaderNames              []string            `json:"forwarded_client_header_names"`
	ForwardedClientHeaderRegularExpressions []RegularExpression `json:"forwarded_client_header_regular_expressions"`
	WsSubProtocol                           string              `json:"ws_sub_protocol"`
	// contains filtered or unexported fields
}

type OnWsConnectionInitCallback

type OnWsConnectionInitCallback func(ctx context.Context, url string, header http.Header) (json.RawMessage, error)

type Planner

type Planner[T Configuration] struct {
	// contains filtered or unexported fields
}

Planner creates the subgraph operation.

func (*Planner[T]) ConfigureFetch

func (p *Planner[T]) ConfigureFetch() resolve.FetchConfiguration

func (*Planner[T]) ConfigureSubscription

func (p *Planner[T]) ConfigureSubscription() plan.SubscriptionConfiguration

func (*Planner[T]) DebugPrint

func (p *Planner[T]) DebugPrint(args ...interface{})

func (*Planner[T]) DownstreamResponseFieldAlias

func (p *Planner[T]) DownstreamResponseFieldAlias(downstreamFieldRef int) (alias string, exists bool)

func (*Planner[T]) EnableDebug

func (p *Planner[T]) EnableDebug()

func (*Planner[T]) EnableDebugQueryPlanLogging

func (p *Planner[T]) EnableDebugQueryPlanLogging()

func (*Planner[T]) EnableSubgraphRequestMinifier

func (p *Planner[T]) EnableSubgraphRequestMinifier()

func (*Planner[T]) EnterArgument

func (p *Planner[T]) EnterArgument(_ int)

func (*Planner[T]) EnterDirective

func (p *Planner[T]) EnterDirective(ref int)

func (*Planner[T]) EnterDocument

func (p *Planner[T]) EnterDocument(_, _ *ast.Document)

func (*Planner[T]) EnterField

func (p *Planner[T]) EnterField(ref int)

func (*Planner[T]) EnterInlineFragment

func (p *Planner[T]) EnterInlineFragment(ref int)

func (*Planner[T]) EnterOperationDefinition

func (p *Planner[T]) EnterOperationDefinition(ref int)

func (*Planner[T]) EnterSelectionSet

func (p *Planner[T]) EnterSelectionSet(ref int)

func (*Planner[T]) EnterVariableDefinition

func (p *Planner[T]) EnterVariableDefinition(ref int)

func (*Planner[T]) ID

func (p *Planner[T]) ID() (id int)

func (*Planner[T]) IncludeQueryPlanInFetchConfiguration

func (p *Planner[T]) IncludeQueryPlanInFetchConfiguration()

func (*Planner[T]) LeaveDocument

func (p *Planner[T]) LeaveDocument(_, _ *ast.Document)

func (*Planner[T]) LeaveField

func (p *Planner[T]) LeaveField(ref int)

func (*Planner[T]) LeaveInlineFragment

func (p *Planner[T]) LeaveInlineFragment(ref int)

func (*Planner[T]) LeaveOperationDefinition

func (p *Planner[T]) LeaveOperationDefinition(_ int)

func (*Planner[T]) LeaveSelectionSet

func (p *Planner[T]) LeaveSelectionSet(ref int)

func (*Planner[T]) LeaveVariableDefinition

func (p *Planner[T]) LeaveVariableDefinition(_ int)

func (*Planner[T]) Register

func (p *Planner[T]) Register(visitor *plan.Visitor, configuration plan.DataSourceConfiguration[T], dataSourcePlannerConfiguration plan.DataSourcePlannerConfiguration) error

func (*Planner[T]) SetID

func (p *Planner[T]) SetID(id int)

type RegularExpression

type RegularExpression struct {
	Pattern     *regexp.Regexp
	NegateMatch bool
}

type SchemaConfiguration

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

func NewSchemaConfiguration

func NewSchemaConfiguration(upstreamSchema string, federationCfg *FederationConfiguration) (*SchemaConfiguration, error)

func (*SchemaConfiguration) FederationServiceSDL

func (c *SchemaConfiguration) FederationServiceSDL() string

func (*SchemaConfiguration) IsFederationEnabled

func (c *SchemaConfiguration) IsFederationEnabled() bool

type SingleTypeField

type SingleTypeField struct {
	TypeName  string
	FieldName string
}

type Source

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

func (*Source) Load

func (s *Source) Load(ctx context.Context, headers http.Header, input []byte) (data []byte, err error)

func (*Source) LoadWithFiles

func (s *Source) LoadWithFiles(ctx context.Context, headers http.Header, input []byte, files []*httpclient.FileUpload) (data []byte, err error)

type SubscriptionClientOption added in v2.1.0

type SubscriptionClientOption func(*subscriptionClientConfig)

SubscriptionClientOption configures the subscription client.

func WithAckTimeout added in v2.1.0

func WithAckTimeout(d time.Duration) SubscriptionClientOption

WithAckTimeout sets the maximum time to wait for connection_ack after connection_init.

func WithDefaultErrorExtensionCode added in v2.1.0

func WithDefaultErrorExtensionCode(code string) SubscriptionClientOption

WithDefaultErrorExtensionCode sets the extension code attached to GraphQL errors produced by upstream connection failures.

func WithLogger

WithLogger sets the logger for the client and its transports. If not set, logging is disabled (silent operation).

func WithPingInterval

func WithPingInterval(d time.Duration) SubscriptionClientOption

WithPingInterval sets the interval between ping messages for connection health checks. Only applies to graphql-transport-ws protocol (legacy graphql-ws uses server-initiated keepalive). Default: 30s. Set to 0 to disable client-initiated pings.

func WithPingTimeout

func WithPingTimeout(d time.Duration) SubscriptionClientOption

WithPingTimeout sets the maximum time to wait for a pong response. If no pong is received within this duration, the connection is considered dead. Default: 10s. Set to 0 to disable the pong-timeout check.

func WithReadLimit added in v2.1.0

func WithReadLimit(n int64) SubscriptionClientOption

WithReadLimit sets the maximum size in bytes for incoming WebSocket messages.

func WithStreamingClient added in v2.1.0

func WithStreamingClient(c *http.Client) SubscriptionClientOption

WithStreamingClient sets the HTTP client used for SSE requests. This client should have appropriate timeouts for long-lived connections.

func WithUpgradeClient added in v2.1.0

func WithUpgradeClient(c *http.Client) SubscriptionClientOption

WithUpgradeClient sets the HTTP client used for WebSocket upgrade requests.

func WithWriteTimeout added in v2.1.0

func WithWriteTimeout(d time.Duration) SubscriptionClientOption

WithWriteTimeout sets the timeout for WebSocket write operations (subscribe, unsubscribe, ping, pong).

type SubscriptionConfiguration

type SubscriptionConfiguration struct {
	URL           string
	Header        http.Header
	UseSSE        bool
	SSEMethodPost bool
	// ForwardedClientHeaderNames indicates headers names that might be forwarded from the
	// client to the upstream server. This is used to determine which connections
	// can be multiplexed together, but the subscription engine does not forward
	// these headers by itself.
	ForwardedClientHeaderNames []string
	// ForwardedClientHeaderRegularExpressions regular expressions that if matched to the header
	// name might be forwarded from the client to the upstream server. This is used to determine
	// which connections can be multiplexed together, but the subscription engine does not forward
	// these headers by itself.
	ForwardedClientHeaderRegularExpressions []RegularExpression
	WsSubProtocol                           string
	// StartupHooks contains the method called when a subscription is started
	StartupHooks []SubscriptionOnStartFn
}

type SubscriptionOnStartFn

type SubscriptionOnStartFn func(ctx resolve.StartupHookContext, input []byte) (err error)

SubscriptionOnStartFn defines a hook function that is called when a subscription starts. It receives the resolve context and the input of the subscription. The function can return an error.

type SubscriptionSource

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

func (*SubscriptionSource) Start

func (s *SubscriptionSource) Start(ctx *resolve.Context, headers http.Header, input []byte, updater resolve.SubscriptionUpdater) error

Start the subscription. The updater is called on new events. Start needs to be called in a separate goroutine.

func (*SubscriptionSource) SubscriptionOnStart

func (s *SubscriptionSource) SubscriptionOnStart(ctx resolve.StartupHookContext, input []byte) error

SubscriptionOnStart is called when a subscription is started. Hooks are invoked sequentially, short-circuiting on the first error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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