Skip to main content

Crate graphql_schema_diff

Crate graphql_schema_diff 

Source
Expand description

§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).

Modules§

path
A structured path to a specific location in a schema. See the docs on Path.

Structs§

Change
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.
PatchedSchema
A schema patched with patch().
Span
A span in a source file.

Enums§

ChangeKind

Functions§

diff
Diff two GraphQL schemas.
diff_asts
Diff two already parsed ASTs. See diff() for the string based API.
patch
Apply a diff to a source schema. The spans in the diff from the original target schema must have been resolved by [resolve_spans()] and not sorted.
resolve_source_spans
Resolve the source spans from Changes and the source schema, for change kinds that have a meaningful source span (see Change::source_span). Source spans are always relative to the source schema, since a Change always goes from source to target. Yields None for changes without a source span.
resolve_spans
Resolve the spans from Changes and the corresponding schemas.