0

We are on HC v12 and need to override the default MaxBatchSize of data loaders (it defaults to 1024 despite the docs saying it defaults to unlimited). Specifically we need an unlimited (or very high) batch size.

The sample custom data loader in the docs is injected via param injection, but we use code-first resolvers like:

            descriptor.Field("myField")
                .Type<BooleanType>()
                .Argument(
                    "projectId",
                    a => a
                        .Type<StringType>()
                        .Description("The ID of the current project"))
                .Resolve(async context =>
                {
                    // resolver code here
                });

There doesn't seem to be a way to configure the data loader using the inline context.BatchDataLoader, so we thought to use a custom data loader class, but that class requires context-specific constructor params and is intended to be auto-injected. We use code-first resolvers so this isn't an option for us. Sample data loader from the docs:

  public PersonBatchDataLoader(
        IPersonRepository repository,
        IBatchScheduler batchScheduler,
        DataLoaderOptions<string>? options = null)
        : base(batchScheduler, options)
    {
        _repository = repository;
    }

So how can we use, say, an instance of PersonBatchDataLoader inside our Resolve method? It no longer seems possible to grab it via context.DataLoader as in this older issue.

1 Answer 1

0

You could just create a static method that generates the DataLoaderOptions instance you want to use and then use that when calling the base class in the constructor:

  public PersonBatchDataLoader(
        IPersonRepository repository,
        IBatchScheduler batchScheduler,
        DataLoaderOptions<string>? options = null)
        : base(batchScheduler, DataLoaderHelper.DefaultOptions)
    {
        _repository = repository;
    }
    public static class DataLoaderHelper
    {
        public static DataLoaderOptions DefaultOptions => new()
        {
            MaxBatchSize = 10000
        };
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.