| 
									
										
										
										
											2022-01-14 20:12:26 -01:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from moto import mock_appsync | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | schema = """type Mutation {
 | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     putPost(id: ID!, title: String!): Post | 
					
						
							| 
									
										
										
										
											2022-01-14 20:12:26 -01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "My custom post type" | 
					
						
							|  |  |  | type Post { | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     id: ID! | 
					
						
							|  |  |  |     title: String! | 
					
						
							| 
									
										
										
										
											2022-01-14 20:12:26 -01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Query { | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     singlePost(id: ID!): Post | 
					
						
							| 
									
										
										
										
											2022-01-14 20:12:26 -01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | schema { | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     query: Query | 
					
						
							|  |  |  |     mutation: Mutation | 
					
						
							| 
									
										
										
										
											2022-01-14 20:12:26 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | }"""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_appsync | 
					
						
							|  |  |  | def test_start_schema_creation(): | 
					
						
							|  |  |  |     client = boto3.client("appsync", region_name="us-east-2") | 
					
						
							|  |  |  |     api_id = client.create_graphql_api(name="api1", authenticationType="API_KEY")[ | 
					
						
							|  |  |  |         "graphqlApi" | 
					
						
							|  |  |  |     ]["apiId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.start_schema_creation(apiId=api_id, definition=b"sth") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp.should.have.key("status").equals("PROCESSING") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_appsync | 
					
						
							|  |  |  | def test_get_schema_creation_status(): | 
					
						
							|  |  |  |     client = boto3.client("appsync", region_name="eu-west-1") | 
					
						
							|  |  |  |     api_id = client.create_graphql_api(name="api1", authenticationType="API_KEY")[ | 
					
						
							|  |  |  |         "graphqlApi" | 
					
						
							|  |  |  |     ]["apiId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.start_schema_creation(apiId=api_id, definition=schema.encode("utf-8")) | 
					
						
							|  |  |  |     resp = client.get_schema_creation_status(apiId=api_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp.should.have.key("status").equals("SUCCESS") | 
					
						
							|  |  |  |     resp.shouldnt.have.key("details") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_appsync | 
					
						
							|  |  |  | def test_get_schema_creation_status_invalid(): | 
					
						
							|  |  |  |     client = boto3.client("appsync", region_name="eu-west-1") | 
					
						
							|  |  |  |     api_id = client.create_graphql_api(name="api1", authenticationType="API_KEY")[ | 
					
						
							|  |  |  |         "graphqlApi" | 
					
						
							|  |  |  |     ]["apiId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.start_schema_creation(apiId=api_id, definition=b"sth") | 
					
						
							|  |  |  |     resp = client.get_schema_creation_status(apiId=api_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp.should.have.key("status").equals("FAILED") | 
					
						
							|  |  |  |     resp.should.have.key("details").match("Syntax Error") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_appsync | 
					
						
							|  |  |  | def test_get_type_from_schema(): | 
					
						
							|  |  |  |     client = boto3.client("appsync", region_name="us-east-2") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     api_id = client.create_graphql_api(name="api1", authenticationType="API_KEY")[ | 
					
						
							|  |  |  |         "graphqlApi" | 
					
						
							|  |  |  |     ]["apiId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.start_schema_creation(apiId=api_id, definition=schema.encode("utf-8")) | 
					
						
							|  |  |  |     resp = client.get_type(apiId=api_id, typeName="Post", format="SDL") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp.should.have.key("type") | 
					
						
							|  |  |  |     graphql_type = resp["type"] | 
					
						
							|  |  |  |     graphql_type.should.have.key("name").equals("Post") | 
					
						
							|  |  |  |     graphql_type.should.have.key("description").equals("My custom post type") | 
					
						
							|  |  |  |     graphql_type.should.have.key("arn").equals("arn:aws:appsync:graphql_type/Post") | 
					
						
							|  |  |  |     graphql_type.should.have.key("definition").equals("NotYetImplemented") | 
					
						
							|  |  |  |     graphql_type.should.have.key("format").equals("SDL") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     query_type = client.get_type(apiId=api_id, typeName="Query", format="SDL")["type"] | 
					
						
							|  |  |  |     query_type.should.have.key("name").equals("Query") | 
					
						
							|  |  |  |     query_type.shouldnt.have.key("description") |