Running the Local GraphQL API

The TinaCMS CLI can be used to set up your project with a TinaCMS schema configuration, and run a local version of the TinaCMS GraphQL API (using your filesystem's content). For a real-world example of how this is being used checkout the TinaCloud Starter.

Installation

The @tinacms/cli package will be installed as a dev dependency with the tina init command.

This will setup a dummy tina/config.{js,ts} in your site, and install any required TinaCMS dependencies.

Running the GraphQL API

tinacms dev will compile the schema into static files, generate typescript types for you to use in your project, and start a GraphQL server on http://localhost:4001

This command also takes an argument (-c) that allows you to run a command as a child process. This is very helpful for running a dev server and building your next.js app. The scripts portion of your package.json should look like this.

The reason we want to run the GraphQL API with our site is so that:

  • When our static pages build in CI, they can source their content from the local files using the GraphQL API.
  • In development, we can test out TinaCMS with our local files.

Now if you run the updated dev script with:

or

Your live site will run, but so will a local version of the GraphQL Content API.

Your console might show something like:

Once the graphql server is running, you can start to explore your graphQL content through the Altair client at http://localhost:3000/admin/index.html#/graphql