|
| 1 | +--- |
| 2 | +'@graphql-inspector/core': major |
| 3 | +--- |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +These changes include: |
| 8 | +- 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. |
| 9 | +- 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`). |
| 10 | +- Added new attributes in order to provide enough context for a new "@graphql-inspector/patch" function to apply changes accurately. |
| 11 | +- Added support for repeatable directives |
| 12 | +- 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.simplifyChanges` rule. |
| 13 | + |
| 14 | +For example, given an existing schema: |
| 15 | + |
| 16 | +```graphql |
| 17 | +type User { |
| 18 | + id: ID! |
| 19 | + name: String! |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +And a diff schema: |
| 24 | + |
| 25 | +```graphql |
| 26 | +type User { |
| 27 | + id: ID! |
| 28 | + name: String! |
| 29 | + address: Address |
| 30 | +} |
| 31 | + |
| 32 | +type Address { |
| 33 | + line1: String! |
| 34 | + line2: String! |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +Then previously the output would be: |
| 39 | + |
| 40 | +```json |
| 41 | +[ |
| 42 | + { |
| 43 | + "criticality": { |
| 44 | + "level": "NON_BREAKING", |
| 45 | + }, |
| 46 | + "message": "Type 'Address' was added", |
| 47 | + "meta": { |
| 48 | + "addedTypeKind": "ObjectTypeDefinition", |
| 49 | + "addedTypeName": "Address", |
| 50 | + }, |
| 51 | + "path": "Address", |
| 52 | + "type": "TYPE_ADDED", |
| 53 | + }, |
| 54 | + { |
| 55 | + "criticality": { |
| 56 | + "level": "NON_BREAKING", |
| 57 | + }, |
| 58 | + "message": "Field 'address' was added to object type 'User'", |
| 59 | + "meta": { |
| 60 | + "addedFieldName": "address", |
| 61 | + "addedFieldReturnType": "Address", |
| 62 | + "typeName": "User", |
| 63 | + "typeType": "object type", |
| 64 | + }, |
| 65 | + "path": "User.address", |
| 66 | + "type": "FIELD_ADDED", |
| 67 | + }, |
| 68 | +] |
| 69 | +``` |
| 70 | + |
| 71 | +But now the output also includes the fields inside the new `Address` type: |
| 72 | + |
| 73 | +```json |
| 74 | +[ |
| 75 | + { |
| 76 | + "criticality": { |
| 77 | + "level": "NON_BREAKING", |
| 78 | + }, |
| 79 | + "message": "Type 'Address' was added", |
| 80 | + "meta": { |
| 81 | + "addedTypeKind": "ObjectTypeDefinition", |
| 82 | + "addedTypeName": "Address", |
| 83 | + }, |
| 84 | + "path": "Address", |
| 85 | + "type": "TYPE_ADDED", |
| 86 | + }, |
| 87 | + { |
| 88 | + "criticality": { |
| 89 | + "level": "NON_BREAKING", |
| 90 | + }, |
| 91 | + "message": "Field 'line1' was added to object type 'Address'", |
| 92 | + "meta": { |
| 93 | + "addedFieldName": "line1", |
| 94 | + "addedFieldReturnType": "String!", |
| 95 | + "typeName": "Address", |
| 96 | + "typeType": "object type", |
| 97 | + }, |
| 98 | + "path": "Address.line1", |
| 99 | + "type": "FIELD_ADDED", |
| 100 | + }, |
| 101 | + { |
| 102 | + "criticality": { |
| 103 | + "level": "NON_BREAKING", |
| 104 | + }, |
| 105 | + "message": "Field 'line2' was added to object type 'Address'", |
| 106 | + "meta": { |
| 107 | + "addedFieldName": "line2", |
| 108 | + "addedFieldReturnType": "String!", |
| 109 | + "typeName": "Address", |
| 110 | + "typeType": "object type", |
| 111 | + }, |
| 112 | + "path": "Address.line2", |
| 113 | + "type": "FIELD_ADDED", |
| 114 | + }, |
| 115 | + { |
| 116 | + "criticality": { |
| 117 | + "level": "NON_BREAKING", |
| 118 | + }, |
| 119 | + "message": "Field 'address' was added to object type 'User'", |
| 120 | + "meta": { |
| 121 | + "addedFieldName": "address", |
| 122 | + "addedFieldReturnType": "Address", |
| 123 | + "typeName": "User", |
| 124 | + "typeType": "object type", |
| 125 | + }, |
| 126 | + "path": "User.address", |
| 127 | + "type": "FIELD_ADDED", |
| 128 | + }, |
| 129 | +] |
| 130 | +``` |
| 131 | + |
| 132 | +These additional changes can be filtered using a new rule: |
| 133 | + |
| 134 | +```js |
| 135 | +import { DiffRule, diff } from "@graphql-inspector/core"; |
| 136 | +const changes = await diff(a, b, [DiffRule.simplifyChanges]); |
| 137 | +``` |
0 commit comments