fix(appsync): require a format for type updates (#8149)

This commit is contained in:
Jackson Price authored and GitHub committed 2026-11-12 16:17:42 -04:00
1 parent 0924e6a46d
commit c0ef5b2bfd
5 files changed
+41 -9

No files matched your search

@@ -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();
@@ -616,16 +616,18 @@ public class AppSyncService {
public synchronized AppSyncType updateType(String apiId, String typeName, Map<String, Object> 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;
}
@@ -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")
@@ -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<String, Object> 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());
}
}
@@ -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")