Skip to content

PruneSchema does not prune unused implementations of a returned interface #4819

@NullScope

Description

@NullScope

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 yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions 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

The PruneSchema utility function, and consequently, the PruneSchema transform, does not prune unused types that implement interfaces that are returned from an operation or used as field types.

To Reproduce
Steps to reproduce the behavior:

Here is a unit test for prune.test.ts:

test('removes unused implementations of a returned interface', () => {
  const schema = buildSchema(/* GraphQL */ `
    type Query {
      operation: SomeType
      anotherOperation: SomeInterface
    }

    interface SomeInterface {
      field: String
    }

    type SomeType implements SomeInterface {
      field: String
    }

    type ShouldPrune implements SomeInterface {
      field: String
    }
  `);

  const result = pruneSchema(schema);

  expect(result.getType('ShouldPrune')).toBeUndefined();
});

Expected behavior

Unused types should be pruned.

Environment:

  • OS: macOS 12.5.1
  • @graphql-tools/utils: 9.0.1
  • NodeJS: v16.15.0

Additional context
This is very important for this project, as the schema that is being transformed and then pruned has literally thousands of types, most of which (around 60%) is unused

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions