CLI Commands

The commands below can be used with the Grafbase CLI.

You use the init command to initialize a new project, or existing project.

cd my-project npx grafbase init

The init command will create the new directory grafbase that contains your schema, environment variables, and more.

You can use the following flags when invoking init:

  • --template — The name or GitHub URL of the template to use for the new project.
npx grafbase init --template blog

You use the dev command to start the local Grafbase server.

npx grafbase dev

You can then visit the following URLs to access:

You can override the default behaviour of dev by passing various flags.

  • -p, --port <PORT> — Set a different port the server runs on. Defaults to 4000.
  • -s, --search — If a given port is unavailable, search for another.
  • --log-level-functions <LOG_LEVEL> — Log level for function invocations. Defaults to log-level.
  • --log-level-graphql-operations <LOG_LEVEL> — Log level for GraphQL operations. Defaults to log-level.
  • --log-level-fetch-requests <LOG_LEVEL> — Log level for fetch requests. Defaults to log-level.
  • --log-level <LOG_LEVEL> — Log level for fetch requests.
  • -v, --verbose — A shortcut to enable detailed logging.
  • --disable-watch — Disable restarting the server when a change to your schema is detected.
  • -h, --help — Print help.

Possible <LOG_LEVEL> values: none, error, warn, info, debug

You should use the login command to authenticate with your Grafbase account so you can create and deploy projects without leaving the CLI.

npx grafbase login

You will be redirected to the Grafbase Dashboard to verify linking your account.

You should configure the environment variable GRAFBASE_ACCESS_TOKEN for use inside of CI/CD, such as GitHub Actions.

You should use the create command to create a new Grafbase project.

Your project will be deployed automatically once created.

npx grafbase create

You can pass the following flags with the create command:

  • -n, --name <NAME> — The name for the new project.
  • -a, --account <SLUG> — The slug of the account in which the new project should be created.
  • -h, --help — Print help

You must pass all arguments if you opt out of the interactive prompt.

You should use the deploy command to redeploy an existing project.

npx grafbase deploy

You can use the reset command to reset your project data:

npx grafbase reset

This does the same as deleting the .grafbase directory.

You can use the help command to list the available commands and options, as well as the installed version details.

npx grafbase help
Was this page helpful?