Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
cf7fcfc
major: diff includes all nested changes when a node is added
jdolle Jul 7, 2025
2adf87b
Fix directive argument changes to match others
jdolle Jul 9, 2025
dfe87bf
Add rule to ignore nested additions
jdolle Jul 9, 2025
c3dcc73
Add a field test
jdolle Jul 9, 2025
6fd13d2
Fix parent path; add more tests
jdolle Jul 9, 2025
0cdcc17
TypeChanged changes
jdolle Jul 9, 2025
985a146
prettier
jdolle Jul 9, 2025
3f781fb
Add more meta to changes
jdolle Jul 17, 2025
441c198
Add directive usage; add tests
jdolle Jul 23, 2025
288ae36
Improve path handling
jdolle Jul 23, 2025
f19e299
WIP: Print test schemas with directives.
jdolle Jul 24, 2025
6cd0ba3
Support all directive usage cases
jdolle Jul 26, 2025
bab8b86
Remove unnecessary import
jdolle Jul 28, 2025
62c16ba
Same
jdolle Jul 28, 2025
e546227
Simplify errors; add readme
jdolle Aug 21, 2025
a430f80
Remove redundant types; patch more descriptions and defaults etc
jdolle Aug 21, 2025
450a572
Prettier
jdolle Aug 21, 2025
d23a3cb
Support more changes
jdolle Aug 22, 2025
7cc882b
fix prettier etc
jdolle Aug 22, 2025
26343fa
Improve error handling and error types
jdolle Aug 26, 2025
39c2616
tweaking errors
jdolle Aug 26, 2025
0cf0b11
More error fixes
jdolle Aug 26, 2025
4d9bd95
Export lower level methods
jdolle Aug 26, 2025
6b83adb
FieldAdded.addedFieldReturnType
jdolle Sep 1, 2025
6f2756b
Fix operation type changes
jdolle Sep 1, 2025
83dfa4e
Consistency; adjust schema operation type logic
jdolle Sep 2, 2025
563b054
Export missing change types
jdolle Sep 3, 2025
f61c716
Change path for deprecated directives; fix duplicating deprecated dir…
jdolle Sep 3, 2025
2a42993
Update seven-jars-yell.md
jdolle Sep 30, 2025
b415723
Repeatable directives are a nightmare
jdolle Oct 30, 2025
a6d80a3
Fix tests
jdolle Oct 30, 2025
cd3db7e
add more complicated tests that are needed for completeness
jdolle Oct 30, 2025
a8fc04d
support repeat directives. Fix argument mutual change
jdolle Oct 30, 2025
e791196
fix import
jdolle Oct 30, 2025
bcd9cef
Detailed changelog
jdolle Oct 31, 2025
82e9bb7
Hide nested changes from CLI by default
jdolle Oct 31, 2025
c8a03d1
Move readme
jdolle Oct 31, 2025
367f544
Add imports on patch on example
jdolle Oct 31, 2025
e51bbd7
Explain requireOldValueMatch
jdolle Oct 31, 2025
4138969
Rename expectPatchToMatch
jdolle Oct 31, 2025
9bffca4
prettier
jdolle Oct 31, 2025
9972ac7
clarify option in types
jdolle Oct 31, 2025
3c870c7
Add meta check to enum value removed
jdolle Oct 31, 2025
a89eec1
inputFieldAddedFromMeta non-breaking cases
jdolle Oct 31, 2025
ee61960
Adjust objectTypeInterfaceAddedFromMeta reason
jdolle Oct 31, 2025
083528d
add path check on union patches
jdolle Oct 31, 2025
15b957a
Fix tests; remove unique patch logic for deprecation
jdolle Oct 31, 2025
9416576
Simplify nested conditions
jdolle Oct 31, 2025
801f0e6
Mention not validating
jdolle Nov 1, 2025
3ce91ba
Simplifying nested conditions
jdolle Nov 1, 2025
aa4ba82
Simplifying nested conditions
jdolle Nov 1, 2025
d1b076a
Simplifying nested conditions
jdolle Nov 1, 2025
87b7f49
Simplifying nested conditions
jdolle Nov 1, 2025
3215991
Make removing deprecation safe
jdolle Nov 4, 2025
e23fe3b
Use version 0.0.0 and add changeset to patch
jdolle Nov 4, 2025
c71a0e8
Adjust error handling
jdolle Nov 5, 2025
5f76581
Fix description removed; move tests outside of src
jdolle Nov 5, 2025
66a21cd
Add failure cases; fix field add error
jdolle Nov 5, 2025
bee17d0
fix removed reference
jdolle Nov 6, 2025
4c697c0
Add edge case tests for directives
jdolle Nov 6, 2025
91e35cd
Improve numerous error messages
jdolle Nov 7, 2025
7450087
More error format improvements
jdolle Nov 7, 2025
af2cfad
Fix changelog
jdolle Nov 7, 2025
408d59a
add fieldremoval to removal list
jdolle Nov 7, 2025
78dc291
consistent missing values
jdolle Nov 7, 2025
d71a60a
Merge branch 'graphql-hive:master' into type-added-meta
jdolle Nov 7, 2025
16a3374
Fix merge conflict
jdolle Nov 7, 2025
e123bc4
prettier
jdolle Nov 7, 2025
0d81d03
Merge branch 'graphql-hive:master' into type-added-meta
jdolle Nov 7, 2025
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
22 changes: 22 additions & 0 deletions .changeset/empty-cougars-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@graphql-inspector/patch': patch
---

