Skip to content

GraphqlApi: Creating GraphqlApi and providing definition using fromSourceApis method , Dependency is not being added between AWS::AppSync::SourceApiAssociation resource and AWS::AppSync::GraphQLSchema which causes creation failures #29044

@rahuldeverani

Description

@rahuldeverani

Describe the bug

When we create mergedAPI using GraphqlApi class and provide the firstApi as sourceApi , and use fromSourceApis method to provide definition of merged API then cloudformation deployment fails with the error:

Resource handler returned message: "Failed to merge source API: to Merged API: with the following error: There's no types found in this API

Expected Behavior

CDK should implicitly add dependency in the template such that AWS::AppSync::SourceApiAssociation for merged api is created after AWS::AppSync::GraphQLSchema of sourceapi.

Current Behavior

Currently , in the generated template , the resource AWS::AppSync::SourceApiAssociation does not wait for the creation of AWS::AppSync::GraphQLSchema for the sourceApi which leads to this error.

Reproduction Steps

const authorizationLambdaFunction = new lambda.Function(this, 'AuthFunction', {
  code: lambda.Code.fromAsset('lambda'),
  runtime: lambda.Runtime.NODEJS_18_X,
  handler: 'hello.handler',
})

// first source API
const firstApi = new appsync.GraphqlApi(this, 'ProductsAPI', {
  name: 'ProductsAPI',
  definition: appsync.Definition.fromFile(path.join(__dirname,'appsync.merged-api-1.graphql')),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.LAMBDA,
      lambdaAuthorizerConfig: {
        handler: authorizationLambdaFunction
      }
    }
  },
  logConfig: {
    fieldLogLevel: appsync.FieldLogLevel.ALL,
    excludeVerboseContent: false
  }
});

// Merged API
const mergedApi = new appsync.GraphqlApi(this, 'MergedAPI', {
  name: 'MergedAPI',
  definition: appsync.Definition.fromSourceApis({
    sourceApis: [
      {
        sourceApi: firstApi,
        mergeType: appsync.MergeType.AUTO_MERGE,
      },
    ],
  }),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.LAMBDA,
      lambdaAuthorizerConfig: {
        handler: authorizationLambdaFunction
      }
    }
  }
});

Possible Solution

Add depends on between the resources such that AWS::AppSync::SourceApiAssociation depends on AWS::AppSync::GraphQLSchema

workaround :

manually add the dependency in cdk code:
mergedApi.node.addDependency(firstApi);

Additional Information/Context

No response

CDK CLI Version

2.124.0

Framework Version

No response

Node.js Version

v20.8.1

OS

MacOs

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-appsyncRelated to AWS AppSyncbugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions