-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(repository): implement inclusionResolver for hasMany relation #3595
Conversation
6bf98c6
to
c74d6b6
Compare
e2ba1c4
to
fe46284
Compare
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
c545033
to
6866dd7
Compare
] | ||
``` | ||
|
||
- You can delete a relation from `inclusionResolvers` to disable the inclusion |
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.
What is this doing exactly? It is not clear to me.
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.
Just to show the way to disable a certain inclusion resolver. Because not all models are traversable.
...ges/repository/src/__tests__/unit/repositories/relations-helpers/build-lookup-map.helpers.ts
Outdated
Show resolved
Hide resolved
951730a
to
105385f
Compare
105385f
to
90ecdb9
Compare
e1c19f9
to
b77f8a9
Compare
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.
The changes look reasonable at very high level, let's improve implementation details now.
`Invalid "filter.include" entries: {"relation":"orders"}`, | ||
); | ||
// reset | ||
customerRepo.inclusionResolvers.set( |
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.
This won't work. If await expect
above throws, then this line is never called.
I believe it should be safe to simply remove this line, because orders
resolver is always initialized from the beforeEach
hook (see lines 74-77 above).
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.
This won't work. If
await expect
above throws, then this line is never called.I believe it should be safe to simply remove this line, because
orders
resolver is always initialized from thebeforeEach
hook (see lines 74-77 above).
☝️
This comment haven't been addressed yet.
packages/repository-tests/src/crud/relations/fixtures/repositories/customer.repository.ts
Outdated
Show resolved
Hide resolved
...ges/repository/src/__tests__/unit/repositories/relations-helpers/build-lookup-map.helpers.ts
Outdated
Show resolved
Hide resolved
...sts__/unit/repositories/relations-helpers/flatten-targets-of-one-to-many-relation.helpers.ts
Outdated
Show resolved
Hide resolved
...ges/repository/src/__tests__/unit/repositories/relations-helpers/build-lookup-map.helpers.ts
Outdated
Show resolved
Hide resolved
...ges/repository/src/__tests__/unit/repositories/relations-helpers/build-lookup-map.helpers.ts
Outdated
Show resolved
Hide resolved
...ges/repository/src/__tests__/unit/repositories/relations-helpers/build-lookup-map.helpers.ts
Outdated
Show resolved
Hide resolved
...sts__/unit/repositories/relations-helpers/flatten-targets-of-one-to-many-relation.helpers.ts
Outdated
Show resolved
Hide resolved
ff03493
to
aeda4b0
Compare
aeda4b0
to
7243075
Compare
7786594
to
3ca0cc6
Compare
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.
The implementation looks good, let's improve the tests please.
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
`Invalid "filter.include" entries: {"relation":"orders"}`, | ||
); | ||
// reset | ||
customerRepo.inclusionResolvers.set( |
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.
This won't work. If
await expect
above throws, then this line is never called.I believe it should be safe to simply remove this line, because
orders
resolver is always initialized from thebeforeEach
hook (see lines 74-77 above).
☝️
This comment haven't been addressed yet.
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
expect(toJSON(result)).to.deepEqual(toJSON(expected)); | ||
}); | ||
|
||
it('returns related instances to target models via findById() method', async () => { |
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.
Please introduce a new describe
block to group findById
tests and apply the comments I posted for find
tests.
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.
I removed find*
from all titles as my intention was to show different use cases instead of testing find*
here.
]; | ||
expect(toJSON(result)).to.deepEqual(toJSON(expected)); | ||
}); | ||
|
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.
I am missing the following test case for find
method:
- Create two customers
- Create one order for each customer
- Run
find
with a filter limiting the results to only one of the customers - Verify that data from the other customer (customer, order) did not leak into the results
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.
I test this case in that findById()
test case. Checks the result has correct instance and its related models.
Since I don't want the test cases in this file look like testing find*
methods, I will reword the titles to show the intention of each test case.
...itory-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
061af6b
to
d22962d
Compare
// get the repository class and create a new instance of it | ||
const customerRepoClass = createCustomerRepo(repositoryClass); | ||
const customerRepo: CustomerRepository = new customerRepoClass( | ||
db, | ||
async () => orderRepo, | ||
async () => addressRepo, | ||
); | ||
// register the inclusionResolvers here for customerRepo | ||
|
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.
Let's add the newline before the comment. I feel the comment belongs to registration of inclusion resolvers below, not to new customerRepoClass
code above.
const customerRepo: CustomerRepository = new customerRepoClass(
db,
async () => orderRepo,
async () => addressRepo,
);
// register the inclusionResolvers here for customerRepo
customerRepo.inclusionResolvers.set(
'orders',
customerRepo.orders.inclusionResolver,
);
ecca712
to
2b208b7
Compare
); | ||
|
||
// add this line to register inclusion resolver | ||
this.registerInclusion('orders', this.orders.inclusionResolver); |
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.
I'm wondering if we can make it even simpler as we can use orders
to get the inclusionResolver (this['orders'].inclusionResolver
).
this.registerInclusion('orders');
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.
Good point. I think it's doable.
Let me land this PR and open a new one for it.
@agnes512 Please fix CI failures. |
Co-authored-by: Nora <[email protected]> Co-authored-by: Miroslav <[email protected]>
888bdcd
to
b99c96b
Compare
@agnes512 when can we expect this to be released ? I have taken a latest update but the inclusion resolver is not available there. |
@samarpanB it will probably be released later today, worst case in 3-4 days 😄 |
Is it possible to release today? Actually I need to use it in one of my ongoing project. I don’t want to use the poor mans inclusion resolver 😊 |
@samarpanB we've just released! thanks for waiting~! |
resolves #3447
This PR implements the inclusionResolver for
hasMany
relation:flattenTargetsOfOneToManyRelation
and its unit tests forhasMany
createHasManyInclusionResolver
to hasMany factory.hasManyInclusionResolver
inrepository-tests
.hasManyInclusionResolver
, and the basic setup/usages.Suggested way to review:
-> start with the document file and
hasmany-inclusion-resolver.acceptance.ts
to get the idea of the inclusion resolver-> review
has-many.inclusion-resolver.ts
to see the implementation details.-> review the rest of files.
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