persisted_operations

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHashFound = errors.New("no hash found")
View Source
var ErrNoLoaderSupplied = errors.New("no remoteLoader supplied")
View Source
var ErrNoRemoteLoaderSpecified = errors.New("no remote loader specified")
View Source
var ErrPersistedOperationNotFound = errors.New("PersistedOperationNotFound")
View Source
var ErrPersistedQueryNotFound = errors.New("PersistedQueryNotFound")
View Source
var ErrReloadIntervalTooShort = errors.New("reload interval cannot be less than 10 seconds")

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled bool `conf:"default:false" yaml:"enabled"`
	// The location on which persisted operations are stored
	Store string `conf:"default:./store" yaml:"store"`
	// Configuration for auto-reloading persisted operations
	Reload struct {
		Enabled  bool          `conf:"default:true" yaml:"enabled"`
		Interval time.Duration `conf:"default:5m" yaml:"interval"`
		Timeout  time.Duration `conf:"default:10s" yaml:"timeout"`
	}
	// Remote strategies for fetching persisted operations
	Remote struct {
		GcpBucket string `yaml:"gcp_bucket"`
	}
	RejectOnFailure bool `conf:"default:true" yaml:"reject_on_failure"`
}

type DirLoader

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

DirLoader loads persisted operations from a filesystem directory It looks at all files in the directory, but doesn't traverse subdirectories If it finds a file with a `.json` extension it attempts to unmarshall it and use it as a source for persisted operations/ If it fails to load a file it moves on to the next file in the directory

func NewLocalDirLoader

func NewLocalDirLoader(cfg Config, log *slog.Logger) *DirLoader

func (*DirLoader) Load

func (d *DirLoader) Load(_ context.Context) (map[string]string, error)

type ErrorMessage

type ErrorMessage struct {
	Message string `json:"message"`
}

type ErrorPayload

type ErrorPayload struct {
	Errors gqlerror.List `json:"errors"`
}

type GcpStorageLoader

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

GcpStorageLoader loads persisted operations from a GCP Storage bucket. It matches files based on a `*.json` glob pattern and attempts to unmarshall them into a persisted operations map structure

func NewGcpStorageLoader

func NewGcpStorageLoader(ctx context.Context, bucket string, store string, logger *slog.Logger) (*GcpStorageLoader, error)

func (*GcpStorageLoader) Load

func (g *GcpStorageLoader) Load(ctx context.Context) error

type LocalLoader

type LocalLoader interface {
	Load(ctx context.Context) (map[string]string, error)
}

type MemoryLoader

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

MemoryLoader is a loader for testing purposes It allows the user to specify operations in memory

func (*MemoryLoader) Load

func (d *MemoryLoader) Load(_ context.Context) (map[string]string, error)

type PersistedOperationsHandler

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

func NewPersistedOperations

func NewPersistedOperations(log *slog.Logger, cfg Config, loader LocalLoader, remoteLoader RemoteLoader) (*PersistedOperationsHandler, error)

func (*PersistedOperationsHandler) Shutdown

func (p *PersistedOperationsHandler) Shutdown()

func (*PersistedOperationsHandler) SwapHashForQuery added in v0.12.1

func (p *PersistedOperationsHandler) SwapHashForQuery(next http.Handler) http.Handler

SwapHashForQuery runs of the persisted operations handler it uses the configuration supplied to decide its behavior

type RemoteLoader

type RemoteLoader interface {
	Load(ctx context.Context) error
}

func RemoteLoaderFromConfig

func RemoteLoaderFromConfig(cfg Config, log *slog.Logger) (RemoteLoader, error)

RemoteLoaderFromConfig looks at the configuration applied and figures out which remoteLoader to initialize and return If no remoteLoader is configured an error is returned

Jump to

Keyboard shortcuts

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