Expand description
§graphql-schema-diff
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:SerializeandDeserializeimpls forChange(default: on).
Modules§
Structs§
- Change
- A change that represents a meaningful difference between the two schemas. Changes have a
direction: from source to target. For example, if
kindisAddField, it means the field does not exist in thesourceschema but it does exist in thetargetschema. - Patched
Schema - A schema patched with patch().
- Span
- A span in a source file.
Enums§
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
sourceschema, since a Change always goes from source to target. YieldsNonefor changes without a source span. - resolve_
spans - Resolve the spans from Changes and the corresponding schemas.