Skip to main content

Create your own app

Scaffolding

  • Read and apply steps explained in the Intro page.
  • Create your own copy of the sub-folder 'examples/minimal-demo-app'.
  • In the 'package.json' file (at the app's root folder) - replace values of name, author, etc.

Fix resource name

Within TS files

  • Replace any occurrence of 'ExampleItem' (match case, not match whole word) with the name of your resource, starting with an uppercase (e.g. 'User').
  • Replace any occurrence of 'exampleItem' (match case, not match whole word) with the name of your resource, starting with a lowercase (e.g. 'user').
  • The later 's' (plural form of the resource name) is supposed to remain (e.g. 'ExampleItemsResolver' should be changed to 'UsersResolver').

In the file system

  • Change the name of the folder 'exampleItems' - to the name (plural) of your resource (e.g. 'users').
  • Change the name of files started with 'exampleItem' - to start with the name (singular) of your resource (e.g. 'user').

Fix resource fields

  • Remove example fields ('exampleProperty1'/'exampleProperty2') from Datos/Dtos classes.
  • Set your desired fields.
  • For more complicated types (Enum/Int/Object...), or complicated relations (one-to-many, many-to-one, one-to-one), or other field spesifications (nullable, primaryKey...):
    1. See DATOs/DTOs properties examples.
    2. See more examples at properties of DATOs/DTOs classes, within advanced-demo-app code.
    3. Browse code documentation:

Use more DATOs/DTOs options

Add custom mutations/queries

Override a default mutations/queries

Inject a service into another service

Use the app

  • Install/build/run/use your app, in the same manner as explained in the Intro page.
  • Obviously you need to prepare/test your own mutations and queries at GraphQL playground.
  • Validate that the corresponding collection is updated in your MongoDB.

Add more resources

  • Get fresh copy of folder exampleItems, and repeat steps in the Fix resource name, Fix resource fields, Add custom mutations/queries and Override a default mutations/queries sections.
  • Add name of your new resource's module, to 'imports' list, at definition of main module of your app (file 'src/app.module.ts'), as shown here:
    @Module({
    imports: [
    AppCommonModule.forRoot('mongodb://localhost', console),
    ExampleItemsModule, // You probebly already replaced 'ExampleItem' with another name.
    // Add here your new resource's module.
    ],
    controllers: [],
    providers: []
    })

Test the app

Run those commands within the app's root folder:

# unit tests
npm run test

# e2e tests
npm run test:e2e

# test coverage
npm run test:cov

Run the app

Run those commands within the app's root folder:

# development
npm run start

# watch mode
npm run start:dev

# production mode
npm run start:prod