Skip to content

Simplify changes rule drops breaking changes when the same type also has simple changes #2955

Description

@AdriVanHoudt

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox

    Make sure to fork this template and run pnpm generate in the terminal.

    Please make sure the Codegen and plugins version under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

When a diff of a type has both a breaking change and simple change, the simplify rules silently drops the breaking change.

To Reproduce Steps to reproduce the behaviour:

// packages/core/__tests__/diff/rules/simplify-changes.test.ts

  test('keeps a breaking field type change when the same field also gains a description', async () => {
    const a = buildSchema(/* GraphQL */ `
      type Payload {
        id: String!
      }
      type Query {
        _: Boolean
      }
      type Mutation {
        doSomething(id: String!): Payload!
      }
    `);
    const b = buildSchema(/* GraphQL */ `
      type Payload {
        id: String!
      }
      type Query {
        _: Boolean
      }
      type Mutation {
        "Does something."
        doSomething(id: String!): Boolean!
      }
    `);

    const changes = await diff(a, b, [simplifyChanges]);

    // The breaking type change must survive simplification even though the same field also gained a description in the same diff. 
    // `simplifyChanges` treats `FieldDescriptionAdded` as a "simple change" and pushes its path, the later `FieldTypeChanged` shares that exact path and is wrongly filtered out.
    const typeChange = changes.find(c => c.type === ChangeType.FieldTypeChanged);
    expect(typeChange).toBeDefined();
    expect(typeChange?.criticality.level).toBe(CriticalityLevel.Breaking);
  });

Expected behavior

Check should never drop breaking changes.

Environment:

Additional context

I can PR the failing test and willing to implement a fix but would need some guidance on where to best fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions