Skip to content

Commit

Permalink
integration tests for graphql resource package (aws#5271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssenchenko authored and lucashuy committed Jun 22, 2023
1 parent 40b3bfd commit d6aefb9
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/integration/package/test_package_command_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/testdata/package/aws-serverless-graphqlapi.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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),
};
}
7 changes: 7 additions & 0 deletions tests/integration/testdata/package/sam_graphql_api/getPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function request(ctx) {
return {};
}

export function response(ctx) {
return ctx.prev.result;
}
Original file line number Diff line number Diff line change
@@ -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),
};
}
22 changes: 22 additions & 0 deletions tests/integration/testdata/package/sam_graphql_api/schema.graphql
Original file line number Diff line number Diff line change
@@ -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!
}

0 comments on commit d6aefb9

Please sign in to comment.