You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(examples, docs): add typegoose discriminator e2e test and docs (#390)
### Description
This pull request introduces an end-to-end test for Typegoose
discriminators, adds crucial documentation for this feature, and fixes a
bug in array field filtering that was discovered during the
investigation.
#### Motivation
I began this work because I was unable to get Typegoose discriminators
working correctly in my own application. The existing examples and
documentation did not cover this specific use case, making it difficult
to debug. The primary goal was to create a fully functional, standalone
example and document the correct implementation pattern. In the process,
we also uncovered and fixed a separate, underlying bug in the query
library.
#### What's in this PR?
1. **New E2E Test for Typegoose Discriminators**
* A new example, `examples/typegoose-discriminators`, has been added.
* This example includes a robust e2e test that validates the full CRUD
lifecycle (create, query, update, delete) for discriminated entities.
2. **New Documentation for Discriminators**
* To make this powerful feature more accessible, a new "Discriminators"
section has been added to the Typegoose `relations.mdx` documentation.
* This new section provides a clear explanation and a complete code
example based on the new e2e test, demonstrating the correct pattern for
implementation.
3. **Bug Fix: Filtering on Array Fields**
* A bug was discovered that prevented filtering on array fields (e.g.,
`string[]`). This would cause an `Unable to create filter comparison for
[null]` error. I'm surprised this hasn't surfaced sooner, as using
arrays in MongoDB as fields is normal practice.
* The `FieldComparisonFactory` has been fixed to correctly infer the
type from array fields.
* A new unit test has been added to cover this specific case and prevent
future regressions.
#### Summary of Changes
* **feat(examples)**: Add new `typegoose-discriminators` e2e test.
* **docs(typegoose)**: Add documentation and example for using
discriminators.
* **fix(query-graphql)**: Correctly create filter comparisons for array
fields.
* **test(query-graphql)**: Add unit test for array field filter
creation.
* **test(query-graphql)**: Update existing unit tests to align with the
array filter fix.
This PR should make it much easier for future users to implement
Typegoose discriminators and resolves a tricky bug in the filtering
logic.
Hope it can be merged soon. 😁
Scott
Copy file name to clipboardExpand all lines: documentation/docs/persistence/typegoose/relations.mdx
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -401,3 +401,85 @@ export class TagDTO {
401
401
</TabItem>
402
402
</Tabs>
403
403
404
+
405
+
## Discriminators
406
+
407
+
Typegoose supports mongoose [discriminators](https://mongoosejs.com/docs/discriminators.html). `nestjs-query` provides support for them through the `NestjsQueryTypegooseModule`.
408
+
409
+
To use discriminators you need to define them in your `NestjsQueryTypegooseModule.forFeature` call.
410
+
411
+
When working with discriminators, `nestjs-query` requires you to provide a service class for each discriminated entity. This is necessary for the auto-generated resolvers to be created correctly. These service classes are also the perfect place to add any custom business logic for your discriminated entities.
0 commit comments