Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(appsync): add x-ray parameter to AppSync #9389

Merged
merged 10 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,16 @@ api.grantMutation(role, 'updateExample');

// For custom types and granular design
api.grant(role, appsync.IamResource.ofType('Mutation', 'updateExample'), 'appsync:GraphQL');
```
```

## AppSync with X-Ray Tracing

```ts
const api = new appsync.GraphQLApi(stack, 'Api', {
name: 'demo',
schemaDefinitionFile: join(__dirname, 'schema.graphql'),
xrayEnabled: true,
});
```

See the [the AWS documentation](https://docs.aws.amazon.com/appsync/latest/devguide/x-ray-tracing.html) to learn more about AWS AppSync's X-Ray support.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather us either put a description of what x-ray support is or not include it at all in the README.

Since it is a feature, I think in order to avoid the linter error, I would be okay with just adding the prop to the example section.

Like as follows:

const api = new appsync.GraphQLApi(stack, 'Api', {
  name: 'demo',
  schemaDefinition: appsync.SchemaDefinition.FILE,
  schemaDefinitionFile: join(__dirname, 'schema.graphql'),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.IAM
    },
  },
  xrayEnabled: true,
});

@MrArnoldPalmer wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it as commented.

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 @@ -238,6 +238,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 @@ -383,6 +389,7 @@ export class GraphQLApi extends Construct {
)
: undefined,
additionalAuthenticationProviders: this.formatAdditionalAuthenticationProviders(props),
xrayEnabled: props.xrayEnabled || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property doesn't need to be configured here. If it is undefined in CloudFormations, Cfn will configure the AppSync without x-ray support by default.

Suggested change
xrayEnabled: props.xrayEnabled || false,
xrayEnabled: props.xrayEnabled,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BryanPan342
Thank you for your comment.
I will fix it along with the integration test.

});

this.apiId = this.api.attrApiId;
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-appsync/test/appsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,22 @@ 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',
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
xrayEnabled: true,
});

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::GraphQLApi', {
XrayEnabled: true,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"UserPoolId": {
"Ref": "PoolD3F588B8"
}
}
},
"XrayEnabled": false
}
},
"ApiSchema510EECD7": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"UserPoolId": {
"Ref": "PoolD3F588B8"
}
}
},
"XrayEnabled": false
}
},
"ApiDefaultAPIKeyApiKey74F5313B": {
Expand Down