Getting started
Configuration
On this page
Gratos has a few configuration options. Set them under the "grats" key of your project's tsconfig.json, beside compilerOptions. Each model sample of these docs has one, which extends a shared base for its compiler options:
{
"extends": "../tsconfig.base.json",
"include": ["*.ts"],
"grats": {
"graphqlSchema": "./generated/schema.graphql",
"tsSchema": "./generated/schema.ts",
"importModuleSpecifierEnding": ".ts",
"schemaHeader": null
}
}Options
Every option is optional. Here is each one, with its type, its description and its default value.
graphqlSchema
string. Where Gratos writes your schema file. The path is relative to the tsconfig.json file.
Default: "./schema.graphql"
tsSchema
string. Where Gratos writes your executable TypeScript schema file. The path is relative to the tsconfig.json file.
Default: "./schema.ts"
tsClientEnums
string | null. Where Gratos writes your TypeScript enums file. The path is relative to the tsconfig.json file.
When it is set, Gratos requires every GraphQL enum to be defined with an exported TypeScript enum. null emits no such file.
Default: null
graphqlSchema, tsSchema and tsClientEnums must name different files, compared without regard to letter case (so Schema.ts and schema.ts count as one file, even on a case-sensitive file system): when two of them are one file, also through a symbolic or hard link, gratos fails and writes nothing.
nullableByDefault
boolean. Whether every field is nullable, following GraphQL best practices.
A field can declare itself non-nullable with the docblock tag @killsParentOnException (see Field nullability).
Default: true
strictSemanticNullability
boolean. An experimental feature that adds @semanticNonNull to every field whose TypeScript return type is non-null, but which the nullableByDefault option makes nullable.
It lets clients that handle errors out of band, for example by discarding responses with errors, know which fields are non-null when there is no error. See Strict semantic nullability.
Enabling strictSemanticNullability with nullableByDefault off is an error.
Default: false
reportTypeScriptTypeErrors
boolean. Whether Gratos reports an error when it finds a TypeScript type error.
Gratos always reports a TypeScript syntax error.
Default: false
schemaHeader
string | string[] | null. Text prepended to the generated schema file: a copyright header, say, or how to regenerate the file. null omits the default header.
Default: a two-line comment, "Schema generated by Gratos (based on Grats, https://grats.capt.dev)", then "Do not manually edit. Regenerate by running gratos."
tsSchemaHeader
string | string[] | null. Text prepended to the generated TypeScript schema file. null omits the default header.
Default: this comment, as in the generated schema.ts of every model sample:
/**
* Executable schema generated by Gratos (based on Grats, https://grats.capt.dev)
* Do not manually edit. Regenerate by running `gratos`.
*/tsClientEnumsHeader
string | string[] | null. Text prepended to the TypeScript enums file written when the tsClientEnums option is set. null omits the default header.
Default: a comment, "TypeScript enum definitions generated by Gratos (based on Grats, https://grats.capt.dev)", then "Do not manually edit. Regenerate by running gratos."
importModuleSpecifierEnding
string. An ending appended to every import path of the generated TypeScript schema file.
When you build a package that uses ES modules, import paths must not omit the file extension. In TypeScript code, this generally means import paths must end with .js (or .ts, when Node runs your TypeScript as it is, as in the samples above).
Default: ""
libraryImport
string. The module that exports the types Gratos reads (Int, Float, ID, GqlInfo, GqlScalar). The generated TypeScript schema imports GqlScalar from it, and error messages tell you to import Int, Float and GqlInfo from it. Gratos adds this option.
Default: "gratos"
EXPERIMENTAL__emitMetadata
boolean. Experimental: this option will be renamed or removed in a future release.
Writes a JSON file next to the generated schema file, with the metadata about the resolvers.
Default: false
EXPERIMENTAL__emitResolverMap
boolean. Experimental: this option will be renamed or removed in a future release.
Instead of a TypeScript file that creates a GraphQLSchema, writes a TypeScript file that creates a GraphQL Tools-style resolver map. An Effect field or a Stream subscription is then an error.
Default: false