Branches

Now our GraphQL API is deployed to the Edge, we can now use Branches to diverge from our production schema when working on new features that consumes the API.

We currently have a schema for Post and Comment. We'll create a new branch in our code to add a new type and relation for Vote.

Let's begin by creating the branch add-vote. You can use the command line, or the GitHub app to do so.

git switch -c add-vote

Then inside of grafbase/schema.graphql add the new type Vote with a field for id, and the post it belongs to. We must also update the Post model to contain the "has many" relation to Vote:

type Post @model {
  id: ID!
  title: String!
  url: URL! @unique
  votes: [Vote]
  comments: [Comment]
}

type Vote @model {
  id: ID!
  rating: Int
  post: Post!
}

type Comment @model {
  id: ID!
  message: String!
  post: Post!
}

That's it! You can run and test this schema locally using the Grafbase CLI, but let's commit and push to GitHub to continue.

Now commit this code using the command line or the GitHub. Don't forget to add a commit message!

git add grafbase/schema.graphql
git commit -m "feat: add vote model type and relation"

Next push this branch and commit to GitHub:

git push

That's it! Grafbase will automatically detect this new branch and immediately deploy a preview.

Grafbase Branch Deployment

You can then from here inspect the schema for any changes, as well as interact with the Playground in a fully isolated environment away from your production data.

Grafbase Schema Diff

Now we have a branch with some schema changes, it's time to promote it to production! We can merge our add-vote branch with main by using a Pull Request.

GitHub Open Pull Request

As soon as you merge the open Pull Request, Grafbase will automatically deploy it to production!

Was this page helpful?