feat(appsync): AWS AppSync management API (Phase 1) (#1108)

* feat(appsync): add GraphQL API management service

Implement Phase 1 CRUDL management API for AWS AppSync.
Includes controller, service layer, and model classes for:
- GraphQL API lifecycle (create/get/update/delete/list)
- Schema creation and introspection
- Data Sources, Resolvers, Functions, Types, API Keys
- Tagging and Environment Variables

* chore(appsync): register service in config and catalog

Add AppSync service configuration (EmulatorConfig), service
descriptor (ResolvedServiceCatalog), YAML config entries, and
SDK test client fixture.

* test(appsync): add integration and SDK compatibility tests

AppSyncIntegrationTest: 44 tests covering CRUDL for all resources
 GraphQL API, Schema, DataSources, Resolvers, Functions, Types,
 API Keys, Tags, Environment Variables, and cascade delete.

AppSyncTest: AWS SDK v2 compatibility tests for management API
 operations using the real AppSyncClient.

* feat(appsync): add typed enums for AWS API models

Add Java enums matching AWS AppSync API constants:
- AuthenticationType (API_KEY, AWS_IAM, COGNITO, OIDC, LAMBDA)
- DataSourceType (NONE, LAMBDA, DYNAMODB, HTTP, EVENTBRIDGE, ...)
- ResolverKind (UNIT, PIPELINE)
- ResolverRuntimeName (APPSYNC_JS, VTL)
- TypeFormat (SDL, JSON)
- SchemaCreationStatusType (PROCESSING, ACTIVE, FAILED, ...)

* refactor(appsync): align model types with AWS API reference

- DataSource.type: String → DataSourceType enum
- GraphqlApi.authenticationType: String → AuthenticationType enum
- GraphqlApi.logConfig: String → Map<String, Object> (structured)
- GraphqlApi.additionalAuthenticationProviders: Map → List<Map> (array)
- GraphqlApi.xrayEnabled: String → Boolean
- Resolver.kind: String → ResolverKind enum
- Resolver.ResolverRuntime.name: String → ResolverRuntimeName enum
- AppSyncType.format: String → TypeFormat enum
- SchemaCreationStatus.status: String → SchemaCreationStatusType enum
- ApiKey.expires: String → Long (epoch seconds)

* fix(appsync): correct ARN format, add enum validation, fix field types

- Function ARN: add missing region parameter
- Add parseEnum() helper for type-safe enum deserialization
- Reject invalid enum values with BadRequestException (400)
- Handle String/Boolean/Number coercion for xrayEnabled, expires
- Remove extra 'details' from StartSchemaCreation response
- Pass region to createFunction from controller

* fix(appsync): validate required fields on resource creation

Reject requests missing required fields with BadRequestException (400):
- CreateGraphqlApi: name required
- CreateDataSource: name and type required
- CreateResolver: fieldName and dataSourceName required
- CreateFunction: name required
- CreateType: name required

* test(appsync): add error handling, delete standalone, and cascade tests

Add 22 new integration tests (44 → 66 total):
- Error handling: missing name, blank name, invalid enum, missing required
  fields for API/DataSources/Resolvers/Functions/Types (11 tests)
- Non-existent resource 404 tests for API, DataSource, Type (3 tests)
- Delete standalone: verify CRUD delete for Resolver, DataSource,
  Function, Type, ApiKey with post-delete 404 confirmation (5 tests)
- Cascade verification: API delete cascades to DataSources and Functions;
  Function delete does not affect resolvers (3 tests)

* feat(appsync): add pagination support for list endpoints

Add maxResults and nextToken query params to all list endpoints:
- ListGraphqlApis, ListDataSources, ListResolvers, ListResolversByFunction
- ListFunctions, ListTypes, ListApiKeys

Uses offset-based pagination with Base64-encoded tokens, following
the Pricing service pattern. Returns nextToken when more results
are available, null when all results have been returned.

* test(appsync): add pagination integration tests

Add 9 pagination tests (66 → 75 total):
- ListApis with maxResults returns subset and nextToken
- ListApis with nextToken returns second page
- ListApis without pagination returns all items
- ListDataSources, ListTypes, ListFunctions, ListApiKeys,
  ListResolvers with maxResults
- Invalid nextToken returns 400

* fix(appsync): align SDK test with AWS SDK v2 model, extract type name from SDL

- Fix SDK test: use typeAsString() for enum comparison, remove apiKey()
  field assertion, use functions() instead of functionConfigurationList()
- Extract type name from SDL definition when name is not provided
  (matches real AWS CreateType behavior)
- Update integration test for type creation without explicit name

* fix(appsync): use extracted type name when definition-based extraction succeeds

The type name extracted from SDL definition was stored in a local
variable but not set on the AppSyncType object, causing createType
to return a type without name and making subsequent get/delete fail.

* refactor(appsync): inject RegionResolver instead of passing region as string

Follow the established pattern used by BackupService and PipesService.
Replace manual ARN string concatenation with regionResolver.buildArn()
and remove the hardcoded accountId field.

* fix(appsync): add functionId to Resolver model and fix listResolversByFunction filtering

The listResolversByFunction endpoint was incorrectly comparing
function.getName() with resolver.getDataSourceName(), which is not
the correct AWS AppSync relationship. Resolvers reference functions
via a functionId field, not by data source name matching.

- Add functionId field to Resolver model
- Handle functionId in createResolver and updateResolver
- Fix listResolversByFunction to filter by functionId
- Add listResolversByType method for per-type filtering

* feat(appsync): add global listResolvers endpoint

Add GET /v1/apis/{apiId}/resolvers to list all resolvers across all
types, matching the AWS AppSync API. The per-type endpoint
(GET /v1/apis/{apiId}/types/{typeName}/resolvers) is preserved.

- Add global listResolvers to controller
- Rename per-type endpoint to listResolversByType for clarity
- Add integration test for global listResolvers
- Update listResolversByFunction test to verify functionId-based filtering

* test(appsync): complete SDK compatibility tests for Phase 1

Add missing SDK v2 compatibility tests to match all Phase 1 operations:

- API Keys: updateApiKey, deleteApiKey
- Resolvers: updateResolver
- Types: createType, getType, listTypes, updateType
- Error handling: getNonExistentApi, getNonExistentDataSource,
  getNonExistentType throw AppSyncException

Total SDK tests: 24 → 35. All operations in Phase 1 are now covered.
This commit is contained in:
AgustinBertagna authored and GitHub committed 2026-06-02 00:17:01 -05:00
1 parent e8441f58a5
commit d7ddac73fe
23 files changed
+3610 -1

No files matched your search

@@ -0,0 +1,531 @@
package com.floci.test;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.appsync.AppSyncClient;
import software.amazon.awssdk.services.appsync.model.*;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import static org.assertj.core.api.Assertions.*;
@DisplayName("AppSync")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class AppSyncTest {
private static AppSyncClient client;
private static String apiId;
private static final ObjectMapper mapper = new ObjectMapper();
@BeforeAll
static void setup() {
client = TestFixtures.appSyncClient();
}
@AfterAll
static void cleanup() {
if (apiId != null) {
try { client.deleteGraphqlApi(r -> r.apiId(apiId)); } catch (Exception ignored) {}
}
if (client != null) client.close();
}
// ── GraphQL API CRUD ────────────────────────────────────────────────
@Test
@Order(1)
void createGraphqlApi() {
CreateGraphqlApiResponse resp = client.createGraphqlApi(CreateGraphqlApiRequest.builder()
.name("sdk-test-api")
.authenticationType("API_KEY")
.tags(Map.of("env", "sdk-test"))
.build());
assertThat(resp.graphqlApi()).isNotNull();
apiId = resp.graphqlApi().apiId();
assertThat(apiId).isNotBlank();
assertThat(resp.graphqlApi().name()).isEqualTo("sdk-test-api");
assertThat(resp.graphqlApi().authenticationType()).isEqualTo(AuthenticationType.API_KEY);
assertThat(resp.graphqlApi().arn()).contains("arn:aws:appsync:");
}
@Test
@Order(2)
void getGraphqlApi() {
GetGraphqlApiResponse resp = client.getGraphqlApi(GetGraphqlApiRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.graphqlApi()).isNotNull();
assertThat(resp.graphqlApi().apiId()).isEqualTo(apiId);
assertThat(resp.graphqlApi().name()).isEqualTo("sdk-test-api");
}
@Test
@Order(3)
void listGraphqlApis() {
ListGraphqlApisResponse resp = client.listGraphqlApis();
assertThat(resp.graphqlApis()).isNotEmpty();
assertThat(resp.graphqlApis().stream()
.anyMatch(a -> a.apiId().equals(apiId))).isTrue();
}
@Test
@Order(4)
void updateGraphqlApi() {
UpdateGraphqlApiResponse resp = client.updateGraphqlApi(UpdateGraphqlApiRequest.builder()
.apiId(apiId)
.name("sdk-test-api-v2")
.build());
assertThat(resp.graphqlApi()).isNotNull();
assertThat(resp.graphqlApi().name()).isEqualTo("sdk-test-api-v2");
}
// ── Schema ──────────────────────────────────────────────────────────
@Test
@Order(10)
void startSchemaCreation() {
StartSchemaCreationResponse resp = client.startSchemaCreation(StartSchemaCreationRequest.builder()
.apiId(apiId)
.definition(SdkBytes.fromUtf8String("type Query { hello: String }"))
.build());
assertThat(resp.status()).isNotNull();
}
@Test
@Order(11)
void getSchemaCreationStatus() {
GetSchemaCreationStatusResponse resp = client.getSchemaCreationStatus(
GetSchemaCreationStatusRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.statusAsString()).isEqualTo("ACTIVE");
}
// ── API Keys ────────────────────────────────────────────────────────
private static String keyId;
@Test
@Order(20)
void createApiKey() {
long expiresEpoch = Instant.parse("2027-01-01T00:00:00Z").getEpochSecond();
CreateApiKeyResponse resp = client.createApiKey(CreateApiKeyRequest.builder()
.apiId(apiId)
.description("sdk-test-key")
.expires(expiresEpoch)
.build());
assertThat(resp.apiKey()).isNotNull();
keyId = resp.apiKey().id();
assertThat(keyId).isNotBlank();
assertThat(resp.apiKey().description()).isEqualTo("sdk-test-key");
}
@Test
@Order(21)
void listApiKeys() {
ListApiKeysResponse resp = client.listApiKeys(ListApiKeysRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.apiKeys()).isNotEmpty();
}
@Test
@Order(22)
void updateApiKey() {
UpdateApiKeyResponse resp = client.updateApiKey(UpdateApiKeyRequest.builder()
.apiId(apiId)
.id(keyId)
.description("updated-sdk-key")
.build());
assertThat(resp.apiKey()).isNotNull();
assertThat(resp.apiKey().description()).isEqualTo("updated-sdk-key");
}
@Test
@Order(23)
void deleteApiKey() {
CreateApiKeyResponse created = client.createApiKey(CreateApiKeyRequest.builder()
.apiId(apiId)
.description("temp-key")
.build());
DeleteApiKeyResponse resp = client.deleteApiKey(DeleteApiKeyRequest.builder()
.apiId(apiId)
.id(created.apiKey().id())
.build());
assertThat(resp).isNotNull();
}
// ── Data Sources ────────────────────────────────────────────────────
@Test
@Order(30)
void createDataSource() {
CreateDataSourceResponse resp = client.createDataSource(CreateDataSourceRequest.builder()
.apiId(apiId)
.name("none-ds")
.type("NONE")
.build());
assertThat(resp.dataSource()).isNotNull();
assertThat(resp.dataSource().name()).isEqualTo("none-ds");
assertThat(resp.dataSource().typeAsString()).isEqualTo("NONE");
}
@Test
@Order(31)
void getDataSource() {
GetDataSourceResponse resp = client.getDataSource(GetDataSourceRequest.builder()
.apiId(apiId)
.name("none-ds")
.build());
assertThat(resp.dataSource()).isNotNull();
assertThat(resp.dataSource().name()).isEqualTo("none-ds");
}
@Test
@Order(32)
void listDataSources() {
ListDataSourcesResponse resp = client.listDataSources(ListDataSourcesRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.dataSources()).isNotEmpty();
}
@Test
@Order(33)
void updateDataSource() {
UpdateDataSourceResponse resp = client.updateDataSource(UpdateDataSourceRequest.builder()
.apiId(apiId)
.name("none-ds")
.description("updated-ds")
.build());
assertThat(resp.dataSource()).isNotNull();
assertThat(resp.dataSource().description()).isEqualTo("updated-ds");
}
@Test
@Order(34)
void deleteDataSource() {
client.createDataSource(CreateDataSourceRequest.builder()
.apiId(apiId)
.name("temp-ds")
.type("NONE")
.build());
DeleteDataSourceResponse resp = client.deleteDataSource(DeleteDataSourceRequest.builder()
.apiId(apiId)
.name("temp-ds")
.build());
assertThat(resp).isNotNull();
}
// ── Resolvers ───────────────────────────────────────────────────────
@Test
@Order(40)
void createResolver() {
CreateResolverResponse resp = client.createResolver(CreateResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("hello")
.dataSourceName("none-ds")
.build());
assertThat(resp.resolver()).isNotNull();
assertThat(resp.resolver().typeName()).isEqualTo("Query");
assertThat(resp.resolver().fieldName()).isEqualTo("hello");
}
@Test
@Order(41)
void getResolver() {
GetResolverResponse resp = client.getResolver(GetResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("hello")
.build());
assertThat(resp.resolver()).isNotNull();
assertThat(resp.resolver().fieldName()).isEqualTo("hello");
}
@Test
@Order(42)
void listResolvers() {
ListResolversResponse resp = client.listResolvers(ListResolversRequest.builder()
.apiId(apiId)
.typeName("Query")
.build());
assertThat(resp.resolvers()).isNotEmpty();
}
@Test
@Order(43)
void updateResolver() {
UpdateResolverResponse resp = client.updateResolver(UpdateResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("hello")
.dataSourceName("none-ds")
.responseMappingTemplate("$util.toJson({\"updated\": true})")
.build());
assertThat(resp.resolver()).isNotNull();
assertThat(resp.resolver().responseMappingTemplate()).contains("updated");
}
@Test
@Order(44)
void deleteResolver() {
client.createResolver(CreateResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("tempField")
.dataSourceName("none-ds")
.build());
DeleteResolverResponse resp = client.deleteResolver(DeleteResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("tempField")
.build());
assertThat(resp).isNotNull();
}
// ── Functions ───────────────────────────────────────────────────────
@Test
@Order(50)
void createFunction() {
CreateFunctionResponse resp = client.createFunction(CreateFunctionRequest.builder()
.apiId(apiId)
.name("sdk-function")
.dataSourceName("none-ds")
.build());
assertThat(resp.functionConfiguration()).isNotNull();
assertThat(resp.functionConfiguration().name()).isEqualTo("sdk-function");
assertThat(resp.functionConfiguration().functionId()).isNotBlank();
}
@Test
@Order(51)
void listFunctions() {
ListFunctionsResponse resp = client.listFunctions(ListFunctionsRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.functions()).isNotEmpty();
}
@Test
@Order(52)
void updateFunction() {
String fnId = client.listFunctions(ListFunctionsRequest.builder()
.apiId(apiId)
.build())
.functions().get(0).functionId();
UpdateFunctionResponse resp = client.updateFunction(UpdateFunctionRequest.builder()
.apiId(apiId)
.functionId(fnId)
.name("sdk-function")
.dataSourceName("none-ds")
.description("updated-fn")
.build());
assertThat(resp.functionConfiguration()).isNotNull();
assertThat(resp.functionConfiguration().description()).isEqualTo("updated-fn");
}
@Test
@Order(53)
void deleteFunction() {
CreateFunctionResponse fnResp = client.createFunction(CreateFunctionRequest.builder()
.apiId(apiId)
.name("temp-function")
.dataSourceName("none-ds")
.build());
DeleteFunctionResponse resp = client.deleteFunction(DeleteFunctionRequest.builder()
.apiId(apiId)
.functionId(fnResp.functionConfiguration().functionId())
.build());
assertThat(resp).isNotNull();
}
// ── Tags ────────────────────────────────────────────────────────────
@Test
@Order(60)
void tagResource() {
GetGraphqlApiResponse api = client.getGraphqlApi(r -> r.apiId(apiId));
String arn = api.graphqlApi().arn();
client.tagResource(TagResourceRequest.builder()
.resourceArn(arn)
.tags(Map.of("team", "platform"))
.build());
ListTagsForResourceResponse resp = client.listTagsForResource(
ListTagsForResourceRequest.builder()
.resourceArn(arn)
.build());
assertThat(resp.tags()).containsEntry("env", "sdk-test");
assertThat(resp.tags()).containsEntry("team", "platform");
}
@Test
@Order(61)
void untagResource() {
GetGraphqlApiResponse api = client.getGraphqlApi(r -> r.apiId(apiId));
String arn = api.graphqlApi().arn();
client.untagResource(UntagResourceRequest.builder()
.resourceArn(arn)
.tagKeys("team")
.build());
ListTagsForResourceResponse resp = client.listTagsForResource(
ListTagsForResourceRequest.builder()
.resourceArn(arn)
.build());
assertThat(resp.tags()).doesNotContainKey("team");
assertThat(resp.tags()).containsEntry("env", "sdk-test");
}
// ── Types ──────────────────────────────────────────────────────────
@Test
@Order(70)
void createType() {
CreateTypeResponse resp = client.createType(CreateTypeRequest.builder()
.apiId(apiId)
.definition("type Item { id: ID!, name: String }")
.build());
assertThat(resp.type()).isNotNull();
assertThat(resp.type().name()).isEqualTo("Item");
assertThat(resp.type().definition()).contains("Item");
}
@Test
@Order(71)
void getType() {
GetTypeResponse resp = client.getType(GetTypeRequest.builder()
.apiId(apiId)
.typeName("Item")
.build());
assertThat(resp.type()).isNotNull();
assertThat(resp.type().name()).isEqualTo("Item");
}
@Test
@Order(72)
void listTypes() {
ListTypesResponse resp = client.listTypes(ListTypesRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.types()).isNotEmpty();
}
@Test
@Order(73)
void updateType() {
UpdateTypeResponse resp = client.updateType(UpdateTypeRequest.builder()
.apiId(apiId)
.typeName("Item")
.definition("type Item { id: ID!, name: String, description: String }")
.build());
assertThat(resp.type()).isNotNull();
assertThat(resp.type().definition()).contains("description");
}
@Test
@Order(74)
void deleteType() {
client.createType(CreateTypeRequest.builder()
.apiId(apiId)
.definition("type TempType { id: ID }")
.build());
DeleteTypeResponse resp = client.deleteType(DeleteTypeRequest.builder()
.apiId(apiId)
.typeName("TempType")
.build());
assertThat(resp).isNotNull();
}
// ── Error Handling ─────────────────────────────────────────────────
@Test
@Order(80)
void getNonExistentApiThrowsException() {
assertThatThrownBy(() -> client.getGraphqlApi(GetGraphqlApiRequest.builder()
.apiId("nonexistent12345678901234")
.build()))
.isInstanceOf(AppSyncException.class);
}
@Test
@Order(81)
void getNonExistentDataSourceThrowsException() {
assertThatThrownBy(() -> client.getDataSource(GetDataSourceRequest.builder()
.apiId(apiId)
.name("nonexistent-ds")
.build()))
.isInstanceOf(AppSyncException.class);
}
@Test
@Order(82)
void getNonExistentTypeThrowsException() {
assertThatThrownBy(() -> client.getType(GetTypeRequest.builder()
.apiId(apiId)
.typeName("NonExistentType")
.build()))
.isInstanceOf(AppSyncException.class);
}
@Test
@Order(83)
void createApiKeyMissingDescriptionSucceeds() {
CreateApiKeyResponse resp = client.createApiKey(CreateApiKeyRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.apiKey()).isNotNull();
assertThat(resp.apiKey().id()).isNotBlank();
}
}