Skip to content

Commit 43a997f

Browse files
committed
Upgrade graphql-inspector to v7; update change models
1 parent 791c025 commit 43a997f

File tree

10 files changed

+784
-275
lines changed

10 files changed

+784
-275
lines changed

.changeset/loose-dots-learn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/cli': minor
3+
'hive': minor
4+
---
5+
6+
Upgrade graphql-inspector/core to v7 and update the models to be able to handle the new change
7+
objects. GraphQL Inspector now supports directive changes and improves the accuracy of the severity level for several change types. This will improve schema checks to make them more accurate and more complete. See graphql-inspector's changelog for details.

integration-tests/tests/api/policy/policy-check.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,12 @@ describe('Schema policy checks', () => {
323323
'',
324324
' - Deprecation reason is required for field foo in type Query. (source: policy-require-deprecation-reason)',
325325
'',
326-
'ℹ Detected 4 changes',
326+
'ℹ Detected 3 changes',
327327
'',
328328
' Safe changes:',
329329
' - Type User was added',
330330
' - Field user was added to object type Query',
331331
' - Field Query.foo is deprecated',
332-
' - Directive deprecated was added to field Query.foo',
333332
'',
334333
'View full report:',
335334
expect.any(String),

integration-tests/tests/api/schema/publish.spec.ts

Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ describe('schema publishing changes are persisted', () => {
818818
equalsObject: {
819819
meta: {
820820
addedDirectiveName: 'foo',
821+
addedDirectiveDescription: null,
822+
addedDirectiveLocations: ['FIELD'],
823+
addedDirectiveRepeatable: false,
821824
},
822825
type: 'DIRECTIVE_ADDED',
823826
},
@@ -1278,8 +1281,10 @@ describe('schema publishing changes are persisted', () => {
12781281
`,
12791282
equalsObject: {
12801283
meta: {
1284+
addedDirectiveDescription: null,
12811285
enumName: 'Foo',
12821286
addedEnumValueName: 'b',
1287+
addedToNewType: false,
12831288
},
12841289
type: 'ENUM_VALUE_ADDED',
12851290
},
@@ -1523,6 +1528,7 @@ describe('schema publishing changes are persisted', () => {
15231528
typeName: 'Query',
15241529
addedFieldName: 'b',
15251530
typeType: 'object type',
1531+
addedFieldReturnType: 'String',
15261532
},
15271533
type: 'FIELD_ADDED',
15281534
},
@@ -1786,6 +1792,7 @@ describe('schema publishing changes are persisted', () => {
17861792
addedArgumentType: 'String!',
17871793
hasDefaultValue: false,
17881794
isAddedFieldArgumentBreaking: true,
1795+
addedToNewField: false,
17891796
},
17901797
type: 'FIELD_ARGUMENT_ADDED',
17911798
},
@@ -1811,6 +1818,7 @@ describe('schema publishing changes are persisted', () => {
18111818
addedArgumentType: 'String',
18121819
hasDefaultValue: false,
18131820
isAddedFieldArgumentBreaking: false,
1821+
addedToNewField: false,
18141822
},
18151823
type: 'FIELD_ARGUMENT_ADDED',
18161824
},
@@ -1866,6 +1874,7 @@ describe('schema publishing changes are persisted', () => {
18661874
addedInputFieldName: 'b',
18671875
isAddedInputFieldTypeNullable: true,
18681876
addedInputFieldType: 'String',
1877+
addedToNewType: false,
18691878
},
18701879
type: 'INPUT_FIELD_ADDED',
18711880
},
@@ -1898,6 +1907,7 @@ describe('schema publishing changes are persisted', () => {
18981907
addedInputFieldName: 'b',
18991908
isAddedInputFieldTypeNullable: false,
19001909
addedInputFieldType: 'String!',
1910+
addedToNewType: false,
19011911
},
19021912
type: 'INPUT_FIELD_ADDED',
19031913
},
@@ -2125,6 +2135,7 @@ describe('schema publishing changes are persisted', () => {
21252135
meta: {
21262136
objectTypeName: 'Query',
21272137
addedInterfaceName: 'Foo',
2138+
addedToNewType: false,
21282139
},
21292140
type: 'OBJECT_TYPE_INTERFACE_ADDED',
21302141
},
@@ -2337,6 +2348,7 @@ describe('schema publishing changes are persisted', () => {
23372348
equalsObject: {
23382349
meta: {
23392350
addedTypeName: 'A',
2351+
addedTypeKind: 'ObjectTypeDefinition',
23402352
},
23412353
type: 'TYPE_ADDED',
23422354
},
@@ -2508,13 +2520,14 @@ describe('schema publishing changes are persisted', () => {
25082520
meta: {
25092521
unionName: 'C',
25102522
addedUnionMemberTypeName: 'B',
2523+
addedToNewType: false,
25112524
},
25122525
type: 'UNION_MEMBER_ADDED',
25132526
},
25142527
});
25152528

25162529
persistedTest({
2517-
name: 'UnionMemberAddedModel',
2530+
name: 'UnionMemberRemovedModel',
25182531
schemaBefore: /* GraphQL */ `
25192532
type Query {
25202533
a: String!
@@ -2612,6 +2625,8 @@ describe('schema publishing changes are persisted', () => {
26122625
enumName: 'Role',
26132626
enumValueName: 'USER',
26142627
addedDirectiveName: 'auth',
2628+
addedToNewType: false,
2629+
directiveRepeatedTimes: 1,
26152630
},
26162631
type: 'DIRECTIVE_USAGE_ENUM_VALUE_ADDED',
26172632
},
@@ -2648,6 +2663,7 @@ describe('schema publishing changes are persisted', () => {
26482663
enumName: 'Role',
26492664
enumValueName: 'USER',
26502665
removedDirectiveName: 'auth',
2666+
directiveRepeatedTimes: 1,
26512667
},
26522668
type: 'DIRECTIVE_USAGE_ENUM_VALUE_REMOVED',
26532669
},
@@ -2681,6 +2697,7 @@ describe('schema publishing changes are persisted', () => {
26812697
`,
26822698
equalsObject: {
26832699
meta: {
2700+
deprecationReason: 'No longer supported',
26842701
typeName: 'User',
26852702
fieldName: 'name',
26862703
},
@@ -2745,6 +2762,8 @@ describe('schema publishing changes are persisted', () => {
27452762
fieldName: 'user',
27462763
argumentName: 'id',
27472764
addedDirectiveName: 'validate',
2765+
addedToNewType: false,
2766+
directiveRepeatedTimes: 1,
27482767
},
27492768
type: 'DIRECTIVE_USAGE_ARGUMENT_DEFINITION_ADDED',
27502769
},
@@ -2772,6 +2791,7 @@ describe('schema publishing changes are persisted', () => {
27722791
fieldName: 'user',
27732792
argumentName: 'id',
27742793
removedDirectiveName: 'validate',
2794+
directiveRepeatedTimes: 1,
27752795
},
27762796
type: 'DIRECTIVE_USAGE_ARGUMENT_DEFINITION_REMOVED',
27772797
},
@@ -2805,6 +2825,8 @@ describe('schema publishing changes are persisted', () => {
28052825
meta: {
28062826
objectName: 'User',
28072827
addedDirectiveName: 'auth',
2828+
addedToNewType: false,
2829+
directiveRepeatedTimes: 1,
28082830
},
28092831
type: 'DIRECTIVE_USAGE_OBJECT_ADDED',
28102832
},
@@ -2838,6 +2860,7 @@ describe('schema publishing changes are persisted', () => {
28382860
meta: {
28392861
objectName: 'User',
28402862
removedDirectiveName: 'auth',
2863+
directiveRepeatedTimes: 1,
28412864
},
28422865
type: 'DIRECTIVE_USAGE_OBJECT_REMOVED',
28432866
},
@@ -2874,6 +2897,9 @@ describe('schema publishing changes are persisted', () => {
28742897
inputObjectName: 'UserInput',
28752898
inputFieldName: 'email',
28762899
addedDirectiveName: 'validate',
2900+
addedToNewType: false,
2901+
directiveRepeatedTimes: 1,
2902+
inputFieldType: 'String!',
28772903
},
28782904
type: 'DIRECTIVE_USAGE_INPUT_FIELD_DEFINITION_ADDED',
28792905
},
@@ -2907,6 +2933,7 @@ describe('schema publishing changes are persisted', () => {
29072933
`,
29082934
equalsObject: {
29092935
meta: {
2936+
directiveRepeatedTimes: 0,
29102937
inputObjectName: 'UserInput',
29112938
inputFieldName: 'email',
29122939
removedDirectiveName: 'validate',
@@ -2943,6 +2970,8 @@ describe('schema publishing changes are persisted', () => {
29432970
meta: {
29442971
interfaceName: 'Node',
29452972
addedDirectiveName: 'auth',
2973+
addedToNewType: false,
2974+
directiveRepeatedTimes: 1,
29462975
},
29472976
type: 'DIRECTIVE_USAGE_INTERFACE_ADDED',
29482977
},
@@ -2974,12 +3003,155 @@ describe('schema publishing changes are persisted', () => {
29743003
`,
29753004
equalsObject: {
29763005
meta: {
3006+
directiveRepeatedTimes: 1,
29773007
interfaceName: 'Node',
29783008
removedDirectiveName: 'auth',
29793009
},
29803010
type: 'DIRECTIVE_USAGE_INTERFACE_REMOVED',
29813011
},
29823012
});
3013+
3014+
persistedTest({
3015+
name: 'DirectiveUsageArgumentAdded',
3016+
schemaBefore: /* GraphQL */ `
3017+
directive @auth(roles: [String!]) on OBJECT
3018+
3019+
interface Node {
3020+
id: ID!
3021+
}
3022+
3023+
type Query @auth {
3024+
node: Node
3025+
}
3026+
`,
3027+
schemaAfter: /* GraphQL */ `
3028+
directive @auth(roles: [String!]) on OBJECT
3029+
3030+
interface Node {
3031+
id: ID!
3032+
}
3033+
3034+
type Query @auth(roles: ["node:read"]) {
3035+
node: Node
3036+
}
3037+
`,
3038+
equalsObject: {
3039+
meta: {
3040+
addedArgumentName: 'roles',
3041+
addedArgumentValue: '["node:read"]',
3042+
directiveName: 'auth',
3043+
directiveRepeatedTimes: 1,
3044+
oldArgumentValue: null,
3045+
parentArgumentName: null,
3046+
parentEnumValueName: null,
3047+
parentFieldName: null,
3048+
parentTypeName: 'Query',
3049+
},
3050+
type: 'DIRECTIVE_USAGE_ARGUMENT_ADDED',
3051+
},
3052+
});
3053+
3054+
persistedTest({
3055+
name: 'DirectiveUsageArgumentRemoved',
3056+
schemaBefore: /* GraphQL */ `
3057+
directive @auth(roles: [String!]) on OBJECT
3058+
3059+
interface Node {
3060+
id: ID!
3061+
}
3062+
3063+
type Query @auth(roles: ["node:read"]) {
3064+
node: Node
3065+
}
3066+
`,
3067+
schemaAfter: /* GraphQL */ `
3068+
directive @auth(roles: [String!]) on OBJECT
3069+
3070+
interface Node {
3071+
id: ID!
3072+
}
3073+
3074+
type Query @auth {
3075+
node: Node
3076+
}
3077+
`,
3078+
equalsObject: {
3079+
meta: {
3080+
directiveName: 'auth',
3081+
directiveRepeatedTimes: 1,
3082+
parentArgumentName: null,
3083+
parentEnumValueName: null,
3084+
parentFieldName: null,
3085+
parentTypeName: 'Query',
3086+
removedArgumentName: 'roles',
3087+
},
3088+
type: 'DIRECTIVE_USAGE_ARGUMENT_REMOVED',
3089+
},
3090+
});
3091+
3092+
persistedTest({
3093+
name: 'DirectiveRepeatableAdded',
3094+
schemaBefore: /* GraphQL */ `
3095+
directive @auth on OBJECT
3096+
3097+
interface Node {
3098+
id: ID!
3099+
}
3100+
3101+
type Query @auth {
3102+
node: Node
3103+
}
3104+
`,
3105+
schemaAfter: /* GraphQL */ `
3106+
directive @auth repeatable on OBJECT
3107+
3108+
interface Node {
3109+
id: ID!
3110+
}
3111+
3112+
type Query @auth {
3113+
node: Node
3114+
}
3115+
`,
3116+
equalsObject: {
3117+
meta: {
3118+
directiveName: 'auth',
3119+
},
3120+
type: 'DIRECTIVE_REPEATABLE_ADDED',
3121+
},
3122+
});
3123+
3124+
persistedTest({
3125+
name: 'DirectiveRepeatableRemoved',
3126+
schemaBefore: /* GraphQL */ `
3127+
directive @auth repeatable on OBJECT
3128+
3129+
interface Node {
3130+
id: ID!
3131+
}
3132+
3133+
type Query @auth {
3134+
node: Node
3135+
}
3136+
`,
3137+
schemaAfter: /* GraphQL */ `
3138+
directive @auth on OBJECT
3139+
3140+
interface Node {
3141+
id: ID!
3142+
}
3143+
3144+
type Query @auth {
3145+
node: Node
3146+
}
3147+
`,
3148+
equalsObject: {
3149+
meta: {
3150+
directiveName: 'auth',
3151+
},
3152+
type: 'DIRECTIVE_REPEATABLE_REMOVED',
3153+
},
3154+
});
29833155
});
29843156

29853157
const SchemaCompareToPreviousVersionQuery = graphql(`

packages/libraries/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"dependencies": {
5151
"@graphql-hive/core": "workspace:*",
52-
"@graphql-inspector/core": "6.4.1",
52+
"@graphql-inspector/core": "7.0.3",
5353
"@graphql-tools/code-file-loader": "~8.1.0",
5454
"@graphql-tools/graphql-file-loader": "~8.1.0",
5555
"@graphql-tools/json-file-loader": "~8.0.0",

packages/services/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@date-fns/utc": "2.1.1",
1818
"@graphql-hive/core": "workspace:*",
1919
"@graphql-hive/signal": "1.0.0",
20-
"@graphql-inspector/core": "6.4.1",
20+
"@graphql-inspector/core": "7.0.3",
2121
"@graphql-tools/merge": "9.1.1",
2222
"@hive/cdn-script": "workspace:*",
2323
"@hive/emails": "workspace:*",

packages/services/api/src/modules/schema/providers/inspector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type GraphQLSchema,
1111
} from 'graphql';
1212
import { Injectable, Scope } from 'graphql-modules';
13-
import { Change, ChangeType, diff, TypeOfChangeType } from '@graphql-inspector/core';
13+
import { Change, ChangeType, diff, DiffRule, TypeOfChangeType } from '@graphql-inspector/core';
1414
import { traceFn } from '@hive/service-common';
1515
import { HiveSchemaChangeModel } from '@hive/storage';
1616
import { Logger } from '../../shared/providers/logger';
@@ -34,7 +34,7 @@ export class Inspector {
3434
async diff(existing: GraphQLSchema, incoming: GraphQLSchema) {
3535
this.logger.debug('Comparing Schemas');
3636

37-
const changes = await diff(existing, incoming);
37+
const changes = await diff(existing, incoming, [DiffRule.simplifyChanges]);
3838

3939
return changes
4040
.filter(dropTrimmedDescriptionChangedChange)

0 commit comments

Comments
 (0)