Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Update EnumType.removeInnerElements() to call remove() on its children #1813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internals-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG for `@apollo/federation-internals`

## vNEXT

- Fix bug removing an enum type [PR #1813](https://github.com/apollographql/federation/pull/1813)

## 2.0.2-alpha.1

- Fix `Schema.clone` when directive application happens before definition [PR #1785](https://github.com/apollographql/federation/pull/1785)
Expand Down
21 changes: 21 additions & 0 deletions internals-js/src/__tests__/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ test('removal of all directives of a schema', () => {
union U = A | B`);
});

test('removal of an enum type should remove enum values', () => {
const schema = buildSchema(`
type Query {
someField: String!
}

enum Enum {
SOME_VALUE
OTHER_VALUE
}
`);

const enumType = schema.type("Enum");
expectEnumType(enumType)
const enumValues = Array.from(enumType.values);
enumType.remove()
for (const value of enumValues) {
expect(value.isAttached()).toBe(false)
}
});

test('removal of all inaccessible elements of a schema', () => {
const subgraph = buildSubgraph('foo', '', `
schema @foo {
Expand Down
6 changes: 5 additions & 1 deletion internals-js/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,11 @@ export class EnumType extends BaseNamedType<OutputTypeReferencer, EnumType> {
}

protected removeInnerElements(): void {
this._values.splice(0, this._values.length);
// Make a copy, since EnumValue.remove() will modify this._values.
const values = Array.from(this._values);
for (const value of values) {
value.remove();
}
}

protected hasNonExtensionInnerElements(): boolean {
Expand Down