Skip to content

Commit fdaa826

Browse files
authored
Merge branch 'main' into release-v1.70.0
2 parents b5dbc6f + 063ac27 commit fdaa826

File tree

102 files changed

+10915
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+10915
-14
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import json
2+
from unittest.case import skipIf
3+
4+
import requests
5+
6+
from integration.config.service_names import APP_SYNC
7+
from integration.helpers.base_test import BaseTest
8+
from integration.helpers.resource import current_region_does_not_support
9+
10+
11+
def execute_and_verify_appsync_query(url, api_key, query):
12+
"""
13+
Executes a query to an AppSync GraphQLApi.
14+
15+
Also checks that the response is 200 and does not contain errors before returning.
16+
"""
17+
headers = {
18+
"Content-Type": "application/json",
19+
"x-api-key": api_key,
20+
}
21+
payload = {"query": query}
22+
23+
response = requests.post(url, json=payload, headers=headers)
24+
response.raise_for_status()
25+
data = response.json()
26+
if "errors" in data:
27+
raise Exception(json.dumps(data["errors"]))
28+
29+
return data
30+
31+
32+
@skipIf(current_region_does_not_support([APP_SYNC]), "AppSync is not supported in this testing region")
33+
class TestGraphQLApiPipelineResolver(BaseTest):
34+
def test_api(self):
35+
file_name = "combination/graphqlapi_lambda_resolver"
36+
self.create_and_verify_stack(file_name)
37+
38+
outputs = self.get_stack_outputs()
39+
40+
author = "AUTHORNAME"
41+
title = "Our first post!"
42+
content = "This is our first post."
43+
44+
query = f"""
45+
mutation addPost {{
46+
addPost(
47+
id: 100
48+
author: "{author}"
49+
title: "{title}"
50+
content: "{content}"
51+
) {{
52+
id
53+
author
54+
title
55+
content
56+
}}
57+
}}
58+
"""
59+
60+
url = outputs["SuperCoolAPI"]
61+
api_key = outputs["SuperCoolAPIMyApiKey"]
62+
63+
response = execute_and_verify_appsync_query(url, api_key, query)
64+
65+
add_post = response["data"]["addPost"]
66+
67+
self.assertEqual(add_post["id"], "100")
68+
self.assertEqual(add_post["author"], author)
69+
self.assertEqual(add_post["title"], title)
70+
self.assertEqual(add_post["content"], content)
71+
72+
query = """
73+
query getPost {
74+
getPost(id:"1") {
75+
id
76+
author
77+
title
78+
content
79+
ups
80+
downs
81+
}
82+
}
83+
"""
84+
85+
response = execute_and_verify_appsync_query(url, api_key, query)
86+
87+
get_post = response["data"]["getPost"]
88+
89+
# These values are hardcoded inside the Lambda function for a post with id "1".
90+
author = "Author1"
91+
title = "First book"
92+
content = "Book 1 has this content"
93+
ups = 100
94+
downs = 10
95+
96+
self.assertEqual(get_post["id"], "1")
97+
self.assertEqual(get_post["author"], author)
98+
self.assertEqual(get_post["title"], title)
99+
self.assertEqual(get_post["content"], content)
100+
self.assertEqual(get_post["ups"], ups)
101+
self.assertEqual(get_post["downs"], downs)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import json
2+
from unittest.case import skipIf
3+
4+
import requests
5+
6+
from integration.config.service_names import APP_SYNC
7+
from integration.helpers.base_test import BaseTest
8+
from integration.helpers.resource import current_region_does_not_support
9+
10+
11+
def execute_and_verify_appsync_query(url, api_key, query):
12+
"""
13+
Executes a query to an AppSync GraphQLApi.
14+
15+
Also checks that the response is 200 and does not contain errors before returning.
16+
"""
17+
headers = {
18+
"Content-Type": "application/json",
19+
"x-api-key": api_key,
20+
}
21+
payload = {"query": query}
22+
23+
response = requests.post(url, json=payload, headers=headers)
24+
response.raise_for_status()
25+
data = response.json()
26+
if "errors" in data:
27+
raise Exception(json.dumps(data["errors"]))
28+
29+
return data
30+
31+
32+
@skipIf(current_region_does_not_support([APP_SYNC]), "AppSync is not supported in this testing region")
33+
class TestGraphQLApiPipelineResolver(BaseTest):
34+
def test_api(self):
35+
file_name = "combination/graphqlapi_pipeline_resolver"
36+
self.create_and_verify_stack(file_name)
37+
38+
outputs = self.get_stack_outputs()
39+
40+
author = "AUTHORNAME"
41+
title = "Our first post!"
42+
content = "This is our first post."
43+
44+
query = f"""
45+
mutation addPost {{
46+
addPost(
47+
author: "{author}"
48+
title: "{title}"
49+
content: "{content}"
50+
) {{
51+
id
52+
author
53+
title
54+
content
55+
ups
56+
downs
57+
version
58+
}}
59+
}}
60+
"""
61+
62+
url = outputs["SuperCoolAPI"]
63+
api_key = outputs["MyApiKey"]
64+
65+
response = execute_and_verify_appsync_query(url, api_key, query)
66+
67+
add_post = response["data"]["addPost"]
68+
69+
self.assertEqual(add_post["author"], author)
70+
self.assertEqual(add_post["title"], title)
71+
self.assertEqual(add_post["content"], content)
72+
self.assertEqual(add_post["ups"], 1)
73+
self.assertEqual(add_post["downs"], 0)
74+
self.assertEqual(add_post["version"], 1)
75+
76+
post_id = add_post["id"]
77+
query = f"""
78+
query getPost {{
79+
getPost(id:"{post_id}") {{
80+
id
81+
author
82+
title
83+
content
84+
ups
85+
downs
86+
version
87+
}}
88+
}}
89+
"""
90+
91+
response = execute_and_verify_appsync_query(url, api_key, query)
92+
93+
get_post = response["data"]["getPost"]
94+
95+
self.assertEqual(get_post["author"], author)
96+
self.assertEqual(get_post["title"], title)
97+
self.assertEqual(get_post["content"], content)
98+
self.assertEqual(get_post["ups"], 1)
99+
self.assertEqual(get_post["downs"], 0)
100+
self.assertEqual(get_post["version"], 1)
101+
self.assertEqual(get_post["id"], post_id)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"LogicalResourceId": "MyLambdaFunction",
4+
"ResourceType": "AWS::Lambda::Function"
5+
},
6+
{
7+
"LogicalResourceId": "LambdaFunctionRole",
8+
"ResourceType": "AWS::IAM::Role"
9+
},
10+
{
11+
"LogicalResourceId": "SuperCoolAPI",
12+
"ResourceType": "AWS::AppSync::GraphQLApi"
13+
},
14+
{
15+
"LogicalResourceId": "SuperCoolAPISchema",
16+
"ResourceType": "AWS::AppSync::GraphQLSchema"
17+
},
18+
{
19+
"LogicalResourceId": "SuperCoolAPICloudWatchRole",
20+
"ResourceType": "AWS::IAM::Role"
21+
},
22+
{
23+
"LogicalResourceId": "SuperCoolAPIMyApiKey",
24+
"ResourceType": "AWS::AppSync::ApiKey"
25+
},
26+
{
27+
"LogicalResourceId": "SuperCoolAPIMyLambdaDataSourceLambdaDataSource",
28+
"ResourceType": "AWS::AppSync::DataSource"
29+
},
30+
{
31+
"LogicalResourceId": "SuperCoolAPIMyLambdaDataSourceLambdaDataSourceRole",
32+
"ResourceType": "AWS::IAM::Role"
33+
},
34+
{
35+
"LogicalResourceId": "SuperCoolAPIMyLambdaDataSourceLambdaDataSourceToLambdaConnectorPolicy",
36+
"ResourceType": "AWS::IAM::ManagedPolicy"
37+
},
38+
{
39+
"LogicalResourceId": "SuperCoolAPIlambdaInvoker",
40+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
41+
},
42+
{
43+
"LogicalResourceId": "SuperCoolAPIMutationaddPost",
44+
"ResourceType": "AWS::AppSync::Resolver"
45+
},
46+
{
47+
"LogicalResourceId": "SuperCoolAPIQuerygetPost",
48+
"ResourceType": "AWS::AppSync::Resolver"
49+
}
50+
]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[
2+
{
3+
"LogicalResourceId": "MyApiKey",
4+
"ResourceType": "AWS::AppSync::ApiKey"
5+
},
6+
{
7+
"LogicalResourceId": "DynamoDBPostsTable",
8+
"ResourceType": "AWS::DynamoDB::Table"
9+
},
10+
{
11+
"LogicalResourceId": "DynamoDBPostsLogTable",
12+
"ResourceType": "AWS::DynamoDB::Table"
13+
},
14+
{
15+
"LogicalResourceId": "SuperCoolAPI",
16+
"ResourceType": "AWS::AppSync::GraphQLApi"
17+
},
18+
{
19+
"LogicalResourceId": "SuperCoolAPISchema",
20+
"ResourceType": "AWS::AppSync::GraphQLSchema"
21+
},
22+
{
23+
"LogicalResourceId": "SuperCoolAPICloudWatchRole",
24+
"ResourceType": "AWS::IAM::Role"
25+
},
26+
{
27+
"LogicalResourceId": "SuperCoolAPIPostsDataSourceDynamoDBDataSource",
28+
"ResourceType": "AWS::AppSync::DataSource"
29+
},
30+
{
31+
"LogicalResourceId": "SuperCoolAPIPostsDataSourceDynamoDBDataSourceRole",
32+
"ResourceType": "AWS::IAM::Role"
33+
},
34+
{
35+
"LogicalResourceId": "SuperCoolAPIPostsDataSourceDynamoDBDataSourceToTableConnectorPolicy",
36+
"ResourceType": "AWS::IAM::ManagedPolicy"
37+
},
38+
{
39+
"LogicalResourceId": "SuperCoolAPIPostsLogDataSourceDynamoDBDataSource",
40+
"ResourceType": "AWS::AppSync::DataSource"
41+
},
42+
{
43+
"LogicalResourceId": "SuperCoolAPIPostsLogDataSourceDynamoDBDataSourceRole",
44+
"ResourceType": "AWS::IAM::Role"
45+
},
46+
{
47+
"LogicalResourceId": "SuperCoolAPIPostsLogDataSourceDynamoDBDataSourceToTableConnectorPolicy",
48+
"ResourceType": "AWS::IAM::ManagedPolicy"
49+
},
50+
{
51+
"LogicalResourceId": "SuperCoolAPIcreatePostItem",
52+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
53+
},
54+
{
55+
"LogicalResourceId": "SuperCoolAPIcreatePostLogItem",
56+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
57+
},
58+
{
59+
"LogicalResourceId": "SuperCoolAPIformatPostLogItem",
60+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
61+
},
62+
{
63+
"LogicalResourceId": "SuperCoolAPIformatPostItem",
64+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
65+
},
66+
{
67+
"LogicalResourceId": "SuperCoolAPIMutationaddPost",
68+
"ResourceType": "AWS::AppSync::Resolver"
69+
},
70+
{
71+
"LogicalResourceId": "SuperCoolAPIgetPostFromTable",
72+
"ResourceType": "AWS::AppSync::FunctionConfiguration"
73+
},
74+
{
75+
"LogicalResourceId": "SuperCoolAPIQuerygetPost",
76+
"ResourceType": "AWS::AppSync::Resolver"
77+
},
78+
{
79+
"LogicalResourceId": "SuperCoolAPINoneDataSource",
80+
"ResourceType": "AWS::AppSync::DataSource"
81+
}
82+
]

0 commit comments

Comments
 (0)