Skip to content

Commit

Permalink
feat(appsync): add x-ray parameter to AppSync (#9389)
Browse files Browse the repository at this point in the history
Close: #7640

- [x] Adding a boolean prop for xrayEnabled
- [x]  Linking it to the xrayEnabled prop in class CfnGraphQLApi from appsync.generated.ts file that is generated on yarn build
- [x]  Writing a unit test to check whether that the boolean property is set in the CloudFormation Template
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
tomoki10 authored and Elad Ben-Israel committed Aug 10, 2020
1 parent c2c5f2a commit 7351858
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const api = new appsync.GraphQLApi(stack, 'Api', {
authorizationType: appsync.AuthorizationType.IAM
},
},
xrayEnabled: true,
});

const demoTable = new db.Table(stack, 'DemoTable', {
Expand Down Expand Up @@ -159,4 +160,4 @@ api.grantMutation(role, 'updateExample');
// For custom types and granular design
api.grant(role, appsync.IamResource.ofType('Mutation', 'updateExample'), 'appsync:GraphQL');
```
```
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ export interface GraphQLApiProps {
* @default - Use schemaDefinition
*/
readonly schemaDefinitionFile?: string;
/**
* A flag indicating whether or not X-Ray tracing is enabled for the GraphQL API.
*
* @default - false
*/
readonly xrayEnabled?: boolean;

}

Expand Down Expand Up @@ -402,6 +408,7 @@ export class GraphQLApi extends Construct {
)
: undefined,
additionalAuthenticationProviders: this.formatAdditionalAuthenticationProviders(props),
xrayEnabled: props.xrayEnabled,
});

this.apiId = this.api.attrApiId;
Expand Down
21 changes: 20 additions & 1 deletion packages/@aws-cdk/aws-appsync/test/appsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ test('appsync should configure resolver as unit when pipelineConfig is empty arr
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
Kind: 'UNIT',
});
});
});

test('when xray is enabled should not throw an Error', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new appsync.GraphQLApi(stack, 'api', {
authorizationConfig: {},
name: 'api',
schemaDefinition: appsync.SchemaDefinition.FILE,
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
xrayEnabled: true,
});

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::GraphQLApi', {
XrayEnabled: true,
});
});

0 comments on commit 7351858

Please sign in to comment.