Skip to content

Commit

Permalink
feat: added additional error detail to the graphql schema creation. S…
Browse files Browse the repository at this point in the history
…ee [16814]

Signed-off-by: Alexander Chernov <[email protected]>
  • Loading branch information
alekc committed Dec 30, 2020
1 parent bebe732 commit 416cd08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aws/resource_aws_appsync_graphql_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ func resourceAwsAppsyncSchemaPut(d *schema.ResourceData, meta interface{}) error
if err != nil {
return 0, "", err
}
if *result.Status == "FAILED" {
return result, *result.Status, fmt.Errorf("%s", *result.Details)
}
return result, *result.Status, nil
},
Timeout: d.Timeout(schema.TimeoutCreate),
Expand Down
26 changes: 26 additions & 0 deletions aws/resource_aws_appsync_graphql_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ func TestAccAWSAppsyncGraphqlApi_Schema(t *testing.T) {
})
}

func TestAccAWSAppsyncGraphqlApi_Schema_Error(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(appsync.EndpointsID, t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
{
Config: testAccAppsyncGraphqlApiConfig_Schema_Invalid(rName),
ExpectError: regexp.MustCompile("The field type 'PostV2' is not present when resolving type 'Query'"),
},
},
})
}

func TestAccAWSAppsyncGraphqlApi_AuthenticationType(t *testing.T) {
var api1, api2 appsync.GraphqlApi
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -1205,6 +1221,16 @@ resource "aws_appsync_graphql_api" "test" {
`, rName)
}

func testAccAppsyncGraphqlApiConfig_Schema_Invalid(rName string) string {
return fmt.Sprintf(`
resource "aws_appsync_graphql_api" "test" {
authentication_type = "API_KEY"
name = %q
schema = "type Mutation {\n\tputPost(id: ID!, title: String!): Post\n}\n\ntype Post {\n\tid: ID!\n\ttitle: String!\n}\n\ntype Query {\n\tsinglePost(id: ID!): PostV2\n}\n\nschema {\n\tquery: Query\n\tmutation: Mutation\n\n}\n"
}
`, rName)
}

func testAccAppsyncGraphqlApiConfig_SchemaUpdate(rName string) string {
return fmt.Sprintf(`
resource "aws_appsync_graphql_api" "test" {
Expand Down

0 comments on commit 416cd08

Please sign in to comment.