dataloader-codegen icon indicating copy to clipboard operation
dataloader-codegen copied to clipboard

Feature: Add support for multiple batch keys

Open muesugi opened this issue 5 years ago • 1 comments

This feature request is to support endpoints with multiple batch ids.

Example use case

The endpoint that would benefit from this would be an endpoint that takes multiple batch ids and returns a nested object, such as an endpoint with the following definition:

Endpoint request business_ids: str[] features: str[]

Endpoint response

{
  "businessId1": {
    "feature1": "yes",
    "feature2": "no"
  },
  "businessId2": {
    "feature1": "yes"
  }
}

With the current dataloaders functionality, we would be able to set:

batchKey: business_ids
newKey: business_id

which would group multiple requests for that single feature for different businesses, but not multiple requests for different features on the same business. Where there is a large number of features, this could get expensive pretty quickly.

Proposed New Functionality

The ability to set multiple (or at least a secondary level of) batch keys, and then where right now we get back response[business_id] from the dataloader, we would get back something like response[business_id][feature] as the value at that feature for that business.

batchKey: business_ids
newKey: business_id
secondaryBatchKey: features
secondaryNewKey: feature

muesugi avatar May 26 '20 20:05 muesugi

++ on this feature, I have a similar user case:

Endpoint request:

business_ids: str[]
properties: str[]

Endpoint response:

properties: [
  {property1: {....  }, property2: {....  }, property3: {....  }, id: 1,},
  {property1: {....  }, property2: {....  }, property3: {....  }, id: 2,},
  {property1: {....  }, property2: {....  }, property3: {....  }, id: 3,},
],

For example, we have:

loaders.foo.load({ business_id: 2, property: 'property1'});
loaders.foo.load({ business_id: 3, property: 'property2'});
loaders.foo.load({ business_id: 4, property: 'property3'});

Status quo, it will make three service call:

getBusiness({ business_ids: [2], properties: ['property1'] });
getBusiness({ business_ids: [3], properties: ['property2'] });
getBusiness({ business_ids: [4], properties: ['property3'] });

we'd like to combine them to one service call:

getBusiness({ business_ids: [2,3,4], properties: ['property1', 'property2', 'property3'] });

gyDBD avatar May 03 '21 19:05 gyDBD