graphql-schema-diff 0.6.0

Semantic diffing for GraphQL schemas
Documentation

graphql-schema-diff

crates.io docs.rs

This crate implements diffing of two GraphQL schemas, returning a list of changes.

This crate was originally created in grafbase/grafbase. When Grafbase was acquired, this crate became unmaintained. With the agreement of the original author, the code was forked into this standalone repository. (its git history was kept)

Example

use graphql_schema_diff::{diff, Change, ChangeKind, Span};

let source = r#"
  type Pizza {
    id: ID!
    name: String!
    toppings: [Topping!]!
  }

  enum Topping {
    OLIVES
    MUSHROOMS
    PINEAPPLE
  }
"#;

let target = r#"
  type Pizza {
    id: ID!
    name: PizzaName
    toppings: [Topping!]!
  }

  type PizzaName {
    english: String
    italian: String!
  }

  enum Topping {
    OLIVES
    MUSHROOMS
    POTATO
  }
"#;

let changes = diff(source, target).unwrap();

assert_eq!(changes,
   &[
        Change {
            path: String::from("Pizza.name"),
            kind: ChangeKind::ChangeFieldType,
            span: Span::new(38, 47),
            source_span: Some(Span::new(38, 45)),
        },
        Change {
            path: String::from("PizzaName"),
            kind: ChangeKind::AddObjectType,
            span: Span::new(81, 142),
            source_span: None,
        },
        Change {
            path: String::from("Topping.PINEAPPLE"),
            kind: ChangeKind::RemoveEnumValue,
            span: Span::new(0, 0),
            source_span: Some(Span::new(123, 135)),
        },
        Change {
            path: String::from("Topping.POTATO"),
            kind: ChangeKind::AddEnumValue,
            span: Span::new(190, 199),
            source_span: None,
        }
]);

Cargo features

  • serde: Serialize and Deserialize impls for Change (default: on).