Skip to content

Instantly share code, notes, and snippets.

@mmccall10
Last active October 18, 2021 14:32
Show Gist options
  • Save mmccall10/c4070e5df1befd95b69e78d98005f099 to your computer and use it in GitHub Desktop.
Save mmccall10/c4070e5df1befd95b69e78d98005f099 to your computer and use it in GitHub Desktop.
AWS CDK Aspect to enforce consistent naming of AppSync resolvers
import { CfnResolver } from '@aws-cdk/aws-appsync'
import { IConstruct } from '@aws-cdk/core'
interface IAspect {
visit: (node: IConstruct) => void
}
class EnforceAppSyncResolverNaming implements IAspect {
visit (node: IConstruct): void {
if (node instanceof CfnResolver) node.overrideLogicalId(`${node.typeName}${node.fieldName}Resolver`)
}
}
export { EnforceAppSyncResolverNaming }
export default class GraphqlApiStack extends Stack {
api: GraphqlApi
constructor (scope: sst.App, id: string, props: GraphqlStackProps) {
super(scope, id, props)
this.api = new GraphqlApi(this, 'GraphqlApi', {
name: 'GraphqlApi',
schema: Schema.fromAsset('graphql/schema.graphql'),
authorizationConfig: {
defaultAuthorization: {
authorizationType: AuthorizationType.API_KEY
}
}
})
Aspects.of(this.api).add(new EnforceAppSyncResolverNaming())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment