moongqlimpact

    Trace GraphQL input and output compatibility regressions to client operations.

    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    6 hours ago
    Downloads
    8

    #MoonGqlImpact library quickstart

    Import cn-wn/moongqlimpact from a local checkout to compare two SDL sources and trace regressions to the operations a client ships. This example checks a query that still selects a valid field after the schema upgrade. Its previous non-null guarantee is lost, so the report points to the aliased response key.

    ///|
    test {
    let baseline : @moongqlimpact.Source = {
    path: "baseline.graphql",
    text: "type Query { title: String! }",
    }
    let proposed : @moongqlimpact.Source = {
    path: "proposed.graphql",
    text: "type Query { title: String }",
    }
    let clients : Array[@moongqlimpact.Client] = [
    {
    name: "web",
    sources: [
    { path: "screen.graphql", text: "query Screen { heading: title }", },
    ],
    },
    ]
    let report = @moongqlimpact.analyze_upgrade(baseline, proposed, clients)
    assert_eq(report.changes.length(), 1)
    let change = report.changes[0]
    assert_eq(change.coordinate, "Query.title")
    assert_eq(change.previous_type, "String!")
    assert_eq(change.proposed_type, Some("String"))
    assert_eq(change.impacts[0].response_path, ["heading"])
    assert_true(report.to_markdown().contains("screen.graphql"))
    }

    AnalysisError

    pub(all) suberror AnalysisError {
    Invalid(Location, String)
    Unsupported(Location, String)
    }

    AnalyzedUpgrade

    pub struct AnalyzedUpgrade {
    report : Report
    coverage : Array[ClientCoverage]
    proposed_rejections : Array[OperationRejection]?
    sample_assessments : Array[SampleAssessment]
    } derive(Eq,
    Debug
    )

    The schema changes and catalog evidence for an upgrade. Its JSON representation adds format_version and coverage alongside changes.

    AnalyzedUpgrade::blocks

    fn AnalyzedUpgrade::blocks(self : AnalyzedUpgrade, observed_only? : Bool, severities? : Array[Severity], reason_codes? : Array[ReasonCode]) -> Bool

    Apply the gate to schema changes and baseline-valid operations that now fail validation.

    AnalyzedUpgrade::equal

    automatically derived

    AnalyzedUpgrade::not_equal

    fn AnalyzedUpgrade::not_equal(x : AnalyzedUpgrade, y : AnalyzedUpgrade) -> Bool
    automatically derived

    AnalyzedUpgrade::to_json

    AnalyzedUpgrade::to_markdown

    fn AnalyzedUpgrade::to_markdown(self : AnalyzedUpgrade) -> String

    Render the change report and any proposed-schema validation diagnostics.

    AnalyzedUpgrade::to_repr

    automatically derived

    Change

    pub(all) struct Change {
    coordinate : String
    previous_type : String
    proposed_type : String?
    baseline : Location
    proposed : Location?
    impacts : Array[Impact]
    reasons : Array[ChangeReason]?
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Change::equal

    fn Change::equal(Change, Change) -> Bool
    automatically derived

    Change::not_equal

    fn Change::not_equal(x : Change, y : Change) -> Bool
    automatically derived

    Change::to_json

    automatically derived

    Change::to_repr

    automatically derived

    ChangeReason

    ChangeReason::equal

    automatically derived

    ChangeReason::not_equal

    fn ChangeReason::not_equal(x : ChangeReason, y : ChangeReason) -> Bool
    automatically derived

    ChangeReason::to_repr

    automatically derived

    Client

    pub(all) struct Client {
    name : String
    sources : Array[Source]
    }

    Query and fragment files are resolved independently for each client.

    ClientCoverage

    pub(all) struct ClientCoverage {
    name : String
    sources : Array[String]
    operations : Array[OperationCoverage]
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Sources and operations actually analyzed under one client identity.

    ClientCoverage::equal

    automatically derived

    ClientCoverage::not_equal

    fn ClientCoverage::not_equal(x : ClientCoverage, y : ClientCoverage) -> Bool
    automatically derived

    ClientCoverage::to_json

    automatically derived

    ClientCoverage::to_repr

    automatically derived

    Impact

    pub(all) struct Impact {
    client : String
    operation : String
    response_path : Array[String]
    selection : Location
    reason_codes : Array[ReasonCode]?
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Impact::equal

    fn Impact::equal(Impact, Impact) -> Bool
    automatically derived

    Impact::not_equal

    fn Impact::not_equal(x : Impact, y : Impact) -> Bool
    automatically derived

    Impact::to_json

    automatically derived

    Impact::to_repr

    automatically derived

    Location

    pub(all) struct Location {
    path : String
    line : Int
    column : Int
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Location::equal

    fn Location::equal(Location, Location) -> Bool
    automatically derived

    Location::not_equal

    fn Location::not_equal(x : Location, y : Location) -> Bool
    automatically derived

    Location::to_json

    automatically derived

    Location::to_repr

    automatically derived

    OperationCoverage

    A query that was checked against the baseline schema.

    OperationCoverage::equal

    automatically derived

    OperationCoverage::not_equal

    fn OperationCoverage::not_equal(x : OperationCoverage, y : OperationCoverage) -> Bool
    automatically derived

    OperationCoverage::to_json

    automatically derived

    OperationCoverage::to_repr

    automatically derived

    OperationRejection

    pub struct OperationRejection {
    client : String
    operation : String
    location : Location
    message : String
    reason : ChangeReason
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    A baseline-valid operation rejected by the proposed schema's static rules.

    OperationRejection::equal

    automatically derived

    OperationRejection::not_equal

    automatically derived

    OperationRejection::to_json

    automatically derived

    OperationRejection::to_repr

    automatically derived

    ReasonCode

    pub(all) enum ReasonCode {
    FieldRemoved
    OutputTypeChanged
    OutputNullabilityWeakened
    OutputEnumValueAdded
    OutputEnumValueRemoved
    AbstractTypeRemoved
    AbstractMemberAdded
    AbstractMemberRemoved
    FragmentNoLongerPossible
    ScalarSpecificationChanged
    ArgumentRemoved
    RequiredArgumentAdded
    ArgumentBecameRequired
    ArgumentTypeChanged
    InputEnumValueRemoved
    ArgumentDefaultChanged
    InputFieldRemoved
    InputObjectBecameOneOf
    RequiredInputFieldAdded
    InputFieldBecameRequired
    InputFieldTypeChanged
    InputFieldDefaultChanged
    InputVariableValueMayBreak
    ProposedOperationRejected
    MutationRootRemoved
    VariableSampleRejected
    VariableSampleCoercionChanged
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Stable identifiers for the rules that detected a change.

    ReasonCode::equal

    fn ReasonCode::equal(ReasonCode, ReasonCode) -> Bool
    automatically derived

    ReasonCode::not_equal

    fn ReasonCode::not_equal(x : ReasonCode, y : ReasonCode) -> Bool
    automatically derived

    ReasonCode::to_repr

    automatically derived

    Report

    Report::blocks

    fn Report::blocks(self : Report, observed_only? : Bool, severities? : Array[Severity], reason_codes? : Array[ReasonCode]) -> Bool

    Decide whether to block using the full report or observed operations. Missing reason metadata from older JSON reports is treated conservatively.

    Report::equal

    fn Report::equal(Report, Report) -> Bool
    automatically derived

    Report::not_equal

    fn Report::not_equal(x : Report, y : Report) -> Bool
    automatically derived

    Report::to_json

    automatically derived

    Report::to_markdown

    fn Report::to_markdown(self : Report) -> String

    Render every change and impact as an escaped, deterministic Markdown report. Ordering follows the report. Unobserved changes are included.

    Report::to_repr

    automatically derived

    SampleAssessment

    pub struct SampleAssessment {
    client : String
    operation : String
    id : String
    status : SampleStatus
    path : String?
    diagnostic : String?
    reason : ChangeReason?
    argument_coordinate : String?
    response_path : Array[String]?
    selection : Location?
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Evidence from coercing a sample. Reports never contain its raw values.

    SampleStatus

    pub(all) enum SampleStatus {
    Unchanged
    CoercionChanged
    VariableRejected
    OperationRejected
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Severity

    The policy category of a change, independent of catalog coverage.

    Severity::equal

    fn Severity::equal(Severity, Severity) -> Bool
    automatically derived

    Severity::not_equal

    fn Severity::not_equal(x : Severity, y : Severity) -> Bool
    automatically derived

    Severity::to_repr

    automatically derived

    Source

    pub(all) struct Source {
    path : String
    text : String
    }

    A named input file. Paths appear verbatim in diagnostics.

    VariableSample

    pub(all) struct VariableSample {
    client : String
    operation : String
    id : String
    variables :
    Json

    }

    A caller-supplied, preferably synthetic or scrubbed JSON variables object.

    analyze_upgrade

    fn analyze_upgrade(baseline : Source, proposed : Source, clients : Array[Client]) -> Report raise AnalysisError

    Compare supported input and output contracts and locate affected selections in baseline-valid queries.

    analyze_upgrade_with_coverage

    fn analyze_upgrade_with_coverage(baseline : Source, proposed : Source, clients : Array[Client]) -> AnalyzedUpgrade raise AnalysisError

    Compare contracts and validate registered operations against both snapshots. An empty client list yields a schema-only report with empty coverage.

    analyze_upgrade_with_samples

    fn analyze_upgrade_with_samples(baseline : Source, proposed : Source, clients : Array[Client], samples : Array[VariableSample], scalar_inputs? : Map[String, (
    Json
    ) -> Bool]) -> AnalyzedUpgrade raise AnalysisError

    Validate both snapshots and compare coercion of baseline-valid JSON variable samples. A scalar rule defines the supported JSON representation for a declared custom scalar.

    analyze_upgrade_with_scalar_contracts

    fn analyze_upgrade_with_scalar_contracts(baseline : Source, proposed : Source, clients : Array[Client], samples : Array[VariableSample], baseline_scalar_inputs~ : Map[String, (
    Json
    ) -> Bool], proposed_scalar_inputs~ : Map[String, (
    Json
    ) -> Bool]) -> AnalyzedUpgrade raise AnalysisError

    Evaluate each schema with its own custom scalar input validators. Validators describe acceptance. Any normalization performed by a resolver remains outside this analysis.