Slash-graphql, Your Command Line Tool for Slash GraphQL - Dgraph Blog

Today we are releasing slash-graphql, a command line to managing your Slash GraphQL backends, without ever leaving your command line.

We’ve been getting loads of queries asking how you’d automatically apply your schema to your DB on a git push, or how you could automatically drop data from a staging cluster and load it with production data.

Let’s walk through how we’d use it.

A journey of a thousand miles starts with an npm install

Let’s get started by installing the slash-graphql from npm. If you have node installed on your laptop, just fire up a terminal and run:

npm i -g slash-graphql

If you don’t have node installed, you can download from the website.

Once it’s installed, let’s go ahead and log in using the command below.

slash-graphql login

You should see a message that looks like the following in your terminal, and your browser should pop up asking you to confirm your login, as seen below:

![](upload://5nfnJmyW5QyGcPAz7iWattiO5IH.png)

Click the continue button to authorise the command line tool. If you aren’t logged in to Slash GraphQL in that browser, it will ask you to log in first.

Duplicating is the sincerest form of flattery

By now, you should have tried out the Slash GraphQL Quick Start. Let’s make sure that backend is still around, and fetch the schema as we last applied it.

slash-graphql list-backends
slash-graphql get-schema -e https://your-subdomain.region.aws.cloud.dgraph.io/graphql

![](upload://7UsPtGLCz2UGt3q67UF6G4doQJr.png)

Yup, that looks like how we left it. Let’s export all that data

slash-graphql export-data -e https://your-subdomain.region.aws.cloud.dgraph.io/graphql

![](upload://3Hpt1251wGECeB3NZd3iAQcc2vw.png)

Next, let’s create a new database, and load it up with the schema we just exported.

slash-graphql create-backend "Another Todo App"
cat ./data/g01.schema.gz | guzip | slash-graphql update-schema -e https://your-subdomain.region.aws.cloud.dgraph.io/graphql "Another Todo App"

![](upload://3i7aNfS2Xub07xT6IHNLXavQPIx.png)

And finally, let’s import our data in (this bit needs you to have docker installed)

slash-graphql import-data -e https://your-subdomain.region.aws.cloud.dgraph.io/graphql ./data

![](upload://xgGe8r512ixeEZjvge3gBBWhki2.png)

Running slash-graphql from a CI/CD

Unfortunately, there are still a few limitations when using slash-graphql on a CI/CD type environment. We issue auth tokens using auth0, and each auth token is only valid for a few hours before it has to be refreshed (which the command line tool does automatically as long as it has access to the filesystem at ~/.config/slash-graphql/auth.yml).

However, in cloud CI/CD environment, this might be difficult to ensure that the refresh token is used only once (the refresh key is also rotated after use).

As a workaround, we have it so that most of the APIs that work on a single backend (such as manipulating schemas, imports and exports) all work with an API token that can be issued from the Slash GraphQL interface, passing in the -t argument.

As an example, you can fetch the schema from a an instance as follows

slash-graphql get-scheme -e https://my.endpoint.could.dgraph.io/graphql -t secretTokenHere

Standing on the shoulders of Giants

slash-graphql is built with the Open CLI Framework from the fine developers at Heroku, which we can’t recommend enough the next time you want to build out a command line app.

ReferencesTop image: Be a NASA Flight Director
![](upload://f8P4YQu9uFeuFFfWlKCOlw5k9gh.jpeg) Tejas Dinkar, Author

Tejas heads the Slash GraphQL team at Dgraph. He cares a lot about code quality and loves learning about new programming languages and paradigms. Tejas started his career at ThoughtWorks, and was an early employee / founder of multiple startups including C42 Engineering, Nilenso and Quintype.


This is a companion discussion topic for the original entry at https://dgraph.io/blog/post/slash-command-line/
1 Like

There is a typo.Correct package name is “slash-graphql”.

Hey, thanks for reporting, we have fixed the typo

Hi when I run export-data I came up with an error
slash-graphql export-data -e https://dgrapxxxx.aws.cloud.dgraph.io/graphql -t xxxxxxx ./backup

Exporting Data, this might take a few minutes
Downloading [=============---------------------------] 33%    TypeError: Cannot read property 'length' of null