dataloader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package dataloader provides DataLoader middleware for batching relationship queries. It prevents N+1 query problems when traversing GraphQL relationships by collecting individual entity lookups within a batching window and executing them as a single query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(client *ent.Client, next http.Handler) http.Handler

Middleware creates fresh DataLoaders per request and injects them into the context.

Types

type Loaders

type Loaders struct {
	OrganizationByID     *dataloadgen.Loader[int, *ent.Organization]
	NetworkByID          *dataloadgen.Loader[int, *ent.Network]
	FacilityByID         *dataloadgen.Loader[int, *ent.Facility]
	InternetExchangeByID *dataloadgen.Loader[int, *ent.InternetExchange]
	IxLanByID            *dataloadgen.Loader[int, *ent.IxLan]
	CarrierByID          *dataloadgen.Loader[int, *ent.Carrier]
	CampusByID           *dataloadgen.Loader[int, *ent.Campus]
}

Loaders holds all DataLoader instances for a single request.

func For

func For(ctx context.Context) *Loaders

For retrieves the DataLoaders from the context. Panics if middleware is not configured.

func NewLoaders

func NewLoaders(client *ent.Client) *Loaders

NewLoaders creates a new set of DataLoaders backed by the given ent client.

Jump to

Keyboard shortcuts

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