Skip to content

Commit

Permalink
feat(appsync): merged APIs (#26895)
Browse files Browse the repository at this point in the history
Add support for [AppSync Merged API](https://aws.amazon.com/blogs/mobile/introducing-merged-apis-on-aws-appsync/) feature.

At the moment, a GraphQL schema can be passed using the `schema` property. I deprecated this property because it is not used for merged APIs.
Depecreated syntax:
```ts
const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
  schema: appsync.SchemaFile.fromAsset(path.join(__dirname, 'schema.graphql')),
});
```
Instead, I introduced a new property `apiSource` that can be used to create a AppSync GraphQL API or Merged API.
GraphQL API:
```ts
const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
  apiSource: appsync.ApiSource.fromSchema(appsync.SchemaFile.fromAsset(path.join(__dirname, 'schema.graphql'))),
  // short version
  apiSource: appsync.ApiSource.fromFile(path.join(__dirname, 'schema.graphql')),
});
```

Merged API:
```ts
const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
  apiSource: appsync.ApiSource.fromSourceApis({
    sourceApis: [
      {
        sourceApi: firstApi,
        mergeType: appsync.MergeType.MANUAL_MERGE,
      },
      {
        sourceApi: secondApi,
        mergeType: appsync.MergeType.AUTO_MERGE,
      },
    ],
  }),
});
```

Closes #25960.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jumic authored Aug 30, 2023
1 parent 9ccab73 commit fe930a5
Show file tree
Hide file tree
Showing 15 changed files with 1,614 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type firstTest {
version: String!
}
type Query {
getFirstTests: [firstTest]!
}
type Mutation {
addFirstTest(version: String!): firstTest
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type secondTest {
version: String!
}
type Query {
getSecondTests: [secondTest]!
}
type Mutation {
addSecondTest(version: String!): secondTest
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "33.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "apiDefaultTestDeployAssert018781F2.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"33.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "33.0.0",
"testCases": {
"api/DefaultTest": {
"stacks": [
"stack"
],
"assertionStack": "api/DefaultTest/DeployAssert",
"assertionStackName": "apiDefaultTestDeployAssert018781F2"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"version": "33.0.0",
"artifacts": {
"stack.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "stack.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"stack": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "stack.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/227b4b7375fe3e7375a62383a2f862327ab90f469d554dcca064258ce7b2821b.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"stack.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"stack.assets"
],
"metadata": {
"/stack/FirstSourceAPI/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "FirstSourceAPIB0DE8D5A"
}
],
"/stack/FirstSourceAPI/Schema": [
{
"type": "aws:cdk:logicalId",
"data": "FirstSourceAPISchemaF2FDB692"
}
],
"/stack/FirstSourceAPI/DefaultApiKey": [
{
"type": "aws:cdk:logicalId",
"data": "FirstSourceAPIDefaultApiKey9D9AE06D"
}
],
"/stack/FirstSourceAPI/FirstSourceDS/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "FirstSourceAPIFirstSourceDS6AD299B7"
}
],
"/stack/SecondSourceAPI/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "SecondSourceAPIE903371D"
}
],
"/stack/SecondSourceAPI/Schema": [
{
"type": "aws:cdk:logicalId",
"data": "SecondSourceAPISchema65B7401E"
}
],
"/stack/SecondSourceAPI/DefaultApiKey": [
{
"type": "aws:cdk:logicalId",
"data": "SecondSourceAPIDefaultApiKeyCE5A0A64"
}
],
"/stack/SecondSourceAPI/SecondSourceDS/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "SecondSourceAPISecondSourceDSEA46EBA7"
}
],
"/stack/MergedAPI/MergedApiExecutionRole/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPIMergedApiExecutionRole5F2BCCAD"
}
],
"/stack/MergedAPI/MergedApiExecutionRole/DefaultPolicy/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPIMergedApiExecutionRoleDefaultPolicy31A96DBC"
}
],
"/stack/MergedAPI/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPI08D3EAD1"
}
],
"/stack/MergedAPI/FirstSourceAPIAssociation": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPIFirstSourceAPIAssociationEC781BA9"
}
],
"/stack/MergedAPI/SecondSourceAPIAssociation": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPISecondSourceAPIAssociationBD1A08F4"
}
],
"/stack/MergedAPI/DefaultApiKey": [
{
"type": "aws:cdk:logicalId",
"data": "MergedAPIDefaultApiKeyAF5EA13C"
}
],
"/stack/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/stack/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "stack"
},
"apiDefaultTestDeployAssert018781F2.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "apiDefaultTestDeployAssert018781F2.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"apiDefaultTestDeployAssert018781F2": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "apiDefaultTestDeployAssert018781F2.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"apiDefaultTestDeployAssert018781F2.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"apiDefaultTestDeployAssert018781F2.assets"
],
"metadata": {
"/api/DefaultTest/DeployAssert/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/api/DefaultTest/DeployAssert/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "api/DefaultTest/DeployAssert"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "33.0.0",
"files": {
"227b4b7375fe3e7375a62383a2f862327ab90f469d554dcca064258ce7b2821b": {
"source": {
"path": "stack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "227b4b7375fe3e7375a62383a2f862327ab90f469d554dcca064258ce7b2821b.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading

0 comments on commit fe930a5

Please sign in to comment.