Skip to main content

Advanced - examples at advanced demo app

DATOs/DTOs classes examples

  • Standard object:
    • DATO (defining MongoDB/GraphQL metadata - what data should exists in specific MongoDB collection, and what data exposed in relevant GraphQL responses): here.
    • Input DTO (defining input parameters): here.
    • Update DTO (defining update parameters): here.
  • Embedded (i.e. not refernced) objects:
  • Virtual (calculated) objects: class UserInfo.

DATOs/DTOs properties examples

  • Passing types (embedded class, enum...) to property decorator:
    • Specify embedded class type:
    • Specify enum type:
    • Specify GraphQL scalar type:
  • Specify objects relation (applicable only at DATO, not in DTO):
    • One-to-one relation: here.
    • One-to-many relation: here.
    • Many-to-one relation: here.

Modules and services examples

  • Resource service: here.
  • Resource resolver: here.
  • Resource module: here.
  • App module: here.

Create custom mutations/queries examples

The 'nestjs-query-simple' package inherently supports standard CRUD operations. If you intend to include custom mutations or queries, refer to the 'demonstrateComplexQuery()' example method:

Override a default mutations/queries examples

If you wish to customize default mutations or queries, refer to the 'createOne()' method in the example here. A similar approach can be applied in the resolver as well.

Inject a service into another service examples

If you wish to access a service from another service (e.g. to handle some asspects of relations between MongoDB documents), refer to usage of TenantsService within TenantBillingsService (this done in order to maintain the one-to-one relation, between 'TenantBillingDato' and 'TenantDato', at the 'TenantDato' side):

  • Consuming the injected service: here.
  • Using the injected service: here.
  • Importing the injected service's module: here.
  • Exporting the injected service: here.
  • Handle the injections in tests: see usage of 'TenantsService', 'TenantDato' and 'tenantId', here and here.