-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marking breaking types as dangerous with the deprecated fields rule (#…
…2240) * Marking breaking types as dangerous with the deprecated fields rule enabled * Adding example * Adding changeset * Adding unit tests for suppressRemovalOfDeprecatedFields rule
- Loading branch information
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-inspector/core': minor | ||
--- | ||
|
||
suppressRemovalOfDeprecatedField rule will now mark removed types as dangerous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type Query { | ||
newQuery: Int! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type Query { | ||
oldQuery: OldType @deprecated(reason: "use newQuery") | ||
newQuery: Int! | ||
} | ||
|
||
type OldType { | ||
field: String! | ||
} |
113 changes: 113 additions & 0 deletions
113
packages/core/__tests__/diff/rules/suppress-removal-of-deprecated-fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { buildSchema } from 'graphql'; | ||
import { suppressRemovalOfDeprecatedField } from '../../../src/diff/rules'; | ||
import { CriticalityLevel, diff } from '../../../src/index'; | ||
import { findFirstChangeByPath } from '../../../utils/testing'; | ||
|
||
describe('suppressRemovalOfDeprecatedFields rule', () => { | ||
test('removed field on object', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
type Foo { | ||
a: String! @deprecated(reason: "use b") | ||
b: String! | ||
} | ||
`); | ||
const b = buildSchema(/* GraphQL */ ` | ||
type Foo { | ||
b: String! | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b, [suppressRemovalOfDeprecatedField]); | ||
|
||
const removed = findFirstChangeByPath(changes, 'Foo.a'); | ||
|
||
expect(removed.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
}); | ||
|
||
test('removed field on interface', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
interface Foo { | ||
a: String! @deprecated(reason: "use b") | ||
b: String! | ||
} | ||
`); | ||
const b = buildSchema(/* GraphQL */ ` | ||
interface Foo { | ||
b: String! | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b, [suppressRemovalOfDeprecatedField]); | ||
|
||
const removed = findFirstChangeByPath(changes, 'Foo.a'); | ||
|
||
expect(removed.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
}); | ||
|
||
test('removed enum', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
enum Foo { | ||
a @deprecated(reason: "use b") | ||
b | ||
} | ||
`); | ||
const b = buildSchema(/* GraphQL */ ` | ||
enum Foo { | ||
b | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b, [suppressRemovalOfDeprecatedField]); | ||
|
||
const removed = findFirstChangeByPath(changes, 'Foo.a'); | ||
|
||
expect(removed.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
}); | ||
|
||
test('removed input field', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
input Foo { | ||
a: String! @deprecated(reason: "use b") | ||
b: String! | ||
} | ||
`); | ||
const b = buildSchema(/* GraphQL */ ` | ||
input Foo { | ||
b: String! | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b, [suppressRemovalOfDeprecatedField]); | ||
|
||
const removed = findFirstChangeByPath(changes, 'Foo.a'); | ||
|
||
expect(removed.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
}); | ||
|
||
test('removed field with custom types', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
type Foo { | ||
a: CustomType! @deprecated(reason: "use b") | ||
b: String! | ||
} | ||
type CustomType { | ||
c: String! | ||
d: String! | ||
} | ||
`); | ||
const b = buildSchema(/* GraphQL */ ` | ||
type Foo { | ||
b: String! | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b, [suppressRemovalOfDeprecatedField]); | ||
|
||
const removedField = findFirstChangeByPath(changes, 'Foo.a'); | ||
const removedType = findFirstChangeByPath(changes, 'CustomType'); | ||
|
||
expect(removedField.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
expect(removedType.criticality.level).toBe(CriticalityLevel.Dangerous); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters