Skip to content

Commit

Permalink
Github: Adding option to send rules to the diff helper (#2259)
Browse files Browse the repository at this point in the history
* Adding option to send rules to the diff helper

* Adding changeset

* Allowing config to be passed through too
  • Loading branch information
Tohaker authored Jan 31, 2023
1 parent d72ad4d commit cdf4c13
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-bikes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-inspector/github': patch
---

Allowing rules to be passed through to `diff`
39 changes: 38 additions & 1 deletion packages/github/__tests__/diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CriticalityLevel } from '@graphql-inspector/core';
import { CriticalityLevel, DiffRule } from '@graphql-inspector/core';
import { buildSchema, Source } from 'graphql';
import nock from 'nock';
import { diff, DiffInterceptorPayload, DiffInterceptorResponse } from '../src/helpers/diff';
Expand Down Expand Up @@ -209,3 +209,40 @@ test('use interceptor to modify check conclusion', async () => {

scope.done();
});

test('should apply the rule suppressRemovalOfDeprecatedField to the diff', async () => {
const { schemas, sources } = build(
/* GraphQL */ `
type Post {
id: ID!
title: String @deprecated(reason: "No more used")
createdAt: String!
}
type Query {
post: Post!
}
`,
/* GraphQL */ `
type Post {
id: ID!
createdAt: String!
}
type Query {
post: Post!
}
`,
);

const action = await diff({
path: 'schema.graphql',
rules: [DiffRule.suppressRemovalOfDeprecatedField],
schemas,
sources,
});

expect(action.annotations).toHaveLength(1);
expect(action.changes).toHaveLength(1);
expect(action.conclusion).toBe(CheckConclusion.Success);
});
8 changes: 6 additions & 2 deletions packages/github/src/helpers/diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Change, CriticalityLevel, diff as diffSchemas } from '@graphql-inspector/core';
import { Change, CriticalityLevel, diff as diffSchemas, Rule } from '@graphql-inspector/core';
import axios from 'axios';
import { GraphQLSchema, Source } from 'graphql';
import { getLocationByPath } from './location';
Expand Down Expand Up @@ -32,6 +32,8 @@ export async function diff({
interceptor,
pullRequests,
ref,
rules,
config,
}: {
path: string;
schemas: {
Expand All @@ -45,8 +47,10 @@ export async function diff({
interceptor?: DiffInterceptor;
pullRequests?: PullRequest[];
ref?: string;
rules?: Rule[];
config?: Parameters<typeof diffSchemas>[3];
}): Promise<ActionResult> {
let changes = await diffSchemas(schemas.old, schemas.new);
let changes = await diffSchemas(schemas.old, schemas.new, rules, config);
let forcedConclusion: CheckConclusion | null = null;

if (!changes || !changes.length) {
Expand Down

0 comments on commit cdf4c13

Please sign in to comment.