From 5d1d626cbe43b17383a0886a1ae81073eb7a84be Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:08:04 -0600 Subject: [PATCH] fix(appsync): validate type updates before mutation (#8129) Reject an invalid type format before changing the stored definition. Keep validation inside the existing synchronized update operation. Cover the refused request through service and AWS SDK tests, including unchanged get/list responses and a subsequent successful valid update. Signed-off-by: Andre Kurait Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Co-authored-by: Andre Kurait --- pom.xml | 6 ++ .../aws/services/appsync/AppSyncService.java | 13 ++++- .../services/appsync/AppSyncServiceTest.java | 14 +++++ .../AppSyncUpdateTypeIntegrationTest.java | 55 +++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java diff --git a/pom.xml b/pom.xml index 1529b12176..5591397a06 100644 --- a/pom.xml +++ b/pom.xml @@ -542,6 +542,12 @@ ${aws.sdk.version} test + + software.amazon.awssdk + appsync + ${aws.sdk.version} + test + software.amazon.awssdk ssm diff --git a/src/main/java/io/floci/aws/services/appsync/AppSyncService.java b/src/main/java/io/floci/aws/services/appsync/AppSyncService.java index fdf10dc751..2e7e7306be 100644 --- a/src/main/java/io/floci/aws/services/appsync/AppSyncService.java +++ b/src/main/java/io/floci/aws/services/appsync/AppSyncService.java @@ -616,9 +616,16 @@ public class AppSyncService { public synchronized AppSyncType updateType(String apiId, String typeName, Map request) { assertSchemaNotBusy(apiId); AppSyncType existing = getType(apiId, typeName); - if (request.containsKey("definition")) existing.setDefinition((String) request.get("definition")); - if (request.containsKey("description")) existing.setDescription((String) request.get("description")); - if (request.containsKey("format")) existing.setFormat(parseEnum(TypeFormat.class, request.get("format"))); + TypeFormat format = request.containsKey("format") ? parseEnum(TypeFormat.class, request.get("format")) : null; + if (request.containsKey("definition")) { + existing.setDefinition((String) request.get("definition")); + } + if (request.containsKey("description")) { + existing.setDescription((String) request.get("description")); + } + if (request.containsKey("format")) { + existing.setFormat(format); + } typeStore.put(apiKey(apiId, typeName), existing); return existing; } diff --git a/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java b/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java index 4795b0daac..3b4ad01ba8 100644 --- a/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java +++ b/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java @@ -705,4 +705,18 @@ class AppSyncServiceTest { assertEquals(SchemaCreationStatusType.PROCESSING, svc.getSchemaCreationStatus(api.getApiId()).getStatus()); } + + @Test + void invalidTypeFormatLeavesTheStoredDefinitionUnchanged() { + GraphqlApi api = service.createGraphqlApi( + Map.of("name", "types", "authenticationType", "API_KEY"), "us-east-1"); + service.createType(api.getApiId(), Map.of("name", "Item", "definition", "type Item { id: ID }", "format", "SDL")); + + AwsException refused = assertThrows(AwsException.class, () -> service.updateType(api.getApiId(), "Item", + Map.of("definition", "type Item { changed: ID }", "format", "BOGUS"))); + + assertEquals("BadRequestException", refused.getErrorCode()); + assertEquals("type Item { id: ID }", service.getType(api.getApiId(), "Item").getDefinition()); + assertEquals("SDL", service.getType(api.getApiId(), "Item").getFormat().name()); + } } diff --git a/src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java b/src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java new file mode 100644 index 0000000000..a9fd9861c4 --- /dev/null +++ b/src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java @@ -0,0 +1,55 @@ +package io.floci.aws.services.appsync; + +import io.floci.aws.testing.AwsTestClients; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.appsync.AppSyncClient; +import software.amazon.awssdk.services.appsync.model.AuthenticationType; +import software.amazon.awssdk.services.appsync.model.BadRequestException; +import software.amazon.awssdk.services.appsync.model.Type; +import software.amazon.awssdk.services.appsync.model.TypeDefinitionFormat; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@QuarkusTest +class AppSyncUpdateTypeIntegrationTest { + + @Test + void rejectedFormatPreservesTheTypeAndValidUpdateStillSucceeds() { + try (AppSyncClient client = AwsTestClients.create( + AppSyncClient.builder(), "741648700015", Region.US_EAST_1)) { + String apiId = client.createGraphqlApi(request -> request.name("type-update-" + UUID.randomUUID()) + .authenticationType(AuthenticationType.API_KEY)).graphqlApi().apiId(); + try { + String original = "type Item { id: ID }"; + String replacement = "type Item { changed: ID }"; + client.createType(request -> request.apiId(apiId).definition(original).format(TypeDefinitionFormat.SDL)); + Type stored = client.getType(request -> request.apiId(apiId).typeName("Item") + .format(TypeDefinitionFormat.SDL)).type(); + + BadRequestException refused = assertThrows(BadRequestException.class, + () -> client.updateType(request -> request.apiId(apiId).typeName("Item") + .definition(replacement).format("BOGUS"))); + + assertEquals(400, refused.statusCode()); + assertEquals(stored, client.getType(request -> request.apiId(apiId).typeName("Item") + .format(TypeDefinitionFormat.SDL)).type()); + assertEquals(original, client.listTypes(request -> request.apiId(apiId).format(TypeDefinitionFormat.SDL)) + .types().getFirst().definition()); + + Type updated = client.updateType(request -> request.apiId(apiId).typeName("Item") + .definition(replacement).format(TypeDefinitionFormat.SDL)).type(); + assertEquals(replacement, updated.definition()); + assertEquals(TypeDefinitionFormat.SDL, updated.format()); + assertEquals(updated, client.getType(request -> request.apiId(apiId).typeName("Item") + .format(TypeDefinitionFormat.SDL)).type()); + } finally { + client.deleteGraphqlApi(request -> request.apiId(apiId)); + } + } + } +}