Skip to main content

CLI

Grats includes a command-line utility for extracting your project's GraphQL schema.

Grats gets both it's configuration options and the set of TypeScript files to scan from your project's tsconfig.json file. By default Grats uses the TypeScript's own algorithm for locating your project's tsconfig.json. However, if you wish to use a different tsconfig.json file, you can specify it with the --tsconfig option.

tip

For guidance on how to make Grats easy run in your project see Workflows.

Build (default command)

Writes your GraphQL schema in SDL format to stdout, or a file.

npx grats --output=./schema.gql

Options

Usage: grats [options] [command]

Extract GraphQL schema from your TypeScript project

Options:
-V, --version output the version number
-o, --output <SCHEMA_FILE> Where to write the schema file. Defaults to stdout
--tsconfig <TSCONFIG> Path to tsconfig.json. Defaults to auto-detecting based on the current working directory
-h, --help display help for command

Commands:
locate [options] <ENTITY>

Locate

Reports the location at which a given type or field is defined in your code.

Can also be used programmatically by other tools. For example the click-to-definition feature of an GraphQL editor integration could use invoke this command to find the location of a type or field.

For example, Relay's VSCode Extension is exploring adding the ability to leverage such a tool.

# Locate a field
npx grats locate User.name

# Locate a named type
npx grats locate User

Options

Usage: grats locate [options] <ENTITY>

Arguments:
ENTITY GraphQL entity to locate. E.g. `User` or `User.id`

Options:
--tsconfig <TSCONFIG> Path to tsconfig.json. Defaults to auto-detecting based on the current working directory
-h, --help display help for command