# How to Prevent GraphQL API Changes in Buffer

How we control API changes to preserve customer experience

- **Source:** [Overflow - Buffer Resources](https://brifing.si/source/a6c4ab48-d486-43b0-91d8-dcf0ac6c953d)
- **Published:** 2024-07-12
- **Topic:** [Software & Engineering](https://brifing.si/c/engineering)
- **Original article:** <https://buffer.com/resources/how-were-preventing-breaking-changes-in-graphql-apis-at-buffer-and-why-its-essential-for-our-customers/>
- **On Brifing:** https://brifing.si/s/4d120fa1-8a5b-44a0-9d17-258837e56ed2

## The Cost of API Breakages

Buffer's engineering team shares how changes in the GraphQL API affect clients. When breakages occur, user experience deteriorates, support requests increase, and teams lose time. Detecting these issues early is crucial.

## The Importance of Early Detection

Buffer's core strategy is to prevent problems rather than solve them. Checking changes before merging into the main branch prevents breakages. Automated schema comparison using GitHub Actions identifies issues at an early stage.

## Schema Comparison Process

The system compares two schema versions: the current PR branch and the main branch. Differences are analyzed to identify changes that risk breakage. This process runs automatically for all PRs modifying .graphql files.

## GitHub Actions Integration

Buffer's custom GitHub Action runs when a PR is opened, reopened, or synchronized. It triggers only for changes in the graphql/ directory to avoid unnecessary workload. It operates on an Ubuntu-based runner.

## Technical Infrastructure

The system uses Node.js 18 and graphql-tools libraries. The @graphql-tools/load-files and @graphql-tools/merge packages combine scattered schema files. Comparison is performed on the resulting single schema file.

## Schema Merging Mechanism

The loadFilesSync function loads all .graphql files, merging them with mergeTypeDefs. The result is saved as a single GraphQL schema file. This process is done separately for both the PR branch and the main branch.

## Change Analysis

Differences between the two schema versions are thoroughly examined. All changes that could cause backward incompatibility (field removal, type changes, etc.) are identified. Buffer emphasizes the importance of performing this check as early as possible.

## PR Feedback

Analysis results are added as comments directly on the PR page. If there's a breakage risk, the PR cannot be merged. Developers can clearly see which change caused the issue and take corrective action.

## Integration Benefits

This system allows Buffer to completely prevent API changes that affect clients. Customer satisfaction is maintained while reducing the support team's workload. Engineers can focus on developing new features instead of firefighting.

## Transparency Culture

Buffer contributes to the community by sharing this technical solution as open source. As part of its 'open build' culture, it helps other teams solve similar problems. This approach aligns perfectly with the company's values.

## Scalable Solution

The developed system manages increasing API complexity as Buffer grows. It's designed to adapt to different GraphQL schemas and large team collaborations. GitHub Actions' flexible structure allows for easy future enhancements.

## Customer-Centric Engineering

Buffer's approach reflects an engineering culture centered on customer experience. Proactive measures prevent breakages and build trust. This system stands out as one of the best practices in API development.

## Sources covering this story

- https://buffer.com/resources/how-were-preventing-breaking-changes-in-graphql-apis-at-buffer-and-why-its-essential-for-our-customers/ — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
