-
Notifications
You must be signed in to change notification settings - Fork 11
Add Inflector
Alex Ald edited this page Apr 30, 2019
·
2 revisions
If you're not happy with the default naming conventions in PostGraphile (or if you want to extend PostGraphile's functionality and use the inflection system to do so), you can use this decorator. A decorator for PostGraphile's makeAddInflectorsPlugin.
Decorator takes a single parameter of type AddInflectorOptions
interface AddInflectorOptions {
inflector: string;
overwriteExisting?: boolean;
}
Visit PostGraphile's docs, for more information about the parameters.
@ProcessSchema({ inflector: '...' })
public inflector(typeName: string) {
...
}
If you want *Patch types to instead be called *ChangeSet, you could use the ProcessSchema
to implement it.
Note: This example was taken from the PostGraphile docs, and updated to be used with the decorator.
import { upperCamelCase } from 'graphile-build';
@Injectable()
export class CustomPostGraphileInflections {
@ProcessSchema({ inflector: 'patchType', overwriteExisting: true })
public inflector(typeName: string) {
return upperCamelCase(`${typeName}-change-set`);
}
}
Be sure to add the class as a provider to your module
@Module({
imports: [
PostGraphileModule.forRoot({
pgConfig: process.env.POSTGRAPHILE_URL,
}),
],
providers: [CustomPostGraphileInflections],
})
export class AppModule {}