Skip to content

Commit

Permalink
fix(appsync): source api association does not depend on schema (#29455)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes #29044.

### Reason for this change

When associating between the source GraphQL API and the merged API using `fromSourceApis`, generated association resource doesn't depend on the source GraphQL schema.

```ts
// This API has `CfnGraphQLSchema` by `definition` prop
const firstApi = new appsync.GraphqlApi(stack, 'FirstSourceAPI', {
  name: 'FirstSourceAPI',
  definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.merged-api-1.graphql')),
});

// This merged API generates `CfnSourceApiAssociation`
new appsync.GraphqlApi(stack, 'MergedAPI', {
  name: 'MergedAPI',
  definition: appsync.Definition.fromSourceApis({
    sourceApis: [
      {
        sourceApi: firstApi,
        mergeType: appsync.MergeType.MANUAL_MERGE,
      },
    ],
  }),
});
```

The same is true if the `SourceApiAssociation` construct is used explicitly.

```ts
// This API has `CfnGraphQLSchema` by `definition` prop
const firstApi = new appsync.GraphqlApi(stack, 'FirstSourceAPI', {
  name: 'FirstSourceAPI',
  definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.merged-api-1.graphql')),
});

// This merged API does not generate `CfnSourceApiAssociation`
const mergedApi = new appsync.GraphqlApi(stack, 'MergedAPI', {
  name: 'MergedAPI',
  definition: appsync.Definition.fromSourceApis({
    sourceApis: [],
    mergedApiExecutionRole: mergedApiExecutionRole,
  }),
});

// This construct has `CfnSourceApiAssociation`
new appsync.SourceApiAssociation(stack, 'SourceApiAssociation1', {
  sourceApi: firstApi,
  mergedApi: mergedApi,
  mergeType: appsync.MergeType.MANUAL_MERGE,
  mergedApiExecutionRole: mergedApiExecutionRole,
});
```

### Description of changes

The `sourceApi` passed by the `fromSourceApis` method or the `SourceApiAssociation` construct has `addSchemaDependency` method. Using this method, we can make the association to depend on the schema in the `sourceApi`.
But, if the api is an IMPORTED resource to begin with, it has no schema in the CDK layer, so there is nothing we can do about it. (The method does nothing.)

### Description of how you validated changes

Both unit and existing integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
go-to-k authored Apr 9, 2024
1 parent 49b4aa1 commit 92a160b
Show file tree
Hide file tree
Showing 25 changed files with 357 additions and 249 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@
"Arn"
]
}
}
},
"DependsOn": [
"FirstSourceAPISchemaF2FDB692"
]
},
"MergedAPISecondSourceAPIAssociationBD1A08F4": {
"Type": "AWS::AppSync::SourceApiAssociation",
Expand All @@ -233,7 +236,10 @@
"Arn"
]
}
}
},
"DependsOn": [
"SecondSourceAPISchema65B7401E"
]
},
"MergedAPIDefaultApiKeyAF5EA13C": {
"Type": "AWS::AppSync::ApiKey",
Expand Down
Loading

0 comments on commit 92a160b

Please sign in to comment.