Skip to content

Options ​

Everything InverseModelModule.forRoot() and forRootAsync() accept.

ts
InverseModelModule.forRoot({
  url: process.env.DATABASE_URL!,
  ssl: true,
  cache: { url: process.env.REDIS_URL!, ttl: 60 },
  pagination: { defaultLimit: 100, maxLimit: 1000 },
  include: ['authors', 'blog_posts'],
  readOnly: ['audit_*'],
  graphql: { introspection: true },
});

Connection ​

OptionDefaultWhat it does
url(required)Connection string; its protocol picks the database. See Databases.
ssldriver defaulttrue, or { rejectUnauthorized, ca, cert, key } with PEM contents. See TLS.

API shape ​

OptionDefaultWhat it does
pagination.defaultLimit100Rows a list returns without limit.
pagination.maxLimit1000Largest limit accepted, and the most rows createMany and deleteMany write.
naming.typesingular PascalCase(table) => string: type name of a table, given its name as listed (schema-qualified where the database has schemas). See Naming.
naming.fieldcamelCase(column, table) => string: field name of a column.
naming.pluralEnglish plural(type) => string: plural of a type name, for lists, counts and to-many relations.
rename.tables{}Type name per table, e.g. { blog_posts: 'Article' }. See Renames.
rename.fields{}Field name per table.column, e.g. { 'authors.full_name': 'name' }.
views{}Per view name, primaryKey (columns) and foreignKeys ({ columns, table, references }). See Views.

Security ​

See Security.

OptionDefaultWhat it does
includeeverythingTables and table.column fields to expose; * matches any name.
excludenothingTables and fields to hide; wins over include.
readOnlyfalsetrue, or the tables that get no mutations.
queryLimits.maxDepth10Deepest nesting of fields a query may have.
queryLimits.maxComplexity50000Largest estimated cost of a query.
authorizeallow all({ model, type, operation, context, args }) => boolean | Promise<boolean>.
scopenone({ model, type, operation, context }) => Where | null, ANDed into reads, updates and deletes.

Cache ​

See Caching.

OptionDefaultWhat it does
cache.url(no cache)Redis connection string. Needs ioredis.
cache.ttl60Seconds a result is kept.
cache.ttlByTable{}TTL per table; 0 leaves a table uncached.
cache.keyPrefixinverse:Prefix of every Redis key.

Extending ​

See Extending the API.

OptionDefaultWhat it does
hooksnonePer table, or *: beforeCreate, afterCreate, beforeUpdate, afterUpdate, beforeDelete, afterDelete.
extend.typeDefsnoneSDL merged into the generated schema.
extend.resolversnoneResolvers, or a function of { connection, model, writes } that returns them.

Apollo ​

OptionDefaultWhat it does
graphql{}Any ApolloDriverConfig option except driver, typeDefs and resolvers, which come from the database: path, context, introspection, plugins, formatError…

forRootAsync ​

Takes the options from a factory, so they can come from @nestjs/config or any other provider:

ts
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot(),
    InverseModelModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        url: config.getOrThrow('DATABASE_URL'),
        cache: config.get('REDIS_URL') ? { url: config.get('REDIS_URL') } : undefined,
      }),
    }),
  ],
})
export class AppModule {}

useClass and useExisting work too, with a class whose createInverseModelOptions() returns the options. The options are injectable through the INVERSE_MODEL_OPTIONS token.

Released under the MIT License.