From 2f5ab57d9282233d4e05e405d3290dc4ffbe2ee3 Mon Sep 17 00:00:00 2001 From: Peter Ng Date: Mon, 8 Oct 2018 22:15:02 -0400 Subject: [PATCH] Re-generated the loaders with `New` --- example/pkgname/userloader_gen.go | 21 +++++++++++++++++++++ example/slice/usersliceloader_gen.go | 21 +++++++++++++++++++++ example/userloader_gen.go | 21 +++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/example/pkgname/userloader_gen.go b/example/pkgname/userloader_gen.go index 23570b2..3cb61df 100644 --- a/example/pkgname/userloader_gen.go +++ b/example/pkgname/userloader_gen.go @@ -9,6 +9,27 @@ import ( "github.com/vektah/dataloaden/example" ) +// UserLoaderConfig captures the config to create a new UserLoader +type UserLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []string) ([]*example.User, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewUserLoader creates a new UserLoader given a fetch, wait, and maxBatch +func NewUserLoader(config UserLoaderConfig) *UserLoader { + return &UserLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // UserLoader batches and caches requests type UserLoader struct { // this method provides the data for the loader diff --git a/example/slice/usersliceloader_gen.go b/example/slice/usersliceloader_gen.go index 1cb5142..08036d8 100644 --- a/example/slice/usersliceloader_gen.go +++ b/example/slice/usersliceloader_gen.go @@ -9,6 +9,27 @@ import ( "github.com/vektah/dataloaden/example" ) +// UserSliceLoaderConfig captures the config to create a new UserSliceLoader +type UserSliceLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []int) ([][]example.User, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewUserSliceLoader creates a new UserSliceLoader given a fetch, wait, and maxBatch +func NewUserSliceLoader(config UserSliceLoaderConfig) *UserSliceLoader { + return &UserSliceLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // UserSliceLoader batches and caches requests type UserSliceLoader struct { // this method provides the data for the loader diff --git a/example/userloader_gen.go b/example/userloader_gen.go index d2759fe..26fc3aa 100644 --- a/example/userloader_gen.go +++ b/example/userloader_gen.go @@ -7,6 +7,27 @@ import ( "time" ) +// UserLoaderConfig captures the config to create a new UserLoader +type UserLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []string) ([]*User, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewUserLoader creates a new UserLoader given a fetch, wait, and maxBatch +func NewUserLoader(config UserLoaderConfig) *UserLoader { + return &UserLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // UserLoader batches and caches requests type UserLoader struct { // this method provides the data for the loader