Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use negative integer for from duration #30

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Apollo Schema Check Action Changelog

## 2.1.1 (November 15, 2022)

- Fix: Use negative from parameter when sending to Apollo backend (@comp615)

## 2.1.0 (October 31, 2022)

- Include a list of errors in the PR comment (@comp615)
Expand Down
4 changes: 4 additions & 0 deletions src/check-schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLClient, gql } from 'graphql-request';
import { getInput } from '@actions/core';

import { debug } from './actions-helpers';
import { getQueryVariables, QueryVariables } from './get-arguments';
import { formatMessage } from './format-message';

Expand Down Expand Up @@ -104,6 +105,9 @@ const checkSchema = async (commentIdentifier: string, existingComment: boolean):

try {
const variables = await getQueryVariables();

debug('Apollo Studio request variables', JSON.stringify(variables, null, 2));

const data = await graphQLClient.request<ApolloStudioResponse, QueryVariables>(mutation, variables);

return formatMessage(data, variables, commentIdentifier, existingComment);
Expand Down
4 changes: 2 additions & 2 deletions src/get-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const getApolloConfigFile = async (file: string): Promise<ApolloConfigFile> => {

const getFromValue = (validationPeriod: string): string => {
if (validationPeriod.startsWith('P')) {
return `${toSeconds(parse(validationPeriod))}`;
return `-${toSeconds(parse(validationPeriod))}`;
} else if (validationPeriod.match(/^-?\d+$/)) {
return `${Math.abs(Number.parseInt(validationPeriod))}`;
return `-${Math.abs(Number.parseInt(validationPeriod))}`;
} else {
return validationPeriod;
}
Expand Down
6 changes: 3 additions & 3 deletions test/get-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ describe.skip('getQueryVariables', () => {

describe('getFromValue', () => {
test('negative number of seconds', () => {
expect(getFromValue('-86400')).toBe('86400');
expect(getFromValue('-86400')).toBe('-86400');
});

test('positive number of seconds', () => {
expect(getFromValue('300')).toBe('300');
expect(getFromValue('300')).toBe('-300');
});

test('ISO 8601 duration', () => {
expect(getFromValue('P2W')).toBe('1209600');
expect(getFromValue('P2W')).toBe('-1209600');
});

test('Plain text duration', () => {
Expand Down