-
-
Notifications
You must be signed in to change notification settings - Fork 205
Add patch package to apply diff changes to schemas #2893
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
cf7fcfc
2adf87b
dfe87bf
c3dcc73
6fd13d2
0cdcc17
985a146
3f781fb
441c198
288ae36
f19e299
6cd0ba3
bab8b86
62c16ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-inspector/core': major | ||
--- | ||
|
||
"diff" includes all nested changes when a node is added. Some change types have had additional meta fields added. | ||
On deprecation add with a reason, a separate "fieldDeprecationReasonAdded" change is no longer included. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,13 +173,13 @@ describe('directive', () => { | |
}; | ||
|
||
// Nullable | ||
expect(change.a.criticality.level).toEqual(CriticalityLevel.NonBreaking); | ||
expect(change.a.type).toEqual('DIRECTIVE_ARGUMENT_ADDED'); | ||
expect(change.a.message).toEqual(`Argument 'name' was added to directive 'a'`); | ||
expect(change.a?.type).toEqual('DIRECTIVE_ARGUMENT_ADDED'); | ||
expect(change.a?.criticality.level).toEqual(CriticalityLevel.NonBreaking); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In several places I reordered things because when tweaking behavior and testing, t was not providing me enough insights to understand what was wrong. Placing the "type" first let me know which change type was being returned. |
||
expect(change.a?.message).toEqual(`Argument 'name' was added to directive 'a'`); | ||
// Non-nullable | ||
expect(change.b.criticality.level).toEqual(CriticalityLevel.Breaking); | ||
expect(change.b.type).toEqual('DIRECTIVE_ARGUMENT_ADDED'); | ||
expect(change.b.message).toEqual(`Argument 'name' was added to directive 'b'`); | ||
expect(change.b?.type).toEqual('DIRECTIVE_ARGUMENT_ADDED'); | ||
expect(change.b?.criticality.level).toEqual(CriticalityLevel.Breaking); | ||
expect(change.b?.message).toEqual(`Argument 'name' was added to directive 'b'`); | ||
}); | ||
|
||
test('removed', async () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,54 @@ import { CriticalityLevel, diff, DiffRule } from '../../src/index.js'; | |
import { findFirstChangeByPath } from '../../utils/testing.js'; | ||
|
||
describe('enum', () => { | ||
test('added', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
type Query { | ||
fieldA: String | ||
} | ||
`); | ||
|
||
const b = buildSchema(/* GraphQL */ ` | ||
type Query { | ||
fieldA: String | ||
} | ||
|
||
enum enumA { | ||
""" | ||
A is the first letter in the alphabet | ||
""" | ||
A | ||
B | ||
} | ||
`); | ||
|
||
const changes = await diff(a, b); | ||
expect(changes.length).toEqual(4); | ||
|
||
{ | ||
const change = findFirstChangeByPath(changes, 'enumA'); | ||
expect(change.meta).toMatchObject({ | ||
addedTypeKind: 'EnumTypeDefinition', | ||
addedTypeName: 'enumA', | ||
}); | ||
expect(change.criticality.level).toEqual(CriticalityLevel.NonBreaking); | ||
expect(change.criticality.reason).not.toBeDefined(); | ||
expect(change.message).toEqual(`Type 'enumA' was added`); | ||
} | ||
|
||
{ | ||
const change = findFirstChangeByPath(changes, 'enumA.A'); | ||
expect(change.criticality.level).toEqual(CriticalityLevel.NonBreaking); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test shows that enum additions also contain all nested changes within that enum, and that those changes are flagged as non-breaking. |
||
expect(change.criticality.reason).not.toBeDefined(); | ||
expect(change.message).toEqual(`Enum value 'A' was added to enum 'enumA'`); | ||
expect(change.meta).toMatchObject({ | ||
addedEnumValueName: 'A', | ||
enumName: 'enumA', | ||
addedToNewType: true, | ||
}); | ||
} | ||
}); | ||
|
||
test('value added', async () => { | ||
const a = buildSchema(/* GraphQL */ ` | ||
type Query { | ||
|
@@ -130,7 +178,7 @@ describe('enum', () => { | |
`); | ||
|
||
const changes = await diff(a, b); | ||
const change = findFirstChangeByPath(changes, 'enumA.A'); | ||
const change = findFirstChangeByPath(changes, 'enumA.A.deprecated'); | ||
|
||
expect(changes.length).toEqual(1); | ||
expect(change.criticality.level).toEqual(CriticalityLevel.NonBreaking); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be convinced that this is a minor patch because the changes to the output's format doesnt break anything. But the actual content of the changes has changed drastically which is why I thought we should be safe and declare a major change.