Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 7 additions & 0 deletions .changeset/loose-dots-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-hive/cli': minor
'hive': minor
---

Upgrade graphql-inspector/core to v7 and update the models to be able to handle the new change
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.
3 changes: 1 addition & 2 deletions integration-tests/tests/api/policy/policy-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,12 @@ describe('Schema policy checks', () => {
'',
' - Deprecation reason is required for field foo in type Query. (source: policy-require-deprecation-reason)',
'',
'ℹ Detected 4 changes',
'ℹ Detected 3 changes',
'',
' Safe changes:',
' - Type User was added',
' - Field user was added to object type Query',
' - Field Query.foo is deprecated',
' - Directive deprecated was added to field Query.foo',
'',
'View full report:',
expect.any(String),
Expand Down
174 changes: 173 additions & 1 deletion integration-tests/tests/api/schema/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,9 @@ describe('schema publishing changes are persisted', () => {
equalsObject: {
meta: {
addedDirectiveName: 'foo',
addedDirectiveDescription: null,
addedDirectiveLocations: ['FIELD'],
addedDirectiveRepeatable: false,
},
type: 'DIRECTIVE_ADDED',
},
Expand Down Expand Up @@ -1278,8 +1281,10 @@ describe('schema publishing changes are persisted', () => {
`,
equalsObject: {
meta: {
addedDirectiveDescription: null,
enumName: 'Foo',
addedEnumValueName: 'b',
addedToNewType: false,
},
type: 'ENUM_VALUE_ADDED',
},
Expand Down Expand Up @@ -1523,6 +1528,7 @@ describe('schema publishing changes are persisted', () => {
typeName: 'Query',
addedFieldName: 'b',
typeType: 'object type',
addedFieldReturnType: 'String',
},
type: 'FIELD_ADDED',
},
Expand Down Expand Up @@ -1786,6 +1792,7 @@ describe('schema publishing changes are persisted', () => {
addedArgumentType: 'String!',
hasDefaultValue: false,
isAddedFieldArgumentBreaking: true,
addedToNewField: false,
},
type: 'FIELD_ARGUMENT_ADDED',
},
Expand All @@ -1811,6 +1818,7 @@ describe('schema publishing changes are persisted', () => {
addedArgumentType: 'String',
hasDefaultValue: false,
isAddedFieldArgumentBreaking: false,
addedToNewField: false,
},
type: 'FIELD_ARGUMENT_ADDED',
},
Expand Down Expand Up @@ -1866,6 +1874,7 @@ describe('schema publishing changes are persisted', () => {
addedInputFieldName: 'b',
isAddedInputFieldTypeNullable: true,
addedInputFieldType: 'String',
addedToNewType: false,
},
type: 'INPUT_FIELD_ADDED',
},
Expand Down Expand Up @@ -1898,6 +1907,7 @@ describe('schema publishing changes are persisted', () => {
addedInputFieldName: 'b',
isAddedInputFieldTypeNullable: false,
addedInputFieldType: 'String!',
addedToNewType: false,
},
type: 'INPUT_FIELD_ADDED',
},
Expand Down Expand Up @@ -2125,6 +2135,7 @@ describe('schema publishing changes are persisted', () => {
meta: {
objectTypeName: 'Query',
addedInterfaceName: 'Foo',
addedToNewType: false,
},
type: 'OBJECT_TYPE_INTERFACE_ADDED',
},
Expand Down Expand Up @@ -2337,6 +2348,7 @@ describe('schema publishing changes are persisted', () => {
equalsObject: {
meta: {
addedTypeName: 'A',
addedTypeKind: 'ObjectTypeDefinition',
},
type: 'TYPE_ADDED',
},
Expand Down Expand Up @@ -2508,13 +2520,14 @@ describe('schema publishing changes are persisted', () => {
meta: {
unionName: 'C',
addedUnionMemberTypeName: 'B',
addedToNewType: false,
},
type: 'UNION_MEMBER_ADDED',
},
});

persistedTest({
name: 'UnionMemberAddedModel',
name: 'UnionMemberRemovedModel',
schemaBefore: /* GraphQL */ `
type Query {
a: String!
Expand Down Expand Up @@ -2612,6 +2625,8 @@ describe('schema publishing changes are persisted', () => {
enumName: 'Role',
enumValueName: 'USER',
addedDirectiveName: 'auth',
addedToNewType: false,
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_ENUM_VALUE_ADDED',
},
Expand Down Expand Up @@ -2648,6 +2663,7 @@ describe('schema publishing changes are persisted', () => {
enumName: 'Role',
enumValueName: 'USER',
removedDirectiveName: 'auth',
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_ENUM_VALUE_REMOVED',
},
Expand Down Expand Up @@ -2681,6 +2697,7 @@ describe('schema publishing changes are persisted', () => {
`,
equalsObject: {
meta: {
deprecationReason: 'No longer supported',
typeName: 'User',
fieldName: 'name',
},
Expand Down Expand Up @@ -2745,6 +2762,8 @@ describe('schema publishing changes are persisted', () => {
fieldName: 'user',
argumentName: 'id',
addedDirectiveName: 'validate',
addedToNewType: false,
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_ARGUMENT_DEFINITION_ADDED',
},
Expand Down Expand Up @@ -2772,6 +2791,7 @@ describe('schema publishing changes are persisted', () => {
fieldName: 'user',
argumentName: 'id',
removedDirectiveName: 'validate',
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_ARGUMENT_DEFINITION_REMOVED',
},
Expand Down Expand Up @@ -2805,6 +2825,8 @@ describe('schema publishing changes are persisted', () => {
meta: {
objectName: 'User',
addedDirectiveName: 'auth',
addedToNewType: false,
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_OBJECT_ADDED',
},
Expand Down Expand Up @@ -2838,6 +2860,7 @@ describe('schema publishing changes are persisted', () => {
meta: {
objectName: 'User',
removedDirectiveName: 'auth',
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_OBJECT_REMOVED',
},
Expand Down Expand Up @@ -2874,6 +2897,9 @@ describe('schema publishing changes are persisted', () => {
inputObjectName: 'UserInput',
inputFieldName: 'email',
addedDirectiveName: 'validate',
addedToNewType: false,
directiveRepeatedTimes: 1,
inputFieldType: 'String!',
},
type: 'DIRECTIVE_USAGE_INPUT_FIELD_DEFINITION_ADDED',
},
Expand Down Expand Up @@ -2907,6 +2933,7 @@ describe('schema publishing changes are persisted', () => {
`,
equalsObject: {
meta: {
directiveRepeatedTimes: 0,
inputObjectName: 'UserInput',
inputFieldName: 'email',
removedDirectiveName: 'validate',
Expand Down Expand Up @@ -2943,6 +2970,8 @@ describe('schema publishing changes are persisted', () => {
meta: {
interfaceName: 'Node',
addedDirectiveName: 'auth',
addedToNewType: false,
directiveRepeatedTimes: 1,
},
type: 'DIRECTIVE_USAGE_INTERFACE_ADDED',
},
Expand Down Expand Up @@ -2974,12 +3003,155 @@ describe('schema publishing changes are persisted', () => {
`,
equalsObject: {
meta: {
directiveRepeatedTimes: 1,
interfaceName: 'Node',
removedDirectiveName: 'auth',
},
type: 'DIRECTIVE_USAGE_INTERFACE_REMOVED',
},
});

persistedTest({
name: 'DirectiveUsageArgumentAdded',
schemaBefore: /* GraphQL */ `
directive @auth(roles: [String!]) on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
schemaAfter: /* GraphQL */ `
directive @auth(roles: [String!]) on OBJECT
interface Node {
id: ID!
}
type Query @auth(roles: ["node:read"]) {
node: Node
}
`,
equalsObject: {
meta: {
addedArgumentName: 'roles',
addedArgumentValue: '["node:read"]',
directiveName: 'auth',
directiveRepeatedTimes: 1,
oldArgumentValue: null,
parentArgumentName: null,
parentEnumValueName: null,
parentFieldName: null,
parentTypeName: 'Query',
},
type: 'DIRECTIVE_USAGE_ARGUMENT_ADDED',
},
});

persistedTest({
name: 'DirectiveUsageArgumentRemoved',
schemaBefore: /* GraphQL */ `
directive @auth(roles: [String!]) on OBJECT
interface Node {
id: ID!
}
type Query @auth(roles: ["node:read"]) {
node: Node
}
`,
schemaAfter: /* GraphQL */ `
directive @auth(roles: [String!]) on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
equalsObject: {
meta: {
directiveName: 'auth',
directiveRepeatedTimes: 1,
parentArgumentName: null,
parentEnumValueName: null,
parentFieldName: null,
parentTypeName: 'Query',
removedArgumentName: 'roles',
},
type: 'DIRECTIVE_USAGE_ARGUMENT_REMOVED',
},
});

persistedTest({
name: 'DirectiveRepeatableAdded',
schemaBefore: /* GraphQL */ `
directive @auth on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
schemaAfter: /* GraphQL */ `
directive @auth repeatable on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
equalsObject: {
meta: {
directiveName: 'auth',
},
type: 'DIRECTIVE_REPEATABLE_ADDED',
},
});

persistedTest({
name: 'DirectiveRepeatableRemoved',
schemaBefore: /* GraphQL */ `
directive @auth repeatable on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
schemaAfter: /* GraphQL */ `
directive @auth on OBJECT
interface Node {
id: ID!
}
type Query @auth {
node: Node
}
`,
equalsObject: {
meta: {
directiveName: 'auth',
},
type: 'DIRECTIVE_REPEATABLE_REMOVED',
},
});
});

const SchemaCompareToPreviousVersionQuery = graphql(`
Expand Down
2 changes: 1 addition & 1 deletion packages/libraries/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@graphql-hive/core": "workspace:*",
"@graphql-inspector/core": "6.4.1",
"@graphql-inspector/core": "7.0.3",
"@graphql-tools/code-file-loader": "~8.1.0",
"@graphql-tools/graphql-file-loader": "~8.1.0",
"@graphql-tools/json-file-loader": "~8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/services/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@date-fns/utc": "2.1.1",
"@graphql-hive/core": "workspace:*",
"@graphql-hive/signal": "1.0.0",
"@graphql-inspector/core": "6.4.1",
"@graphql-inspector/core": "7.0.3",
"@graphql-tools/merge": "9.1.1",
"@hive/cdn-script": "workspace:*",
"@hive/emails": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type GraphQLSchema,
} from 'graphql';
import { Injectable, Scope } from 'graphql-modules';
import { Change, ChangeType, diff, TypeOfChangeType } from '@graphql-inspector/core';
import { Change, ChangeType, diff, DiffRule, TypeOfChangeType } from '@graphql-inspector/core';
import { traceFn } from '@hive/service-common';
import { HiveSchemaChangeModel } from '@hive/storage';
import { Logger } from '../../shared/providers/logger';
Expand All @@ -34,7 +34,7 @@ export class Inspector {
async diff(existing: GraphQLSchema, incoming: GraphQLSchema) {
this.logger.debug('Comparing Schemas');

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

return changes
.filter(dropTrimmedDescriptionChangedChange)
Expand Down
Loading
Loading