---
description:
  Learn about GraphQL Mesh CLI commands, such as mesh dev, build, validate, start, and serve-source.
  Customize options with global flags.
---

import { Callout } from '@theguild/components'

# CLI commands

## Global Options

All commands can take two global optional options.

### `-r (alias: require) [array]`

Loads specific require.extensions before running the codegen and reading the configuration.

```sh /-r/
yarn graphql-mesh -r lodash
```

```sh /--require/
yarn graphql-mesh --require lodash fluke2
```

### `--dir [string]`

Used to modify the base directory for looking for a `.meshrc` config file.

```sh /--dir/
yarn graphql-mesh --dir ./mystuff/meshproject
```

## List of Commands

### `mesh dev`

Serves a GraphQL server with a GraphQL interface to test your Mesh API locally.

Can have an optional `--port` argument.

<Callout>GraphQL Mesh does not currently support hot reloading.</Callout>

**Options**

**`--port [number]`**

The system port on which graphql-mesh will be made available.

This should be one of the normal system ports [1-65386] not currently used by any other service.

```sh /--port/
yarn graphql-mesh dev --port 4002
```

### `mesh build`

Builds artifacts required to use `mesh start` for a gateway (production) server or SDK.

Can have `--throwOnInvalidConfig` to make CLI throw in case of an invalid configuration. By default,
CLI gives a warning and continues.

### `mesh validate`

Validate the built artifacts (`mesh build`) required to use `mesh start` for a gateway (production)
server. The validation will check the following:

- presence of the `.mesh/` folder
- validation of the mesh configuration (see
  [`packages/legacy/types/src/config-schema.json`](https://github.com/ardatan/graphql-mesh/blob/master/packages/legacy/types/src/config-schema.json))
- configured sources are valid

More information about this on the [Mesh deployment](/docs/getting-started/deploy-mesh-gateway)
page.

### `mesh start`

Serves a GraphQL server using the built artifacts. `mesh start` compared to `mesh dev` does not rely
on the sources to build the schema. Instead, it uses the built artifacts. Therefore, `mesh start` is
recommended to start a mesh server in production.

More information about `mesh start` on the
[Mesh deployment](/docs/getting-started/deploy-mesh-gateway) page.

Can have an optional `--port` argument.

**Options**

**`--port [number]`**

The system port on which graphql-mesh will be made available.

This should be one of the normal system ports [1-65386] not currently used by any other service.

```sh /--port/
yarn graphql-mesh start --port 4002
```

### `mesh serve-source`

`serve-source` helps with quickly assessing that Mesh properly ingests a source. Given a source name
as the only argument, Mesh will serve a GraphQL API only exposing the given source.

This command is handy to debug a source.

**Example**

Given the following configuration:

```yaml filename=".meshrc.yaml"
sources:
  - name: Cities
    handler:
      openapi:
        source: https://api.apis.guru/v2/specs/mashape.com/geodb/1.0.0/swagger.json
    transforms:
      - rename:
          - from:
              type: Error
            to:
              type: CitiesError

  - name: Weather
    handler:
      openapi:
        source: https://api.apis.guru/v2/specs/weatherbit.io/2.0.0/swagger.json
    transforms:
      - rename:
          - from:
              type: Error
            to:
              type: WeatherError
```

You can test that the "Weather" source is properly ingested by mesh by running:

```sh
yarn graphql-mesh serve-source Weather
```

Then, Mesh will serve a GraphQL API only exposing the "Weather" source.
