Skip to content

Commit

Permalink
test: improve schema validation in tests (aws-amplify#7845)
Browse files Browse the repository at this point in the history
This commit exposes the validateModelSchema() function from
the GraphQL Transformer core. This function is helpful
for validating the Transformer output schema's correctness.
This commit also applies the validation to @predictions v2
test suite.

Co-authored-by: Colin Ihrig <colihrig@amazon.com>
  • Loading branch information
2 people authored and akshbhu committed Aug 15, 2021
1 parent f355fa2 commit a7f77a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { anything, countResources, expect as cdkExpect, haveResourceLike } from '@aws-cdk/assert';
import { GraphQLTransform } from '@aws-amplify/graphql-transformer-core';
import { GraphQLTransform, validateModelSchema } from '@aws-amplify/graphql-transformer-core';
import { parse } from 'graphql';
import { PredictionsTransformer } from '..';

Expand All @@ -14,6 +14,7 @@ test('does not generate any resources if @predictions is unused', () => {
});

const out = transformer.transform(schema);
validateModelSchema(parse(out.schema));
expect(out).toBeDefined();
expect(out.stacks).toBeDefined();
expect(out.stacks.PredictionsDirectiveStack).toEqual(undefined);
Expand All @@ -31,7 +32,7 @@ test('lambda function is added to pipeline when lambda dependent action is added
const out = transformer.transform(validSchema);
expect(out).toBeDefined();
expect(out.stacks).toBeDefined();
parse(out.schema);
validateModelSchema(parse(out.schema));
expect(out.schema).toMatchSnapshot();
const stack = out.stacks.PredictionsDirectiveStack;
expect(stack).toBeDefined();
Expand Down Expand Up @@ -157,7 +158,7 @@ test('return type is a list based on the action', () => {
const out = transformer.transform(validSchema);
expect(out).toBeDefined();
expect(out.stacks).toBeDefined();
parse(out.schema);
validateModelSchema(parse(out.schema));
expect(out.schema).toMatchSnapshot();
const stack = out.stacks.PredictionsDirectiveStack;
expect(stack).toBeDefined();
Expand Down Expand Up @@ -186,7 +187,7 @@ test('can use actions individually and in supported sequences', () => {
const out = transformer.transform(validSchema);
expect(out).toBeDefined();
expect(out.stacks).toBeDefined();
parse(out.schema);
validateModelSchema(parse(out.schema));
expect(out.schema).toMatchSnapshot();
const stack = out.stacks.PredictionsDirectiveStack;
expect(stack).toBeDefined();
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-graphql-transformer-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
UserPoolConfig,
} from './transformation';
export { DeploymentResources } from './transformation/types';
export { validateModelSchema } from './transformation/validation';
export {
ConflictDetectionType,
ConflictHandlerType,
Expand Down

0 comments on commit a7f77a6

Please sign in to comment.