Package: aws-cdk-appsync-transformer
AppSync Transformer Construct for AWS CDKWhy This PackageIn April 2020 I wrote ablog poston using the AWS Cloud Development Kit with AppSync. I wrote my own transformer in order to emulate AWS Amplify's method of using GraphQL directives in order to template a lot of the Schema Definition Language.This package is my attempt to convert all of that effort into a separate construct in order to clean up the process.How Do I Use ItExample UsageAPI With Default Values# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826fromaws_cdk_appsync_transformerimportAppSyncTransformerAppSyncTransformer(self,"my-cool-api",schema_path="schema.graphql")schema.graphqltypeCustomer@model@auth(rules:[{allow:groups,groups:["Admins"]},{allow:private,provider:iam,operations:[read,update]}]){id:ID!firstName:String!lastName:String!active:Boolean!address:String!}typeProduct@model@auth(rules:[{allow:groups,groups:["Admins"]},{allow:public,provider:iam,operations:[read]}]){id:ID!name:String!description:String!price:String!active:Boolean!added:AWSDateTime!orders:[Order]@connection}typeOrder@model@key(fields:["id","productID"]){id:ID!productID:ID!total:String!ordered:AWSDateTime!}Supported Amplify DirectivesTested:@model@auth@connectionExperimental:@key@versioned@functionThese work differently here than they do in Amplify - seeFunctionsbelowNot Yet Supported:@searchable@predictions@httpAuthenticationUser Pool Authentication# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826user_pool=UserPool(self,"my-cool-user-pool",...)user_pool_client=UserPoolClient(self,f"{id}-client",user_pool=self.user_pool,...)AppSyncTransformer(self,"my-cool-api",schema_path="schema.graphql",authorization_config={"default_authorization":{"authorization_type":AuthorizationType.USER_POOL,"user_pool_config":{"user_pool":user_pool,"app_id_client_regex":user_pool_client.user_pool_client_id,"default_action":UserPoolDefaultAction.ALLOW}}})IAMUnauth Role: TODOAuth Role: Unsupported (for now?). Authorized roles (Lambda Functions, EC2 roles, etc) are required to setup their own role permissions.FunctionsFields with the@functiondirective will be accessible viaapi.outputs.FUNCTION_RESOLVERS. It will return an array like below.Currently these are not named and do not specify a region. There are improvements that can be made here but this simple way has worked for me so I've implemented it first. Typically I send all@functionrequests to one Lambda Function and have it route as necessary.[{typeName:'Query',fieldName:'listUsers'},{typeName:'Query',fieldName:'getUser'},{typeName:'Mutation',fieldName:'createUser'},{typeName:'Mutation',fieldName:'updateUser'}]DataStore SupportPasssyncEnabled: trueto theAppSyncTransformerPropsGenerate necessary exports (seeCode Generationbelow)Code GenerationI've written some helpers to generate code similarly to how AWS Amplify generates statements and types. You can find the codehere.VersioningI willattemptto align the major and minor version of this package withAWS CDK, but always check the release descriptions for compatibility.I currently supportLimitationsContributingSeeCONTRIBUTINGfor detailsLicenseDistributed underApache License, Version 2.0