loaders

package
v0.0.0-...-6be7acf Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPatch

func GetPatch(ctx context.Context, patchID string) (*patch.Patch, error)

GetPatch returns a single patch by ID efficiently using the dataloader. Returns nil if the patch is not found.

func GetProject

func GetProject(ctx context.Context, idOrIdentifier string) (*model.ProjectRef, error)

GetProject returns a single merged project ref by its id or identifier efficiently using the dataloader. Returns nil if the project is not found.

func GetTask

func GetTask(ctx context.Context, taskID string) (*task.Task, error)

GetTask returns a single task by ID efficiently using the dataloader. Returns nil if the task is not found.

func GetUser

func GetUser(ctx context.Context, userID string) (*user.DBUser, error)

GetUser returns a single user by ID efficiently using the dataloader. Returns nil if the user is not found (e.g. service users).

func GetVersion

func GetVersion(ctx context.Context, versionID string) (*model.Version, error)

GetVersion returns a single version by ID efficiently using the dataloader. Returns nil if the version is not found.

func Inject

func Inject(ctx context.Context) context.Context

Inject returns a copy of ctx with a fresh set of data loaders attached. It is useful for tests that exercise resolver helpers directly without going through Middleware.

func IsBatchError

func IsBatchError(err error) bool

IsBatchError reports whether err was produced by a dataloader batch operation and has already been logged. The GraphQL error presenter should skip logging these to avoid duplicate log entries.

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware injects data loaders into the request context.

func PreloadPatches

func PreloadPatches(ctx context.Context, patchIDs []string)

PreloadPatches enqueues every patch ID into the dataloader's current batch in a single synchronous loop, guaranteeing that subsequent GetPatch calls for these IDs are served from the loader's thunk cache without any additional MongoDB queries. Use this when a resolver knows up front that it will need many patches whose loads would otherwise be split across multiple batches due to the wait-time window.

Errors are intentionally discarded here; per-key errors are still surfaced to the individual GetPatch callers via the cached thunks.

func PreloadProjects

func PreloadProjects(ctx context.Context, idsOrIdentifiers []string)

PreloadProjects enqueues every project id or identifier into the dataloader's current batch in a single synchronous loop, guaranteeing that subsequent GetProject calls for these values are served from the loader's thunk cache without any additional MongoDB queries. Use this when a resolver knows up front that it will need many projects whose loads would otherwise be split across multiple batches due to the wait-time window.

Errors are intentionally discarded here; per-key errors are still surfaced to the individual GetProject callers via the cached thunks.

func PreloadTasks

func PreloadTasks(ctx context.Context, taskIDs []string)

PreloadTasks enqueues every task ID into the dataloader's current batch in a single synchronous loop, guaranteeing that subsequent GetTask calls for these IDs are served from the loader's thunk cache without any additional MongoDB queries. Use this when a resolver knows up front that it will need many tasks whose loads would otherwise be split across multiple batches due to the wait-time window.

Errors are intentionally discarded here; per-key errors are still surfaced to the individual GetTask callers via the cached thunks.

func PreloadVersions

func PreloadVersions(ctx context.Context, versionIDs []string)

PreloadVersions enqueues every version ID into the dataloader's current batch in a single synchronous loop, guaranteeing that subsequent GetVersion calls for these IDs are served from the loader's thunk cache without any additional MongoDB queries. Use this when a resolver knows up front that it will need many versions whose loads would otherwise be split across multiple batches due to the wait-time window (e.g. the TaskHistory resolver, where hundreds of inactive tasks each request their own version).

Errors are intentionally discarded here; per-key errors are still surfaced to the individual GetVersion callers via the cached thunks.

Types

type Loaders

type Loaders struct {
	UserLoader    *dataloadgen.Loader[string, *user.DBUser]
	VersionLoader *dataloadgen.Loader[string, *model.Version]
	ProjectLoader *dataloadgen.Loader[string, *model.ProjectRef]
	TaskLoader    *dataloadgen.Loader[string, *task.Task]
	PatchLoader   *dataloadgen.Loader[string, *patch.Patch]
}

Loaders contains all dataloader instances for batching GraphQL queries.

func For

func For(ctx context.Context) *Loaders

For returns the dataloader for a given context.

func New

func New() *Loaders

New instantiates data loaders for the middleware.

Jump to

Keyboard shortcuts

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