Setup Stellate in CI

While Stellate offers caching functionality without knowing anything about your schema, some features rely on us knowing the structure of your GraphQL API. To automate schema updates and at the same time manage your Stellate service configuration as Configuration-as-Code, we recommend setting up your CI system to push changes to Stellate whenever you deploy to production.

  1. Pull your service's latest stellate.ts configuration file your service with the stellate pull command. Specify the --service argument set to your service's name, for example:

    npx stellate pull --service demo-app
    

    Commit your service's stellate.ts file to your repository. Also, make sure to regularly commit an up-to-date version of the configuration file to your repository if you make changes to your services configuration via the online dashboard.

  2. Create a Personal Access Token for your account at <https://stellate.co/app/settings/access-tokens>.

  3. Set the STELLATE_TOKEN environment variable in your CI service to the personal access token created in step 2.

  4. Add a task to your CI service for your desired branch, which runs npx stellate push. This command will push your GraphQL schema and configuration changes to Stellate.

Provider Specific Instructions

Below are specific CI provider configurations. If your CI provider is not on this list contact us at support@stellate.co, we'd be happy to help you configure it correctly!

GitHub Actions

To do this from GitHub Actions, add a file named .github/workflows/stellate.yml with the following contents and add the token you created as an encrypted secret to your repository.

.github/workflows/stellate.yml

name: Stellate
on:
  push:
    branches:
      - main

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 'lts/*'
          check-latest: true
          cache: 'npm'
      - name: Push to Stellate
        run: npx stellate push
        env:
          STELLATE_TOKEN: ${{ secrets.STELLATE_TOKEN }}

GitLab CI

For GitLab CI, add (or extend) your .gitlab-ci.yml configuration at the root of your repository.

You'll also need to configure your Stellate token as a masked and protected CI/CD variable. You'll find that section in your project settings, within the CI/CD settings page. See GitLab's documentation on CI/CD Variables for more information.

.gitlab-ci.yml

config_push:
  image: node:lts
  cache:
    paths:
      - node_modules
  rules:
    - if: '$CI_COMMIT_BRANCH =~ /^main/'
  script:
    - npx stellate push

You might also want to update the rules section to your needs. The Gitlab documentation on rules has a good overview of how this works. Our example above pushes the configuration for each commit on the main branch.

CircleCI

Configure your Stellate token as an environment variable in a CircleCI Context and make sure that the jobs are configured to use that context.

.circleci/config.yml

version: 2.1

jobs:
  stellate:
    docker:
      - image: cimg/node:lts
    steps:
      - checkout
      - run: npx stellate push

workflows:
  version: 2.1
  config_push:
    jobs:
      - stellate:
          context:
            - stellate