vektah / dataloaden

go generate based DataLoader
MIT License
528 stars 79 forks source link

expose fetch, wait and maxbatch, so that they are no longer internals #12

Closed udayreddy closed 6 years ago

udayreddy commented 6 years ago

this will be useful for package management , and generated files can be packaged separately and remove dependency for the middleware to be in the same package.

vektah commented 6 years ago

Thanks for the PR, but I don't think this is the right move.

The idea behind keeping them private is to hide the implementation from the rest of the app as much as possible.

The public interface is currently designed to be for the calling code, not the implementation. image

By making these public this interface becomes very muddy image

Should I call Fetch or Load? What happens if I change MaxBatch or Wait?

Maybe a NewXLoader method that takes a config object addresses both of these concerns? It keeps the runtime interface separate from the setup, but still allows you to work out of the package if you want, without breaking existing code.

eg:

    ldrs.UsersById = NewUserLoader(loader.UserLoaderConfig{
        Wait:     2 * time.Millisecond,
        MaxBatch: 200,
        Fetch: func(keys []int) ([]*api.User, []error) {
            ...
        },
    }
udayreddy commented 6 years ago

@vektah After putting some thought , what you say makes sense. let me close the PR