Last active
October 18, 2021 14:32
-
-
Save mmccall10/c4070e5df1befd95b69e78d98005f099 to your computer and use it in GitHub Desktop.
AWS CDK Aspect to enforce consistent naming of AppSync resolvers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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