What is @graphql-inspector/diff-command?
@graphql-inspector/diff-command is a tool that helps you detect changes in your GraphQL schema. It allows you to compare two GraphQL schemas and identify breaking changes, dangerous changes, and safe changes. This is particularly useful for maintaining backward compatibility and ensuring that updates to your GraphQL API do not inadvertently break existing clients.
What are @graphql-inspector/diff-command's main functionalities?
Detect Breaking Changes
This feature allows you to detect breaking changes between two GraphQL schemas. In the example, the type of the 'hello' field changes from String to Int, which is a breaking change.
const { diff } = require('@graphql-inspector/diff-command');
const oldSchema = `type Query { hello: String }`;
const newSchema = `type Query { hello: Int }`;
const changes = diff(oldSchema, newSchema);
console.log(changes);
Detect Dangerous Changes
This feature allows you to detect dangerous changes between two GraphQL schemas. In the example, a new field 'world' is added to the Query type, which could be considered a dangerous change if clients are not expecting it.
const { diff } = require('@graphql-inspector/diff-command');
const oldSchema = `type Query { hello: String }`;
const newSchema = `type Query { hello: String, world: String }`;
const changes = diff(oldSchema, newSchema);
console.log(changes);
Detect Safe Changes
This feature allows you to detect safe changes between two GraphQL schemas. In the example, a new field 'world' is added to the Query type, which is a safe change as it does not affect existing clients.
const { diff } = require('@graphql-inspector/diff-command');
const oldSchema = `type Query { hello: String }`;
const newSchema = `type Query { hello: String, world: String }`;
const changes = diff(oldSchema, newSchema);
console.log(changes);
Other packages similar to @graphql-inspector/diff-command
graphql-schema-diff
graphql-schema-diff is a tool that compares two GraphQL schemas and outputs the differences. It is similar to @graphql-inspector/diff-command in that it helps identify changes between schemas, but it may not provide as detailed a breakdown of breaking, dangerous, and safe changes.
apollo-server
Apollo Server is a popular GraphQL server implementation that includes tools for schema management. While it is not specifically focused on diffing schemas, it provides a comprehensive suite of tools for working with GraphQL schemas, including schema validation and versioning.