I am using the code-first approach in @aws-cdk/aws-appsync for generating my graphql schema. For Typescript code generation purposes I need a way to retrieve the schema.graphql before deployment (maybe somehow extracting it from the cdk synth
command?).
For getting the automatically created schema before deployment, use this script:
readFile('cdk.out/<YOUR-APP-NAME>.template.json', 'utf8', (err, data) => {
if (err) {
throw err;
}
const definition = JSON.parse(data)
.Resources
.<YOUR-SCHEMA-ID> // replace with your schema id
.Properties
.Definition;
writeFile('lib/domain/generated.graphql', definition, (error) => {
if (error) throw error;
});
});