Skip to content

Conversation

gyDBD
Copy link
Contributor

@gyDBD gyDBD commented Aug 3, 2021

function unPartitionResultsByBatchKeyPartition is used to help us split the results back up into the order that they were requested. And it requires some certain contract of the resource, see https://github.com/Yelp/dataloader-codegen/blob/master/API_DOCS.md#batch-resources-with-properties-parameters

I have to separate the getPropertyBatchLoader and the normal getBatchLoader, otherwise, all resources with isBatchResource: true will have unPartitionResultsByBatchKeyPartition inside the codegen, and throw flow errors.

What's the change?

  1. Create a new function getPropertyBatchLoader, which will only be called when properyBatch key is being used.
  2. Put everything that can be shared between getPropertyBatchLoader and the getBatchLoader into a function getBatchResourceCommonLoader to avoid copy and paste hundred of lines of code

test

make test passed
test on swapi example

@gyDBD gyDBD requested review from magicmark and kkellyy August 3, 2021 22:09
requestGroups = partitionItems('${resourceConfig.newKey}', keys);
}
function getBatchResourceCommonLoader(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) {
Copy link
Collaborator

@magicmark magicmark Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, there's now 3 top level loader implementation functions:

  • getPropertyBatchLoader
  • getBatchLoader
  • getNonBatchLoader

which makes sense.

The naming of "getBatchResourceCommonLoader" makes me think it might be another top level factory function (it follows the same naming getXYZLoader pattern), but I guess it's not - it's a helper shared between getPropertyBatchLoader and getBatchLoader? So maybe we could just tweak the name to clarify this?

maybe something like:

Suggested change
function getBatchResourceCommonLoader(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) {
/**
* This is a helper to implement the batch logic, shared between blah blah blah
*
function batchLoaderLogic(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) {

(with a lil docstring to clarify)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines -84 to -91
assert(
resourceConfig.isBatchResource === true,
`${errorPrefix(resourcePath)} Expected getBatchLoader to be called with a batch resource config`,
);
assert(
typeof resourceConfig.batchKey === 'string' && typeof resourceConfig.newKey === 'string',
`${errorPrefix(resourcePath)} Expected both batchKey and newKey for a batch resource`,
);
Copy link
Collaborator

@magicmark magicmark Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep these assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@magicmark magicmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg2m!

@gyDBD gyDBD merged commit 876ab4c into master Aug 4, 2021
gyDBD added a commit that referenced this pull request Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants