compiler/crates/graphql-ir-diff/README.md
Comparing the intermediate representation (IR) of 2 GraphQL documents and outputs the differences.
The compare function determines whether one GraphQL document (doc1) is a subset of another (doc2) by comparing their normalized selection sets. The algorithm produces a similarity score and a detailed report of any missing selections.
Load Schema: Parse the GraphQL schema from the provided paths to enable type-aware comparison.
Parse to IR: Convert both GraphQL documents into intermediate representation (IR).
Build Normalized Trees: Transform each IR into a NormalizedTree - a tree structure that:
my_id: id becomes id)The normailized tree mirrors the JSON response structure of the query
Subtract Trees: Perform a DFS traversal comparing tree1 from (doc1) against tree2 (from doc2):
tree1, find a matching superset selection in tree2 using the subset checktree1 are satisfied by tree2tree1 that have no matching superset in tree2Compute Score: Calculate a similarity score as:
score = 1.0 - (missing_nodes_count / total_nodes_in_doc1)
1.0 means doc1 is a complete subset of doc20.0 means doc1 is completely disjoint from doc2A ⊆ B if A's field name matches B's and each argument in A has a matching argument in B whose value is equal or is a variable