How to sync GraphQL schema changes (from CI)

While GraphCDN 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 GraphCDN service configuration as Configuration-as-Code, we recommend setting up your CI system to push changes to GraphCDN whenever you deploy to production.

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

    npx graphcdn pull --service demo-app
    

    Commit your service's graphcdn.yml 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://graphcdn.io/dashboard/settings.

  3. Set the GRAPHCDN_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 graphcdn push. This command will push your GraphQL schema and configuration changes to GraphCDN.

Provider Specific Instructions

Below are specific CI provider configurations. If your CI provider is not on this list contact us at [email protected], we'd be happy to help you configure it correctly!

GitHub Actions

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

name: GraphCDN
on: 
  push: 
    branches: 
      - main 

jobs: 
  main: 
    runs-on: ubuntu-latest
    steps: 
      - uses: actions/[email protected] 
      - uses: actions/[email protected] 
        with: 
          node-version: '16.3.0'
          check-latest: true 
      - name: Push to GraphCDN
        run: npx graphcdn push 
        env: 
          GRAPHCDN_TOKEN: ${{ secrets.GRAPHCDN_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 GraphCDN 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 Project Variables for more information.

config_push:
  image: node:16.3.0
  cache:
    paths:
      - node_modules
  rules:
    - if: '$CI_COMMIT_BRANCH =~ /^main/'
  script:
    - npx graphcdn 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 GraphCDN token as an environment variable in a CircleCI Context and make sure that the jobs are configured to use that context.

jobs: 
  graphcdn: 
    docker: 
      - image: cimg/node:16.3.0 
    steps: 
      - checkout 
      - run: npx graphcdn push 

workflows:
  config_push:
    jobs:
      - graphcdn:
          context:
            - graphcdn

Did this page help you?