Expand description

§graphql-schema-diff

crates.io] docs.rs

This crate implements diffing of two GraphQL schemas, returning a list of changes. It powers the changelog feature and operation checks at Grafbase.

§Example

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

fn main() {
  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
          },
          Change {
              path: String::from("PizzaName"),
              kind: ChangeKind::AddObjectType
          },
          Change {
              path: String::from("PizzaName.english"),
              kind: ChangeKind::AddField
          },
          Change {
              path: String::from("PizzaName.italian"),
              kind: ChangeKind::AddField
          },
          Change {
              path: String::from("Topping.PINEAPPLE"),
              kind: ChangeKind::RemoveEnumValue
          },
          Change {
              path: String::from("Topping.POTATO"),
              kind: ChangeKind::AddEnumValue
          }
  ]);
}

§Cargo features

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

Structs§

  • A change that represents a meaningful difference between the two schemas. Changes have a direction: from source to target. For example, if kind is AddField, it means the field does not exist in the source schema but it does exist in the target schema.

Enums§

Functions§

  • Diff two GraphQL schemas.