feat(appsync): Phase 2 — Schema Registry, Model Fixes, CRUDL completion & AWS Scalars (#1185)

* build: add graphql-java dependency

* feat(appsync): add and extend data models for Phase 2

- Add AdditionalAuthenticationProvider, DomainName, ChannelNamespace, ApiAssociation models
- Add 14 fields to GraphqlApi (apiType, visibility, owner, etc.)
- Change additionalAuthenticationProviders from raw maps to typed list
- Add 6 fields to Resolver (resolverArn, cachingConfig, maxBatchSize, etc.)
- Add dataSourceArn to DataSource
- Rename FunctionConfiguration.arn to functionArn

* feat(appsync): add service and controller changes for Phase 2

* feat(appsync): add service and controller changes for Phase 2

* test(appsync): add Phase 2 integration tests

Add ~60 new tests for:
- Model completeness (new fields, ARNs, functionArn rename)
- Domain names CRUDL + associate/disassociate
- Channel namespaces CRUDL + update
- Merged API associations CRUDL
- Enhanced metrics
- Schema registry parsing with AWS scalars and extensions
- Directive registration (aws_api_key, aws_subscribe, deprecated, unknown)
- Edge cases (null auth providers, maxBatchSize 0, cleanup on delete)

* test(appsync): add AWS scalar unit tests

Test all 17 AWS scalars:
- All registered in AppSyncScalarRegistry
- AWSDateTime, AWSJSON, AWSEmail parse valid/invalid values
- AWSTimestamp and AWSShort range validation
- AWSURL and AWSPhone format validation

* test(appsync): add SDK compatibility tests for Phase 2

Validate that the AWS SDK Java v2 can read:
- dataSourceArn() on CreateDataSource response
- resolverArn() on CreateResolver response
- functionArn() on CreateFunction response
- BadRequestException on invalid schema creation

* docs(appsync): add Phase 2 operations, schema registry, and AWS scalars documentation

- Add Domain Names, Channel Namespaces, Merged API Associations, Enhanced Metrics
- Document AWS scalar types (17 scalars with validation rules)
- Document AppSync directives (8 directives with locations)
- Update Not Implemented section with future phase references
- Add CLI examples for domain names and channel namespaces
- Update cascade delete to include channel namespaces and domain associations

* docs: add AppSync to service tables, env vars, storage config, and SDK README

- README.md: add AppSync to category table, detailed notes, and architecture diagram
- docs/index.md: add AppSync to supported services table, fix count to 52
- docs/configuration/environment-variables.md: add FLOCI_SERVICES_APPSYNC_ENABLED
- docs/configuration/advanced/application-yml.md: add appsync config block
- docs/configuration/storage.md: add AppSync per-service storage override
- compatibility-tests/sdk-test-java/README.md: add AppSyncTest to services table

* fix(appsync): reuse ObjectMapper and fix AWSJSON serialize for non-string values

AWSJSON scalar was creating a new ObjectMapper on every parseValue() call. serialize() used toString() which produces invalid JSON for Map/JsonNode results.

* fix(appsync): strip string literals and comments before unknown directive validation

The regex @(\w+) incorrectly flagged @ mentions inside GraphQL string literals and comments as unknown directives.

* fix(appsync): prevent silent overwrite on creates, validate required fields and input values

- Add existence checks on createDataSource, createResolver, createType,
  createChannelNamespace, createMergedApiAssociation (→ ConflictException 409)
- Validate authenticationType is required on createGraphqlApi
- Validate typeName is required on createResolver
- Validate dataSourceName exists on createResolver and createFunction
- Prevent associateApi from silently overwriting existing association
- Enforce API key limit (max 2 per API)
- Fix expires parsing to accept ISO 8601 strings, throw on invalid values
- Fix castInt overflow detection
- Fix updateApiKey expires validation (was silently swallowing errors)
- Change InvalidNextTokenException to BadRequestException (AWS standard)
- Fix maxResults=0 to return empty page
- Fix getIntrospectionSchema to throw 404 instead of returning null
- Fix tags with null values (was producing literal string "null")

* test(appsync): fix cascade delete test to create data source before function, align with new validation

* refactor(appsync): remove dead code and unused hasSchema()

- Delete AppSyncDirectiveRegistry.java (100 lines, never used)
- Delete DirectiveValidator.java (45 lines, never called)
- Remove hasSchema() from SchemaRegistry (never called)

* fix(appsync): scalar null-safety, type validation, and DNS resolution

- Add null checks to 5 serialize() methods (AWS_TIMESTAMP, AWS_LONG,
  AWS_INTEGER, AWS_BOOLEAN, AWS_FLOAT) to prevent NPE
- Fix AWS_TIMESTAMP parseValue() ClassCastException on String input
- Replace InetAddress.getByName() with regex in AWS IPAddress to
  prevent DNS resolution (SSRF concern)
- AWSBoolean now rejects non-boolean values (matches AppSync behavior)

* refactor(appsync): centralize directive definitions in AppSyncDirective enum

- Add AppSyncDirective enum as single source of truth for directive
  names and SDL definitions
- Update AppSyncSchemaParser to use enum instead of duplicated strings
- Eliminates 3 sources of truth (validateNoUnknownDirectives Set,
  injectDirectiveDefinitions SDL, and formerly AppSyncDirectiveRegistry)

* perf(appsync): cache scalarMap in AppSyncScalarRegistry

- Initialize scalarMap once in constructor as unmodifiableMap
- Avoids recreating HashMap on every call (was called twice per
  schema parse)

* test(appsync): add tests for scalar fixes and behavior changes

- Add tests for null-safety in serialize() (5 scalars)
- Add test for AWSTimestamp parseValue with String input
- Add tests for AWSIPAddress regex validation (IPv4, IPv6, invalid)
- Add tests for AWSBoolean rejecting non-boolean values
- Add test for scalarMap caching

* test(sdk): add AWS scalars schema creation test

Verifies that schemas with AWS scalar types (AWSDateTime, AWSJSON,
AWSIPAddress, AWSBoolean) parse correctly via the SDK.

* fix(appsync): correct API paths to match AWS documentation

- Channel namespaces: /v1/ → /v2/, channelnamespaces → channelNamespaces
- Domain association: /apis → /apiassociation
- Remove ListApiAssociations (not a real AppSync operation)
- Remove GetEnhancedMetricsConfig (not a real AppSync operation)
- Rename Merged API Association to Source API Association with correct paths:
  - AssociateSourceGraphqlApi: POST /v1/mergedApis/{id}/sourceApiAssociations
  - GetSourceApiAssociation: GET /v1/mergedApis/{id}/sourceApiAssociations/{id}
  - ListSourceApiAssociations: GET /v1/apis/{apiId}/sourceApiAssociations
  - DisassociateSourceGraphqlApi: DELETE /v1/mergedApis/{id}/sourceApiAssociations/{id}

* feat(appsync): add SourceApiAssociation models

Add SourceApiAssociation, SourceApiAssociationConfig, and
SourceApiAssociationSummary models to support merged/source API
association operations per AWS AppSync API Reference.

* feat(appsync): add ChannelNamespace support models

Add AuthMode, HandlerConfig, HandlerConfigs, Integration, and
LambdaConfig models for ChannelNamespace handler configuration
per AWS AppSync API Reference.

* fix(appsync): fix ApiAssociation and ChannelNamespace models

ApiAssociation: remove source/merged API fields, keep only domain
association fields (apiId, associationStatus, deploymentDetail,
domainName) per AWS AppSync API Reference.

ChannelNamespace: add missing fields (channelNamespaceArn,
codeHandlers, created, handlerConfigs, lastModified,
publishAuthModes, subscribeAuthModes, tags) per AWS docs.

* feat(appsync): add missing service methods and fix response models

- associateApi now returns full ApiAssociation object
- createMergedApiAssociation returns SourceApiAssociation
- createSourceApiAssociation returns SourceApiAssociation
- getSourceApiAssociation validates mergedApiId
- listSourceApiAssociations returns SourceApiAssociationSummary
- Add updateSourceApiAssociation method
- Add deleteMergedApiAssociation method
- ChannelNamespace: populate arn, timestamps on create/update

* feat(appsync): fix response formats and add missing endpoints

- associateMergedGraphqlApi: response key apiAssociation → sourceApiAssociation
- disassociateSourceGraphqlApi: returns 200 + body (not 204)
- associateApi: returns full ApiAssociation from service
- Add POST /v1/mergedApis/{id}/sourceApiAssociations/{assocId} (UpdateSourceApiAssociation)
- Add DELETE /v1/sourceApis/{id}/mergedApiAssociations/{assocId} (DisassociateMergedGraphqlApi)

* test(appsync): fix and add integration tests for new endpoints

- Fix associateSourceGraphqlApi: use mergedApiId and sourceApiAssociationStatus
- Fix deleteSourceApiAssociation: expect 200 with body (not 204)
- Add updateDomainName test
- Add associateMergedGraphqlApi test
- Add updateSourceApiAssociation test
- Add disassociateMergedGraphqlApi test

* test(appsync): add SDK tests for missing operations

- Add updateDomainName test
- Add associateMergedGraphqlApi test
- Add updateSourceApiAssociation test
- Add disassociateMergedGraphqlApi test
- Fix test ordering for new domain tests
This commit is contained in:
AgustinBertagna authored and GitHub committed 2026-06-07 00:05:51 -05:00
1 parent 9a7070992e
commit 4446404288
34 files changed
+3718 -110

No files matched your search

@@ -487,6 +487,394 @@ class AppSyncTest {
assertThat(resp).isNotNull();
}
// ── Phase 2: Model Compatibility ───────────────────────────────────
@Test
@Order(90)
void createDataSource_hasDataSourceArn() {
CreateDataSourceResponse resp = client.createDataSource(CreateDataSourceRequest.builder()
.apiId(apiId)
.name("arn-check-ds")
.type("NONE")
.build());
assertThat(resp.dataSource().dataSourceArn()).isNotNull();
assertThat(resp.dataSource().dataSourceArn()).contains("arn:aws:appsync:");
assertThat(resp.dataSource().dataSourceArn()).contains("/datasources/arn-check-ds");
client.deleteDataSource(r -> r.apiId(apiId).name("arn-check-ds"));
}
@Test
@Order(91)
void createResolver_hasResolverArn() {
CreateResolverResponse resp = client.createResolver(CreateResolverRequest.builder()
.apiId(apiId)
.typeName("Query")
.fieldName("resolverArnCheck")
.dataSourceName("none-ds")
.build());
assertThat(resp.resolver().resolverArn()).isNotNull();
assertThat(resp.resolver().resolverArn()).contains("arn:aws:appsync:");
assertThat(resp.resolver().resolverArn()).contains("/types/Query/resolvers/resolverArnCheck");
client.deleteResolver(r -> r.apiId(apiId).typeName("Query").fieldName("resolverArnCheck"));
}
@Test
@Order(92)
void createFunction_hasFunctionArn() {
CreateFunctionResponse resp = client.createFunction(CreateFunctionRequest.builder()
.apiId(apiId)
.name("arn-check-fn")
.dataSourceName("none-ds")
.build());
assertThat(resp.functionConfiguration().functionArn()).isNotNull();
assertThat(resp.functionConfiguration().functionArn()).contains("arn:aws:appsync:");
client.deleteFunction(r -> r.apiId(apiId).functionId(resp.functionConfiguration().functionId()));
}
@Test
@Order(93)
void startSchemaCreation_invalidSchema() {
assertThatThrownBy(() -> client.startSchemaCreation(StartSchemaCreationRequest.builder()
.apiId(apiId)
.definition(SdkBytes.fromUtf8String("type Query { invalid !!! }"))
.build()))
.isInstanceOf(AppSyncException.class)
.hasMessageContaining("Invalid schema");
}
@Test
@Order(94)
void startSchemaCreation_withAWSScalars() {
StartSchemaCreationResponse resp = client.startSchemaCreation(
StartSchemaCreationRequest.builder()
.apiId(apiId)
.definition(SdkBytes.fromUtf8String(
"type Query { now: AWSDateTime, data: AWSJSON, ip: AWSIPAddress, active: AWSBoolean }"))
.build());
assertThat(resp.status()).isNotNull();
}
// ── Channel Namespaces ─────────────────────────────────────────────
private static String channelNsName;
@Test
@Order(95)
void createChannelNamespace() {
CreateChannelNamespaceResponse resp = client.createChannelNamespace(
CreateChannelNamespaceRequest.builder()
.apiId(apiId)
.name("sdk-channel-ns")
.build());
assertThat(resp.channelNamespace()).isNotNull();
channelNsName = resp.channelNamespace().name();
assertThat(channelNsName).isEqualTo("sdk-channel-ns");
assertThat(resp.channelNamespace().apiId()).isEqualTo(apiId);
}
@Test
@Order(96)
void getChannelNamespace() {
GetChannelNamespaceResponse resp = client.getChannelNamespace(
GetChannelNamespaceRequest.builder()
.apiId(apiId)
.name(channelNsName)
.build());
assertThat(resp.channelNamespace()).isNotNull();
assertThat(resp.channelNamespace().name()).isEqualTo(channelNsName);
}
@Test
@Order(97)
void updateChannelNamespace() {
UpdateChannelNamespaceResponse resp = client.updateChannelNamespace(
UpdateChannelNamespaceRequest.builder()
.apiId(apiId)
.name(channelNsName)
.build());
assertThat(resp.channelNamespace()).isNotNull();
}
@Test
@Order(98)
void listChannelNamespaces() {
ListChannelNamespacesResponse resp = client.listChannelNamespaces(
ListChannelNamespacesRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.channelNamespaces()).isNotEmpty();
}
@Test
@Order(99)
void deleteChannelNamespace() {
DeleteChannelNamespaceResponse resp = client.deleteChannelNamespace(
DeleteChannelNamespaceRequest.builder()
.apiId(apiId)
.name(channelNsName)
.build());
assertThat(resp).isNotNull();
}
// ── Domain Association ─────────────────────────────────────────────
private static String tempDomainName;
@Test
@Order(100)
void createDomainName() {
// Use unique domain name to avoid conflicts
String domainSuffix = java.util.UUID.randomUUID().toString().substring(0, 8);
CreateDomainNameResponse resp = client.createDomainName(
CreateDomainNameRequest.builder()
.domainName("sdk-" + domainSuffix + ".example.com")
.certificateArn("arn:aws:acm:us-east-1:000000000000:certificate/sdk")
.build());
assertThat(resp.domainNameConfig()).isNotNull();
tempDomainName = resp.domainNameConfig().domainName();
assertThat(tempDomainName).startsWith("sdk-");
assertThat(resp.domainNameConfig().appsyncDomainName()).isNotNull();
}
@Test
@Order(101)
void getDomainName() {
GetDomainNameResponse resp = client.getDomainName(
GetDomainNameRequest.builder()
.domainName(tempDomainName)
.build());
assertThat(resp.domainNameConfig()).isNotNull();
assertThat(resp.domainNameConfig().domainName()).isEqualTo(tempDomainName);
}
@Test
@Order(102)
void updateDomainName() {
UpdateDomainNameResponse resp = client.updateDomainName(
UpdateDomainNameRequest.builder()
.domainName(tempDomainName)
.description("updated-domain")
.build());
assertThat(resp.domainNameConfig()).isNotNull();
assertThat(resp.domainNameConfig().domainName()).isEqualTo(tempDomainName);
}
@Test
@Order(103)
void associateApi() {
AssociateApiResponse resp = client.associateApi(
AssociateApiRequest.builder()
.domainName(tempDomainName)
.apiId(apiId)
.build());
assertThat(resp.apiAssociation()).isNotNull();
assertThat(resp.apiAssociation().domainName()).isEqualTo(tempDomainName);
assertThat(resp.apiAssociation().apiId()).isEqualTo(apiId);
}
@Test
@Order(104)
void getApiAssociation() {
GetApiAssociationResponse resp = client.getApiAssociation(
GetApiAssociationRequest.builder()
.domainName(tempDomainName)
.build());
assertThat(resp.apiAssociation()).isNotNull();
assertThat(resp.apiAssociation().apiId()).isEqualTo(apiId);
}
@Test
@Order(105)
void disassociateApi() {
DisassociateApiResponse resp = client.disassociateApi(
DisassociateApiRequest.builder()
.domainName(tempDomainName)
.build());
assertThat(resp).isNotNull();
}
@Test
@Order(106)
void deleteDomainName() {
DeleteDomainNameResponse resp = client.deleteDomainName(
DeleteDomainNameRequest.builder()
.domainName(tempDomainName)
.build());
assertThat(resp).isNotNull();
}
// ── Source API Association ─────────────────────────────────────────
private static String sourceApiId;
private static String assocId;
@Test
@Order(107)
void associateSourceGraphqlApi() {
// Create source API
CreateGraphqlApiResponse sourceResp = client.createGraphqlApi(
CreateGraphqlApiRequest.builder()
.name("sdk-source-api")
.authenticationType("API_KEY")
.build());
sourceApiId = sourceResp.graphqlApi().apiId();
AssociateSourceGraphqlApiResponse resp = client.associateSourceGraphqlApi(
AssociateSourceGraphqlApiRequest.builder()
.mergedApiIdentifier(apiId)
.sourceApiIdentifier(sourceApiId)
.build());
assertThat(resp.sourceApiAssociation()).isNotNull();
assocId = resp.sourceApiAssociation().associationId();
assertThat(assocId).isNotNull();
assertThat(resp.sourceApiAssociation().sourceApiId()).isEqualTo(sourceApiId);
}
@Test
@Order(108)
void getSourceApiAssociation() {
GetSourceApiAssociationResponse resp = client.getSourceApiAssociation(
GetSourceApiAssociationRequest.builder()
.mergedApiIdentifier(apiId)
.associationId(assocId)
.build());
assertThat(resp.sourceApiAssociation()).isNotNull();
assertThat(resp.sourceApiAssociation().associationId()).isEqualTo(assocId);
assertThat(resp.sourceApiAssociation().sourceApiId()).isEqualTo(sourceApiId);
}
@Test
@Order(109)
void listSourceApiAssociations() {
ListSourceApiAssociationsResponse resp = client.listSourceApiAssociations(
ListSourceApiAssociationsRequest.builder()
.apiId(apiId)
.build());
assertThat(resp.sourceApiAssociationSummaries()).isNotEmpty();
}
@Test
@Order(110)
void disassociateSourceGraphqlApi() {
DisassociateSourceGraphqlApiResponse resp = client.disassociateSourceGraphqlApi(
DisassociateSourceGraphqlApiRequest.builder()
.mergedApiIdentifier(apiId)
.associationId(assocId)
.build());
assertThat(resp).isNotNull();
}
@Test
@Order(111)
void cleanupSourceApi() {
client.deleteGraphqlApi(DeleteGraphqlApiRequest.builder()
.apiId(sourceApiId)
.build());
}
// ── Merged API Associations ────────────────────────────────────────
private static String mergedAssocSourceApiId;
private static String mergedAssocId;
@Test
@Order(112)
void associateMergedGraphqlApi() {
CreateGraphqlApiResponse sourceResp = client.createGraphqlApi(
CreateGraphqlApiRequest.builder()
.name("sdk-merged-source")
.authenticationType("API_KEY")
.build());
mergedAssocSourceApiId = sourceResp.graphqlApi().apiId();
AssociateMergedGraphqlApiResponse resp = client.associateMergedGraphqlApi(
AssociateMergedGraphqlApiRequest.builder()
.sourceApiIdentifier(mergedAssocSourceApiId)
.mergedApiIdentifier(apiId)
.build());
assertThat(resp.sourceApiAssociation()).isNotNull();
mergedAssocId = resp.sourceApiAssociation().associationId();
assertThat(mergedAssocId).isNotNull();
assertThat(resp.sourceApiAssociation().sourceApiId()).isEqualTo(mergedAssocSourceApiId);
assertThat(resp.sourceApiAssociation().mergedApiId()).isEqualTo(apiId);
}
@Test
@Order(113)
void updateSourceApiAssociation() {
CreateGraphqlApiResponse updateSourceResp = client.createGraphqlApi(
CreateGraphqlApiRequest.builder()
.name("sdk-update-source")
.authenticationType("API_KEY")
.build());
String updateSourceApiId = updateSourceResp.graphqlApi().apiId();
AssociateSourceGraphqlApiResponse assocResp = client.associateSourceGraphqlApi(
AssociateSourceGraphqlApiRequest.builder()
.mergedApiIdentifier(apiId)
.sourceApiIdentifier(updateSourceApiId)
.build());
String updateAssocId = assocResp.sourceApiAssociation().associationId();
UpdateSourceApiAssociationResponse resp = client.updateSourceApiAssociation(
UpdateSourceApiAssociationRequest.builder()
.mergedApiIdentifier(apiId)
.associationId(updateAssocId)
.description("updated-association")
.build());
assertThat(resp.sourceApiAssociation()).isNotNull();
assertThat(resp.sourceApiAssociation().associationId()).isEqualTo(updateAssocId);
assertThat(resp.sourceApiAssociation().description()).isEqualTo("updated-association");
client.deleteGraphqlApi(DeleteGraphqlApiRequest.builder().apiId(updateSourceApiId).build());
}
@Test
@Order(114)
void disassociateMergedGraphqlApi() {
DisassociateMergedGraphqlApiResponse resp = client.disassociateMergedGraphqlApi(
DisassociateMergedGraphqlApiRequest.builder()
.sourceApiIdentifier(mergedAssocSourceApiId)
.associationId(mergedAssocId)
.build());
assertThat(resp).isNotNull();
assertThat(resp.sourceApiAssociationStatus()).isNotNull();
}
@Test
@Order(115)
void cleanupMergedSourceApi() {
client.deleteGraphqlApi(DeleteGraphqlApiRequest.builder()
.apiId(mergedAssocSourceApiId)
.build());
}
// ── Error Handling ─────────────────────────────────────────────────
@Test