Initial release. Patch applies a list of changes (output from `@graphql-inspector/core`'s `diff`) to
a GraphQL Schema.

Example usage:

```typescript
import { buildSchema } from "graphql";
import { diff } from "@graphql-inspector/core";
import { patchSchema } from "@graphql-inspector/patch";

const schemaA = buildSchema(before, { assumeValid: true, assumeValidSDL: true });
const schemaB = buildSchema(after, { assumeValid: true, assumeValidSDL: true });

const changes = await diff(schemaA, schemaB);
const patched = patchSchema(schemaA, changes);
```

If working from an AST, you may alternatively use the exported `patch` function. But be careful to make sure directives are included in your AST or those changes will be missed.
5 changes: 5 additions & 0 deletions .changeset/long-rules-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-inspector/diff-command': minor
---

Added option to include nested changes. Use `--rule showNestedAdditions`.
137 changes: 137 additions & 0 deletions .changeset/seven-jars-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
'@graphql-inspector/core': major
---

This is a major change to `@graphql-inspector/core` and introduces a new `@graphql-inspector/patch` package, which applies changes output from `diff` on top of a schema -- essentially rebasing these changes onto any schema.

These changes include:
- Numerous adjustments to Change types to create more accurate severity levels, such as a boolean indicating if the change applies to a new type or an existing type.
- Adjustmented the "path" on several change types in order to consistently map to the exact AST node being changed. For example, `EnumValueDeprecationReasonAdded`'s path previously referenced the enumValue (e.g. `EnumName.value`), not the deprecated directive (e.g. `EnumName.value.@deprecated`).
- Added new attributes in order to provide enough context for a new "@graphql-inspector/patch" function to apply changes accurately.
- Added support for repeatable directives
- Includes all nested changes in `diff` output when a new node is added. This can dramatically increase the number of changes listed which can be noisy, but it makes it possible for "@graphql-inspector/patch" to apply all changes from a schema. This can be optionally filtered using a newly exported `DiffRule.ignoreNestedAdditions` rule.

For example, given an existing schema:

```graphql
type User {
id: ID!
name: String!
}
```

And a diff schema:

```graphql
type User {
id: ID!
name: String!
address: Address
}

type Address {
line1: String!
line2: String!
}
```

Then previously the output would be:

```json
[
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Type 'Address' was added",
"meta": {
"addedTypeKind": "ObjectTypeDefinition",
"addedTypeName": "Address",
},
"path": "Address",
"type": "TYPE_ADDED",
},
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Field 'address' was added to object type 'User'",
"meta": {
"addedFieldName": "address",
"addedFieldReturnType": "Address",
"typeName": "User",
"typeType": "object type",
},
"path": "User.address",
"type": "FIELD_ADDED",
},
]
```

But now the output also includes the fields inside the new `Address` type:

```json
[
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Type 'Address' was added",
"meta": {
"addedTypeKind": "ObjectTypeDefinition",
"addedTypeName": "Address",
},
"path": "Address",
"type": "TYPE_ADDED",
},
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Field 'line1' was added to object type 'Address'",
"meta": {
"addedFieldName": "line1",
"addedFieldReturnType": "String!",
"typeName": "Address",
"typeType": "object type",
},
"path": "Address.line1",
"type": "FIELD_ADDED",
},
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Field 'line2' was added to object type 'Address'",
"meta": {
"addedFieldName": "line2",
"addedFieldReturnType": "String!",
"typeName": "Address",
"typeType": "object type",
},
"path": "Address.line2",
"type": "FIELD_ADDED",
},
{
"criticality": {
"level": "NON_BREAKING",
},
"message": "Field 'address' was added to object type 'User'",
"meta": {
"addedFieldName": "address",
"addedFieldReturnType": "Address",
"typeName": "User",
"typeType": "object type",
},
"path": "User.address",
"type": "FIELD_ADDED",
},
]
```

These additional changes can be filtered using a new rule:

```js
import { DiffRule, diff } from "@graphql-inspector/core";
const changes = await diff(a, b, [DiffRule.ignoreNestedAdditions]);
```
31 changes: 19 additions & 12 deletions packages/commands/diff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,27 @@ export async function handler(input: {
? resolveCompletionHandler(input.onComplete)
: failOnBreakingChanges;

const rules = input.rules
? input.rules
.filter(isString)
.map((name): Rule => {
const rule = resolveRule(name);
let showNestedAdditions = false;
const rules = [...(input.rules ?? [])]
.filter(isString)
.map((name): Rule | undefined => {
if (name === 'showNestedAdditions') {
showNestedAdditions = true;
return;
}

if (!rule) {
throw new Error(`Rule '${name}' does not exist!\n`);
}
const rule = resolveRule(name);

return rule;
})
.filter(f => f)
: [];
if (!rule) {
throw new Error(`Rule '${name}' does not exist!\n`);
}

return rule;
})
.filter((f): f is NonNullable<typeof f> => !!f);
if (!showNestedAdditions) {
rules.push(DiffRule.ignoreNestedAdditions);
}

const changes = await diffSchema(input.oldSchema, input.newSchema, rules, {
checkUsage: input.onUsage ? resolveUsageHandler(input.onUsage) : undefined,
Expand Down
Loading