More ways to manage graphs from the CLI
Today we introduce new commands to the Grafbase CLI for graph management. The focus is to enable CI based workflows to define branches and environment variables.
Additionally the deploy
command gained a feature to define the branch for the deployment. The command outputs the deployment process directly to the terminal, and returns a non-zero exit code if the deployment was not successful.
The commands for modifying branches should not be used together with a graphs which follow changes from a GitHub repository. For users who like the GitHub workflow, the old ways of deploying and managing branches still exist.
Traditionally the grafbase deploy
command was meant to deploy a new version of the graph from the developer's command line; to try out the graph on production without pushing code to GitHub. A typical workflow so far is to link the new graph to a GitHub project, and trigger a new deployment when code is merged to the branch. This is not always feasible for a graph, sometimes it is better to have more control when to deploy a new graph.
A grafbase deploy
command could not be executed if the current project was not linked to a Grafbase graph. This could be quite tedious on CI, so we added a new parameter --graph-ref
, which can be used to define the graph and branch for the deployment. If the parameter is given, the CLI will not expect to be on a linked project, and the deployment can be triggered for example from a GitHub Action.
It would also be beneficial to fail a CI workflow if a deployment is not successful. Previously, the grafbase deploy
would just return immediately after a successful API call. The deployment would run asynchronously in the Grafbase platform, and it could lead to a failure. We changed this, and now when deploying a graph, the deploy command will display the log output from the platform and exit with a non-zero code which can be used to fail the CI action.
In the latest version of Grafbase CLI, we introduce new commands to list and modify branches. The first one allows listing branches with their latest deployment and the status of that deployment:
❯ grafbase branch ls
Grafbase CLI 0.71.0
BRANCH GRAPH ACCOUNT LATEST DEPLOY STATUS
main* test-project julius-grafbasecom 4d 1h ago succeeded
We see one branch (main
), the graph and account, and how latest deployment happened four days ago successfully.
A new branch can be created using the grafbase deploy
command:
❯ grafbase deploy --graph-ref julius-grafbasecom/test-project@test
Grafbase CLI 0.71.0
🕒 Your graph is being deployed...
18:01:05.293 INFO Installing dependencies...
18:01:15.530 INFO Dependency installation finished: 1.49s
18:01:18.472 INFO GraphQL schema generation finished: 2.57s
18:01:31.567 INFO Deployment completed
✨ Your graph was successfully deployed!
Now we see a new branch in our listing:
❯ grafbase branch ls
Grafbase CLI 0.71.0
BRANCH GRAPH ACCOUNT LATEST DEPLOY STATUS
main* test-project julius-grafbasecom 4d 1h ago succeeded
test cors-test-project julius-grafbasecom 3m 7s ago succeeded
If the branch is no longer needed, the branch remove
command removes it from the Grafbase platform:
❯ grafbase branch rm julius-grafbasecom/test-project@test
Grafbase CLI 0.71.0
🕒 Branch is being deleted...
✨ The branch was successfully deleted!
The production branch is restricted, and cannot be removed from the CLI. In the listing, the production branch is marked with a *
after its name.
The new commands will make it easier to manage graphs directly from the CI, and make it much simpler to enroll secrets from the CI directly to the Grafbase platform. The documentation for the new CLI commands can be read from the documentation website, and the source code for the CLI is available in our GitHub repository.