Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dataloader/dataloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DataLoaders interface {
// DataLoader interface
type DataLoader interface {
Load(context.Context, interface{}) (interface{}, error)
LoadOne(context.Context, interface{}) (interface{}, error)
LoadMany(context.Context, []interface{}) ([]interface{}, []error)
Clear(interface{})
ClearAll()
Expand Down
7 changes: 7 additions & 0 deletions dataloader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ func (l *Loader) Load(ctx context.Context, key interface{}) (interface{}, error)
return thunk()
}

// LoadOne loads the given key, doing one request instead of batch, and returns a thunk that resolves the key.
func (l *Loader) LoadOne(ctx context.Context, key interface{}) (interface{}, error) {
// set batch capacity to 1
l.batchCap = 1
return l.Load(ctx, key)
}

// LoadMany loads mulitiple keys, returning a thunk (type: ThunkMany) that will resolve the keys passed in.
func (l *Loader) LoadMany(ctx context.Context, keys []interface{}) ([]interface{}, []error) {
length := len(keys)
Expand Down
1 change: 1 addition & 0 deletions router/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type GQLSubscriptionAdaptor interface {
// DataLoaderAdaptor interface
type DataLoaderAdaptor interface {
Load(context.Context, interface{}) (interface{}, error)
LoadOne(context.Context, interface{}) (interface{}, error)
LoadMany(context.Context, []interface{}) ([]interface{}, []error)
Clear(interface{})
ClearAll()
Expand Down