From 541a631337d3223515ac35d38e7b31eb3e670b36 Mon Sep 17 00:00:00 2001 From: Nicholas DeJaco <54116900+ndejaco2@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:36:11 -0700 Subject: [PATCH] Update graphql java dependency to pick up fix for directive handling (#249) * Update graphql java dependency to pick up fix for directive handling when performing schema diff in the breaking change detection hook * Use new interface --- hooks/AppSync_BreakingChangeDetection/pom.xml | 2 +- .../schema/AppSyncSchemaDiffUtil.java | 13 +++++++------ .../PreUpdateHookHandlerTest.java | 11 +++++++++++ .../resources/original-schema-hidden.graphql | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 hooks/AppSync_BreakingChangeDetection/src/test/resources/original-schema-hidden.graphql diff --git a/hooks/AppSync_BreakingChangeDetection/pom.xml b/hooks/AppSync_BreakingChangeDetection/pom.xml index 6e6cf707..39909df5 100644 --- a/hooks/AppSync_BreakingChangeDetection/pom.xml +++ b/hooks/AppSync_BreakingChangeDetection/pom.xml @@ -96,7 +96,7 @@ com.graphql-java graphql-java - 21.0 + 21.2 diff --git a/hooks/AppSync_BreakingChangeDetection/src/main/java/com/awscommunity/appsync/breakingchangedetection/schema/AppSyncSchemaDiffUtil.java b/hooks/AppSync_BreakingChangeDetection/src/main/java/com/awscommunity/appsync/breakingchangedetection/schema/AppSyncSchemaDiffUtil.java index 5ba701c2..1237808a 100644 --- a/hooks/AppSync_BreakingChangeDetection/src/main/java/com/awscommunity/appsync/breakingchangedetection/schema/AppSyncSchemaDiffUtil.java +++ b/hooks/AppSync_BreakingChangeDetection/src/main/java/com/awscommunity/appsync/breakingchangedetection/schema/AppSyncSchemaDiffUtil.java @@ -1,16 +1,17 @@ package com.awscommunity.appsync.breakingchangedetection.schema; import com.awscommunity.appsync.breakingchangedetection.model.aws.appsync.graphqlschema.AwsAppsyncGraphqlschema; - import graphql.schema.GraphQLSchema; -import graphql.schema.diff.DiffSet; -import graphql.schema.idl.*; import graphql.schema.diff.SchemaDiff; +import graphql.schema.diff.SchemaDiffSet; +import graphql.schema.idl.RuntimeWiring; +import graphql.schema.idl.SchemaGenerator; +import graphql.schema.idl.SchemaParser; +import graphql.schema.idl.TypeDefinitionRegistry; +import java.util.Objects; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.Logger; -import java.util.Objects; - import static com.awscommunity.appsync.breakingchangedetection.schema.AppSyncDirectives.APPSYNC_DIRECTIVE_DEFINITIONS; import static com.awscommunity.appsync.breakingchangedetection.schema.AppSyncScalars.APPSYNC_SCALAR_DEFINITIONS; @@ -34,7 +35,7 @@ public static AppSyncSchemaDiffReporter diffSchema(final AwsAppsyncGraphqlschema final SchemaDiff schemaDiff = new SchemaDiff(SchemaDiff.Options.defaultOptions().enforceDirectives()); final GraphQLSchema currentSchema = getGraphQLSchema(previousResourceProperties, proxy); final GraphQLSchema newSchema = getGraphQLSchema(resourceProperties, proxy); - final DiffSet diffset = DiffSet.diffSet(currentSchema, newSchema); + final SchemaDiffSet diffset = SchemaDiffSet.diffSetFromSdl(currentSchema, newSchema); final AppSyncSchemaDiffReporter reporter = new AppSyncSchemaDiffReporter(logger, resourceProperties.getApiId()); schemaDiff.diffSchema(diffset, reporter); diff --git a/hooks/AppSync_BreakingChangeDetection/src/test/java/com/awscommunity/appsync/breakingchangedetection/PreUpdateHookHandlerTest.java b/hooks/AppSync_BreakingChangeDetection/src/test/java/com/awscommunity/appsync/breakingchangedetection/PreUpdateHookHandlerTest.java index 3678c7a9..ac25680d 100644 --- a/hooks/AppSync_BreakingChangeDetection/src/test/java/com/awscommunity/appsync/breakingchangedetection/PreUpdateHookHandlerTest.java +++ b/hooks/AppSync_BreakingChangeDetection/src/test/java/com/awscommunity/appsync/breakingchangedetection/PreUpdateHookHandlerTest.java @@ -138,6 +138,17 @@ public void handleRequest_BuiltInTypes() throws IOException { assertResponse(response, OperationStatus.SUCCESS, expectedMessage, null); } + @Test + public void handleRequest_HiddenDirectiveRemoved() throws IOException { + final ProgressEvent response = executeSchemaDiffHook( + "original-schema-hidden.graphql", + "original-schema.graphql"); + + final String expectedMessage = "Breaking changes have been detected for this AWS::AppSync::GraphQLSchema:\n" + + "API Id: 1 [BREAKING] [MISSING] - The new API does not have a directive named 'hidden' on type 'test'\n"; + assertResponse(response, OperationStatus.FAILED, expectedMessage, HandlerErrorCode.NonCompliant); + } + @SuppressWarnings("unchecked") @Test public void handleRequest_GetDefinitionFromS3Succeeds() throws IOException { diff --git a/hooks/AppSync_BreakingChangeDetection/src/test/resources/original-schema-hidden.graphql b/hooks/AppSync_BreakingChangeDetection/src/test/resources/original-schema-hidden.graphql new file mode 100644 index 00000000..99f4898d --- /dev/null +++ b/hooks/AppSync_BreakingChangeDetection/src/test/resources/original-schema-hidden.graphql @@ -0,0 +1,17 @@ +type test { + version: String! @hidden + type: TestType +} + +type Query { + getTests: [test]! +} + +type Mutation { + addTest(version: String!): test +} + +enum TestType { + SIMPLE, + COMPLEX +} \ No newline at end of file