From c0ef5b2bfd8e762c537a526a3c5c4decedc4b09c Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:17:42 -0600 Subject: [PATCH] fix(appsync): require a format for type updates (#8149) --- .../test/java/com/floci/test/AppSyncTest.java | 1 + .../aws/services/appsync/AppSyncService.java | 10 +++++--- .../appsync/AppSyncIntegrationTest.java | 2 +- .../services/appsync/AppSyncServiceTest.java | 25 +++++++++++++++++++ .../AppSyncUpdateTypeIntegrationTest.java | 12 ++++++--- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppSyncTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppSyncTest.java index 1408419a34..e3d4052a8f 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppSyncTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppSyncTest.java @@ -588,6 +588,7 @@ class AppSyncTest { .apiId(apiId) .typeName("Item") .definition("type Item { id: ID!, name: String, description: String }") + .format(TypeDefinitionFormat.SDL) .build()); assertThat(resp.type()).isNotNull(); 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 2e7e7306be..ba931b9206 100644 --- a/src/main/java/io/floci/aws/services/appsync/AppSyncService.java +++ b/src/main/java/io/floci/aws/services/appsync/AppSyncService.java @@ -616,16 +616,18 @@ public class AppSyncService { public synchronized AppSyncType updateType(String apiId, String typeName, Map request) { assertSchemaNotBusy(apiId); AppSyncType existing = getType(apiId, typeName); - TypeFormat format = request.containsKey("format") ? parseEnum(TypeFormat.class, request.get("format")) : null; + Object formatValue = request.get("format"); + if (formatValue == null) { + throw new AwsException("BadRequestException", "A type format is required", 400); + } + TypeFormat format = parseEnum(TypeFormat.class, formatValue); 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); - } + existing.setFormat(format); typeStore.put(apiKey(apiId, typeName), existing); return existing; } diff --git a/src/test/java/io/floci/aws/services/appsync/AppSyncIntegrationTest.java b/src/test/java/io/floci/aws/services/appsync/AppSyncIntegrationTest.java index b9e7efd0d7..0d8cde72a4 100644 --- a/src/test/java/io/floci/aws/services/appsync/AppSyncIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/appsync/AppSyncIntegrationTest.java @@ -430,7 +430,7 @@ class AppSyncIntegrationTest { .header("Authorization", AUTH) .contentType("application/json") .body(""" - {"definition": "type Query { hello: String, goodbye: String }"} + {"definition": "type Query { hello: String, goodbye: String }", "format": "SDL"} """) .when() .post("/v1/apis/" + apiId + "/types/Query") 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 3b4ad01ba8..8378e80a77 100644 --- a/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java +++ b/src/test/java/io/floci/aws/services/appsync/AppSyncServiceTest.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import java.time.Clock; import java.time.Duration; @@ -719,4 +720,28 @@ class AppSyncServiceTest { assertEquals("type Item { id: ID }", service.getType(api.getApiId(), "Item").getDefinition()); assertEquals("SDL", service.getType(api.getApiId(), "Item").getFormat().name()); } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void missingTypeFormatLeavesTheStoredTypeUnchanged(boolean explicitNull) { + 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 }", + "description", "original", "format", "SDL")); + Map request = new HashMap<>(); + request.put("definition", "type Item { changed: ID }"); + request.put("description", "replacement"); + if (explicitNull) { + request.put("format", null); + } + + AwsException refused = assertThrows(AwsException.class, + () -> service.updateType(api.getApiId(), "Item", request)); + + assertEquals("BadRequestException", refused.getErrorCode()); + assertTrue(refused.getMessage().contains("format")); + assertEquals("type Item { id: ID }", service.getType(api.getApiId(), "Item").getDefinition()); + assertEquals("original", service.getType(api.getApiId(), "Item").getDescription()); + 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 index a9fd9861c4..1376b384b8 100644 --- a/src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/appsync/AppSyncUpdateTypeIntegrationTest.java @@ -2,7 +2,9 @@ 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 org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.appsync.AppSyncClient; import software.amazon.awssdk.services.appsync.model.AuthenticationType; @@ -18,8 +20,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @QuarkusTest class AppSyncUpdateTypeIntegrationTest { - @Test - void rejectedFormatPreservesTheTypeAndValidUpdateStillSucceeds() { + @ParameterizedTest + @NullSource + @ValueSource(strings = {"BOGUS", ""}) + void rejectedFormatPreservesTheTypeAndValidUpdateStillSucceeds(String format) { try (AppSyncClient client = AwsTestClients.create( AppSyncClient.builder(), "741648700015", Region.US_EAST_1)) { String apiId = client.createGraphqlApi(request -> request.name("type-update-" + UUID.randomUUID()) @@ -33,7 +37,7 @@ class AppSyncUpdateTypeIntegrationTest { BadRequestException refused = assertThrows(BadRequestException.class, () -> client.updateType(request -> request.apiId(apiId).typeName("Item") - .definition(replacement).format("BOGUS"))); + .definition(replacement).format(format))); assertEquals(400, refused.statusCode()); assertEquals(stored, client.getType(request -> request.apiId(apiId).typeName("Item")