-
Notifications
You must be signed in to change notification settings - Fork 13
separate getPropertyBatchLoader #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/implementation.ts
Outdated
requestGroups = partitionItems('${resourceConfig.newKey}', keys); | ||
} | ||
function getBatchResourceCommonLoader(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) { |
There was a problem hiding this comment.
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:
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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`, | ||
); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lg2m!
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-parametersI have to separate the
getPropertyBatchLoader
and the normalgetBatchLoader
, otherwise, all resources withisBatchResource: true
will haveunPartitionResultsByBatchKeyPartition
inside the codegen, and throw flow errors.What's the change?
getPropertyBatchLoader
, which will only be called whenproperyBatch
key is being used.getPropertyBatchLoader
and thegetBatchLoader
into a functiongetBatchResourceCommonLoader
to avoid copy and paste hundred of lines of codetest
make test passed
test on swapi example