diff --git a/tests/integration/package/test_package_command_zip.py b/tests/integration/package/test_package_command_zip.py index b18524cfb4..85d2f36ab5 100644 --- a/tests/integration/package/test_package_command_zip.py +++ b/tests/integration/package/test_package_command_zip.py @@ -88,6 +88,7 @@ def test_package_nested_template(self, template_file, uploading_count): "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", "aws-include-transform.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_barebones(self, template_file): @@ -140,6 +141,7 @@ def test_package_without_required_args(self): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_prefix(self, template_file): @@ -183,6 +185,7 @@ def test_package_with_prefix(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_output_template_file(self, template_file): @@ -237,6 +240,7 @@ def test_package_with_output_template_file(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_json(self, template_file): @@ -292,6 +296,7 @@ def test_package_with_json(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_force_upload(self, template_file): @@ -349,6 +354,7 @@ def test_package_with_force_upload(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_kms_key(self, template_file): @@ -405,6 +411,7 @@ def test_package_with_kms_key(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_metadata(self, template_file): @@ -460,6 +467,7 @@ def test_package_with_metadata(self, template_file): "aws-serverlessrepo-application.yaml", "aws-serverless-statemachine.yaml", "aws-stepfunctions-statemachine.yaml", + "aws-serverless-graphqlapi.yaml", ] ) def test_package_with_resolve_s3(self, template_file): diff --git a/tests/integration/testdata/package/aws-serverless-graphqlapi.yaml b/tests/integration/testdata/package/aws-serverless-graphqlapi.yaml new file mode 100644 index 0000000000..ba55a34310 --- /dev/null +++ b/tests/integration/testdata/package/aws-serverless-graphqlapi.yaml @@ -0,0 +1,46 @@ +Transform: AWS::Serverless-2016-10-31 + +Resources: + DynamoDBPostsTable: + Type: AWS::Serverless::SimpleTable + + SuperCoolAPI: + Type: AWS::Serverless::GraphQLApi + Properties: + SchemaUri: ./sam_graphql_api/schema.graphql + Auth: + Type: AWS_IAM + DataSources: + DynamoDb: + PostsDataSource: + TableName: !Ref DynamoDBPostsTable + TableArn: !GetAtt DynamoDBPostsTable.Arn + Functions: + createPostItem: + Runtime: + Name: APPSYNC_JS + Version: "1.0.0" + DataSource: PostsDataSource + CodeUri: ./sam_graphql_api/createPostItem.js + getPostFromTable: + Runtime: + Name: APPSYNC_JS + Version: "1.0.0" + DataSource: PostsDataSource + CodeUri: ./sam_graphql_api/getPostFromTable.js + Resolvers: + Mutation: + addPost: + Runtime: + Name: APPSYNC_JS + Version: "1.0.0" + Pipeline: + - createPostItem + Query: + getPost: + CodeUri: ./sam_graphql_api/getPost.js + Runtime: + Name: APPSYNC_JS + Version: "1.0.0" + Pipeline: + - getPostFromTable diff --git a/tests/integration/testdata/package/sam_graphql_api/createPostItem.js b/tests/integration/testdata/package/sam_graphql_api/createPostItem.js new file mode 100644 index 0000000000..ca55c8bc75 --- /dev/null +++ b/tests/integration/testdata/package/sam_graphql_api/createPostItem.js @@ -0,0 +1,19 @@ +import { util } from "@aws-appsync/utils"; + +export function request(ctx) { + return dynamoDBGetItemRequest({ id: ctx.args.id }); +} + +export function response(ctx) { + return ctx.result; +} + +/** + * A helper function to get a DynamoDB item + */ +function dynamoDBGetItemRequest(key) { + return { + operation: "GetItem", + key: util.dynamodb.toMapValues(key), + }; +} diff --git a/tests/integration/testdata/package/sam_graphql_api/getPost.js b/tests/integration/testdata/package/sam_graphql_api/getPost.js new file mode 100644 index 0000000000..86a88bd957 --- /dev/null +++ b/tests/integration/testdata/package/sam_graphql_api/getPost.js @@ -0,0 +1,7 @@ +export function request(ctx) { + return {}; +} + +export function response(ctx) { + return ctx.prev.result; +} diff --git a/tests/integration/testdata/package/sam_graphql_api/getPostFromTable.js b/tests/integration/testdata/package/sam_graphql_api/getPostFromTable.js new file mode 100644 index 0000000000..ca55c8bc75 --- /dev/null +++ b/tests/integration/testdata/package/sam_graphql_api/getPostFromTable.js @@ -0,0 +1,19 @@ +import { util } from "@aws-appsync/utils"; + +export function request(ctx) { + return dynamoDBGetItemRequest({ id: ctx.args.id }); +} + +export function response(ctx) { + return ctx.result; +} + +/** + * A helper function to get a DynamoDB item + */ +function dynamoDBGetItemRequest(key) { + return { + operation: "GetItem", + key: util.dynamodb.toMapValues(key), + }; +} diff --git a/tests/integration/testdata/package/sam_graphql_api/schema.graphql b/tests/integration/testdata/package/sam_graphql_api/schema.graphql new file mode 100644 index 0000000000..e529ee0615 --- /dev/null +++ b/tests/integration/testdata/package/sam_graphql_api/schema.graphql @@ -0,0 +1,22 @@ +schema { + query: Query + mutation: Mutation +} + +type Query { + getPost(id: String!): Post +} + +type Mutation { + addPost(author: String!, title: String!, content: String!): Post! +} + +type Post { + id: String! + author: String + title: String + content: String + ups: Int! + downs: Int! + version: Int! +}