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

fix(amplify-appsync-simulator): parse AWSTimestamp literals as Ints #6979

Merged
merged 1 commit into from
Apr 9, 2021
Merged
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
64 changes: 32 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,37 +1077,37 @@ jobs:
environment:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
migration-node-function-amplify_e2e_tests:
schema-iterative-update-locking-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: ap-southeast-1
api_4-amplify_e2e_tests:
migration-node-function-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-2
schema-iterative-update-locking-amplify_e2e_tests:
function_5-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-east-2
function_5-amplify_e2e_tests:
api_4-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: us-west-2
schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand Down Expand Up @@ -1719,44 +1719,44 @@ jobs:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
steps: *ref_5
migration-node-function-amplify_e2e_tests_pkg_linux:
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: ap-southeast-1
steps: *ref_5
api_4-amplify_e2e_tests_pkg_linux:
migration-node-function-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-2
steps: *ref_5
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
function_5-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-east-2
steps: *ref_5
function_5-amplify_e2e_tests_pkg_linux:
api_4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: us-west-2
steps: *ref_5
workflows:
Expand Down Expand Up @@ -1854,11 +1854,11 @@ workflows:
- hostingPROD-amplify_e2e_tests
- amplify-app-amplify_e2e_tests
- init-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- function_5-amplify_e2e_tests
- predictions-amplify_e2e_tests
- schema-predictions-amplify_e2e_tests
- amplify-configure-amplify_e2e_tests
- function_5-amplify_e2e_tests
- api_4-amplify_e2e_tests
- function_3-amplify_e2e_tests
- containers-api-amplify_e2e_tests
- interactions-amplify_e2e_tests
Expand All @@ -1874,22 +1874,22 @@ workflows:
- schema-key-amplify_e2e_tests
- analytics-amplify_e2e_tests
- notifications-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- schema-auth-10-amplify_e2e_tests
- hosting-amplify_e2e_tests
- tags-amplify_e2e_tests
- api_4-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- done_with_pkg_linux_e2e_tests:
context: amplify-cli-ecr
requires:
- hostingPROD-amplify_e2e_tests_pkg_linux
- amplify-app-amplify_e2e_tests_pkg_linux
- init-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- predictions-amplify_e2e_tests_pkg_linux
- schema-predictions-amplify_e2e_tests_pkg_linux
- amplify-configure-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- function_3-amplify_e2e_tests_pkg_linux
- containers-api-amplify_e2e_tests_pkg_linux
- interactions-amplify_e2e_tests_pkg_linux
Expand All @@ -1905,11 +1905,11 @@ workflows:
- schema-key-amplify_e2e_tests_pkg_linux
- analytics-amplify_e2e_tests_pkg_linux
- notifications-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- schema-auth-10-amplify_e2e_tests_pkg_linux
- hosting-amplify_e2e_tests_pkg_linux
- tags-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- amplify_migration_tests_latest:
context: amplify-cli-ecr
filters:
Expand Down Expand Up @@ -2059,7 +2059,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-7-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests:
- function_5-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2119,7 +2119,7 @@ workflows:
filters: *ref_8
requires:
- auth_4-amplify_e2e_tests
- function_5-amplify_e2e_tests:
- api_4-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2335,7 +2335,7 @@ workflows:
filters: *ref_8
requires:
- schema-searchable-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests:
- schema-iterative-update-locking-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2389,7 +2389,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-8-amplify_e2e_tests
- api_4-amplify_e2e_tests:
- migration-node-function-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2457,7 +2457,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-7-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
- function_5-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2521,7 +2521,7 @@ workflows:
filters: *ref_10
requires:
- auth_4-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux:
- api_4-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2753,7 +2753,7 @@ workflows:
filters: *ref_10
requires:
- schema-searchable-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux:
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2811,7 +2811,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-8-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
- migration-node-function-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ValueNode } from 'graphql';
import { scalars } from '../../schema/appsync-scalars';

describe('AWSTimestamp parseLiteral', () => {
it('Returns literals as integers', () => {
const astNode = { kind: 'IntValue', value: '1234', loc: { start: 68, end: 74 } } as ValueNode;
expect(scalars.AWSTimestamp.parseLiteral(astNode, null)).toEqual(1234);
});

it('Rejects non-integer literals', () => {
const astNode = { kind: 'StringValue', value: '1234', loc: { start: 68, end: 74 } } as ValueNode;

expect(() => {
scalars.AWSTimestamp.parseLiteral(astNode, null);
}).toThrow('Can only validate integers but received: StringValue');
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { URL } from 'url';
import { GraphQLInt, GraphQLScalarType, GraphQLError, Kind, StringValueNode } from 'graphql';
import { GraphQLInt, GraphQLScalarType, GraphQLError, Kind, StringValueNode, ValueNode } from 'graphql';
import { isValidNumber } from 'libphonenumber-js';

import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';
Expand Down Expand Up @@ -104,8 +104,12 @@ are also accepted and these represent the number of seconds till 1970-01-01T00:0
parseValue(value) {
return GraphQLInt.parseValue(value) ? value : undefined;
},
parseLiteral(value) {
return GraphQLInt.parseLiteral(value, null) ? (value as StringValueNode).value : undefined;
parseLiteral(value: ValueNode) {
if (value.kind !== Kind.INT) {
throw new GraphQLError(`Can only validate integers but received: ${value.kind}`);
}

return Number.parseInt(value.value, 10);
},
});

Expand Down