Configuration
There's both codegen and runtime configuration of the ent framework.
codegen
codegen can be configured in a yml file in order of precedence (from the root of the project):
- a
ent.yml
file - a
src/ent.yml
file - a
src/graphql/ent.yml
file
The root of codegen configuration is the codegen
key in the file.
The following properties can be configured:
defaultEntPolicy
configures the Privacy Policy in base class of generated Ents. Overrides the default privacy policy. See PrivacyConfig for the expected format.defaultActionPolicy
configures the Privacy Policy in base class of generated Actions. Overrides the default privacy policy. See PrivacyConfig for the expected format.prettier
configures prettier. We currently use prettier to format the entire codebase after codegen to ensure a consistent format in the generated files. If you already have a prettier configuration or want to override the glob passed to prettier (default issrc/ent/**/*.ts
), use this option. See PrettierConfig for the expected format.relativeImports
configures where to use relative imports in generated files instead ofsrc/ent/user
etc. needed for legacy scenarios or situations where the custom compiler has issues.disableGraphQLRoot
: the default graphql root is src/graphql/index.ts. if integrating into an existing project (with an existing root) or just want to do something different, set this to truegeneratedHeader
: add header to each generated file in addition to "Generated by github.com/lolopinto/ent, DO NOT EDIT."disableBase64Encoding
: disable base64encoding of id fields. When set to true, id fields aren't resolved with nodeIDEncoder and the actual uuid or integer is sent to the clientgenerateRootResolvers
: for each type exposed to GraphQL instead of node(). Should be used in combination withdefaultGraphQLMutationName
: default names for graphql actions|mutations is nounVerb e.g. userCreate. If you wanna change it to verbNoun e.g. createUser, set this field toVERB_NOUN
defaultGraphQLFieldFormat
: default format for fields is lowerCamelCase e.g. firstName. If you wanna change it to snake_case e.g. first_name, set this field to snake_caseschemaSQLFilePath
: if we should generate schema.sql file and path to generate itglobalImportPath
: path to add to src/ent/internal.ts so that it's included everywhere. Where things like global augmentation can be doneuserOverridenFiles
: list of files to not override during codegen i.e. because there's a bug in codegen and the user has decided to override it.transformLoadMethod
: if set, overrides the loadNoTransform(X) methods to be this instead of the default loadNoTransform(X)transformDeleteMethod
: if set, overrides the saveWithoutTransform(X) methods to be this instead of the default saveWithoutTransform(X)disableDefaultExportForActions
: by default, actions are exported withexport default
. This changes that to named defaults.
PrivacyConfig
Following fields supported:
policyName
(string. required). name of default privacy policypath
(string. required). path to import to get the policyclass
(boolean. optional). indicates if the policy is a class as opposed to a constant.
PrettierConfig
Following fields supported:
custom
(boolean. optional). indicates there's already a custom prettier configuration that should be used. Depends on prettier finding the configurationglob
(string. optional). glob to pass to prettier instead of defaultsrc/ent/**/*.ts
runtime
Because there could be so many possible entrypoints into the framework e.g. GraphQL endpoint, REST API endpoint, tests, migration script, etc, there's no way to automatically configure runtime behavior so it has to be done manually via calling loadConfig
.
loadConfig
loadConfig takes an optional file, Buffer or Config
. If nothing is passed, it assumes local ent.yml
file, if string is passed, it assumes yml file and attempts to read and parse it.
loadConfig(file?: string | Buffer | Config): void;
type logType = "query" | "warn" | "info" | "error" | "debug";
export interface Database {
database?: string;
user?: string;
password?: string;
host?: string;
port?: number;
ssl?: boolean;
sslmode?: string;
}
export type env = "production" | "test" | "development";
export declare type DBDict = Partial<Record<env, Database>>;
export interface Config {
dbConnectionString?: string; // raw db connection string
dbFile?: string; // config/database.yml is default
db?: Database | DBDict;
log?: logType | logType[]; // logging levels.
// config for codegen. not relevant when loadConfig is called but have it here for posterity
codegen?: CodegenConfig;
}
interface CodegenConfig {
defaultEntPolicy?: PrivacyConfig;
defaultActionPolicy?: PrivacyConfig;
prettier?: PrettierConfig;
}
interface PrettierConfig {
custom?: boolean;
// default glob is 'src/**/*.ts', can override this
glob?: string;
}
interface PrivacyConfig {
path: string; // e.g. "@snowtop/ent"
policyName: string; // e.g. "AlwaysAllowPrivacyPolicy";
class?: boolean;
}
Example
log:
- query
- error
- warn
- info
codegen:
defaultEntPolicy:
path: "@snowtop/ent"
policyName: "AlwaysAllowPrivacyPolicy"
defaultActionPolicy:
path: '@snowtop/ent'
policyName: 'AlwaysAllowPrivacyPolicy'
prettier:
custom: true