Gratos' interface is a command-line tool, gratos, that extracts your project's GraphQL schema. It aims to be friendly and helpful: expect its error messages to guide you to a solution.

gratos reads its configuration options from your project's tsconfig.json. By default, it uses the nearest tsconfig.json from the current directory. To use another one, name it with the --tsconfig option.

Tip

To make Gratos easy to run in your project, see Workflows.

Build (the default)

gratos writes a TypeScript module that exports an executable GraphQL schema, and a .graphql file that holds the schema's text. By default, it writes them next to your tsconfig.json; to put them elsewhere, configure it in your tsconfig.json. It writes only the files that are out of date, and leaves the others untouched.

Watch mode

gratos has no --watch: TypeScript 7 does not expose the watch API it would need. To rebuild as you work, restart your app on every save with node --watch-path, and boot it through the lazy gratos/dev entry, which regenerates the schema before it loads the app. A save then gives you a fresh schema and a restarted server. The example app's dev script does both (GRATS_DEV=1 turns on the gratos/dev boot):

examples/orders/package.json
"dev": "GRATS_DEV=1 node --watch-path=src/models --watch-path=src/services --watch-preserve-output src/server.ts",

A restart drops whatever the process held in memory: open subscriptions end, and caches start empty. The development loop shows the boot, and what the app serves while the models do not build.

Check

gratos --check writes nothing, and exits with status 1 when a generated file is missing or out of date. Run it in CI (see Workflows).

Not in Gratos

  • gratos has no --fix: fix each diagnostic by hand, as its message says (a docblock tag's casing, a deprecated tag).
  • gratos has no locate command: search your code for the type or field, whose GraphQL name is its TypeScript name unless a tag renames it.
  • gratos has no editor plugin: run gratos or gratos --check to see its diagnostics.

Options

Option What it does
--tsconfig <path> The tsconfig.json to read. Defaults to the nearest one from the current directory
--check Writes nothing; exits with status 1 if a generated file is missing or out of date
--version, -v, -V Prints the version
--help, -h Prints the help, which also lists the CLI framework's own flags (--wizard, --completions, --log-level)

The command's own options, as gratos defines them:

packages/gratos/src/cli.ts
tsconfig: Flag.String("tsconfig").pipe(
  Flag.withDescription(
    "Path to tsconfig.json. Defaults to the nearest tsconfig.json from the current directory.",
  ),
  Flag.optional,
),
check: Flag.Boolean("check").pipe(
  Flag.withDescription(
    "Write nothing; exit with status 1 if a generated file is missing or out of date.",
  ),
  Flag.withDefault(false),
),